mirror of
https://github.com/saymrwulf/pytorch.git
synced 2026-05-15 21:00:47 +00:00
Summary: (1) BlobsQueue is causing a gcc error (google search suggeste it was a bug, but we'll put the implementation in a separate cc file). (2) Preparing for cuda 9: update cub. (3) Prepare for cudnn 7: update cudnn rnn op. (4) Fix an MSVC issue Reviewed By: sf-wind, jerryzh168 Differential Revision: D5574352 fbshipit-source-id: 230820ce3ceaa32bee8323bdc509de352c93fcf2
67 lines
1.6 KiB
C++
67 lines
1.6 KiB
C++
#pragma once
|
|
|
|
#include <atomic>
|
|
#include <condition_variable>
|
|
#include <memory>
|
|
#include <mutex>
|
|
#include <queue>
|
|
|
|
#include "caffe2/core/blob_stats.h"
|
|
#include "caffe2/core/logging.h"
|
|
#include "caffe2/core/stats.h"
|
|
#include "caffe2/core/tensor.h"
|
|
#include "caffe2/core/workspace.h"
|
|
|
|
namespace caffe2 {
|
|
|
|
// A thread-safe, bounded, blocking queue.
|
|
// Modelled as a circular buffer.
|
|
|
|
// Containing blobs are owned by the workspace.
|
|
// On read, we swap out the underlying data for the blob passed in for blobs
|
|
|
|
class BlobsQueue : public std::enable_shared_from_this<BlobsQueue> {
|
|
public:
|
|
BlobsQueue(
|
|
Workspace* ws,
|
|
const std::string& queueName,
|
|
size_t capacity,
|
|
size_t numBlobs,
|
|
bool enforceUniqueName,
|
|
const std::vector<std::string>& fieldNames = {});
|
|
|
|
~BlobsQueue() {
|
|
close();
|
|
}
|
|
|
|
bool blockingRead(
|
|
const std::vector<Blob*>& inputs,
|
|
float timeout_secs = 0.0f);
|
|
bool tryWrite(const std::vector<Blob*>& inputs);
|
|
bool blockingWrite(const std::vector<Blob*>& inputs);
|
|
void close();
|
|
size_t getNumBlobs() const {
|
|
return numBlobs_;
|
|
}
|
|
|
|
private:
|
|
bool canWrite();
|
|
void doWrite(const std::vector<Blob*>& inputs);
|
|
|
|
std::atomic<bool> closing_{false};
|
|
|
|
size_t numBlobs_;
|
|
std::mutex mutex_; // protects all variables in the class.
|
|
std::condition_variable cv_;
|
|
int64_t reader_{0};
|
|
int64_t writer_{0};
|
|
std::vector<std::vector<Blob*>> queue_;
|
|
|
|
struct QueueStats {
|
|
CAFFE_STAT_CTOR(QueueStats);
|
|
CAFFE_EXPORTED_STAT(queue_balance);
|
|
CAFFE_EXPORTED_STAT(queue_dequeued_records);
|
|
CAFFE_DETAILED_EXPORTED_STAT(queue_dequeued_bytes);
|
|
} stats_;
|
|
};
|
|
} // namespace caffe2
|