1 #include "caffe2/sgd/iter_op.h" 8 BlobSerializerBase::SerializationAcceptor acceptor) {
9 CAFFE_ENFORCE(blob.
IsType<std::unique_ptr<std::mutex>>());
11 blob_proto.set_name(name);
12 blob_proto.set_type(
"std::unique_ptr<std::mutex>");
13 blob_proto.set_content(
"");
14 acceptor(name, blob_proto.SerializeAsString());
17 void MutexDeserializer::Deserialize(
const BlobProto& ,
Blob* blob) {
18 *blob->
GetMutable<std::unique_ptr<std::mutex>>() =
19 caffe2::make_unique<std::mutex>();
25 REGISTER_BLOB_SERIALIZER(
33 .EnforceInplace({{0, 0}})
35 Stores a singe integer, that gets incremented on each call to Run(). 36 Useful for tracking the iteration count during SGD, for example. 39 OPERATOR_SCHEMA(AtomicIter) 42 .EnforceInplace({{1, 0}}) 44 Similar to Iter, but takes a mutex as the first input to make sure that 45 updates are carried out atomically. This can be used in e.g. Hogwild sgd 48 .Input(0, "mutex",
"The mutex used to do atomic increment.")
49 .Input(1,
"iter",
"The iter counter as an int64_t TensorCPU.");
52 NO_GRADIENT(AtomicIter);
Blob is a general container that hosts a typed pointer.
A global dictionary that holds information about what Caffe2 modules have been loaded in the current ...
T * GetMutable(bool *is_new_object=nullptr)
Gets a mutable pointer to the stored object.
bool IsType() const
Checks if the content stored in the blob is of type T.
void Serialize(const Blob &blob, const string &name, BlobSerializerBase::SerializationAcceptor acceptor) override
Serializes a std::unique_ptr<std::mutex>.