/usr/local/lib64/python3.6/site-packages/torch/include/caffe2/core
NameSizeModeActions
allocator.h1360644editdlrm
blob.h41680644editdlrm
blob_serialization.h107910644editdlrm
blob_serializer_base.h39050644editdlrm
blob_stats.h11270644editdlrm
common.h43290644editdlrm
common_cudnn.h98930644editdlrm
common_gpu.h214140644editdlrm
common_omp.h1560644editdlrm
context.h61740644editdlrm
context_base.h43820644editdlrm
context_gpu.h110140644editdlrm
cudnn_wrappers.h69560644editdlrm
db.h93520644editdlrm
distributions_stubs.h21610644editdlrm
event.h124200644editdlrm
event_cpu.h11920644editdlrm
export_c10_op_to_caffe2.h94870644editdlrm
export_caffe2_op_to_c10.h111010644editdlrm
flags.h740644editdlrm
graph.h52580644editdlrm
init.h64960644editdlrm
logging.h750644editdlrm
macros.h34260644editdlrm
memonger.h8170644editdlrm
module.h24730644editdlrm
net.h46340644editdlrm
net_async_base.h73970644editdlrm
net_async_scheduling.h9930644editdlrm
net_async_task.h8330644editdlrm
net_async_task_future.h19250644editdlrm
net_async_task_graph.h22530644editdlrm
net_async_tracing.h50930644editdlrm
net_dag_utils.h21460644editdlrm
net_parallel.h21440644editdlrm
net_simple.h26060644editdlrm
net_simple_refcount.h20970644editdlrm
numa.h720644editdlrm
observer.h38090644editdlrm
operator.h588720644editdlrm
operator_gradient.h102220644editdlrm
operator_schema.h184770644editdlrm
plan_executor.h2190644editdlrm
prof_dag_counters.h27510644editdlrm
qtensor.h66150644editdlrm
qtensor_serialization.h26240644editdlrm
scope_guard.h46750644editdlrm
static_tracepoint.h3980644editdlrm
static_tracepoint_elfx86.h55550644editdlrm
stats.h103650644editdlrm
storage.h7330644editdlrm
tensor.h186680644editdlrm
tensor_impl.h3510644editdlrm
tensor_int8.h4500644editdlrm
test_utils.h62850644editdlrm
timer.h12180644editdlrm
transform.h57410644editdlrm
types.h22480644editdlrm
workspace.h113050644editdlrm
Edit: /usr/local/lib64/python3.6/site-packages/torch/include/caffe2/core/context.h (6174B)
#ifndef CAFFE2_CORE_CONTEXT_H_ #define CAFFE2_CORE_CONTEXT_H_ #include #include #include #include #include #include "caffe2/core/allocator.h" #include "caffe2/core/context_base.h" #include "caffe2/core/event.h" #include "caffe2/core/logging.h" #include "caffe2/proto/caffe2_pb.h" #include #if !defined(CAFFE2_IS_XPLAT_BUILD) && !defined(C10_MOBILE) #include #include #include #else #include "caffe2/core/distributions_stubs.h" #endif C10_DECLARE_bool(caffe2_report_cpu_memory_usage); namespace caffe2 { /** * A function to generate a random number seed that is unique in a best-effort * basis, using an ever-incrementing seed and the current time. */ TORCH_API uint32_t RandomNumberSeed(); /** * The CPU Context, representing the bare minimum of what a Context class in * Caffe2 should implement. * * // TODO modify docs * See operator.h, especially Operator, for how Context are used in * actual operator implementations that are associated with specific devices. * In general, the Context class is passed in as a template argument, and * the operator can use the functions defined in the context to execute whatever * computation it has. * */ class TORCH_API CPUContext final : public BaseContext { public: #if !defined(CAFFE2_IS_XPLAT_BUILD) && !defined(C10_MOBILE) class rand_gen_type { public: explicit rand_gen_type(uint64_t seed_in = default_rng_seed_val) : engine_{seed_in} {} uint32_t random() { return engine_(); } uint64_t random64() { uint32_t random1 = engine_(); uint32_t random2 = engine_(); return (static_cast(random1) << 32) | random2; } c10::optional next_float_normal_sample() { return next_float_normal_sample_; } c10::optional next_double_normal_sample() { return next_double_normal_sample_; } void set_next_float_normal_sample(c10::optional randn) { next_float_normal_sample_ = randn; } void set_next_double_normal_sample(c10::optional randn) { next_double_normal_sample_ = randn; } private: at::mt19937 engine_; c10::optional next_float_normal_sample_; c10::optional next_double_normal_sample_; }; #else typedef std::mt19937 rand_gen_type; #endif CPUContext() {} explicit CPUContext(const DeviceOption& option) : random_seed_(option.has_random_seed() ? option.random_seed() : 1701), random_seed_set_(option.has_random_seed() ? true : false) { CAFFE_ENFORCE_EQ(option.device_type(), PROTO_CPU); } explicit CPUContext(const at::Device& device) : CPUContext(DeviceToOption(device)) {} ~CPUContext() noexcept override {} inline void SwitchToDevice(int64_t /*stream_id*/) override {} using BaseContext::SwitchToDevice; inline void WaitEvent(const Event& ev) override { ev.Wait(CPU, this); } inline void Record(Event* ev, const char* err_msg = nullptr) const override { CAFFE_ENFORCE(ev, "Event must not be null."); ev->Record(CPU, this, err_msg); } inline void FinishDeviceComputation() override {} inline rand_gen_type* RandGenerator() { if (!random_generator_.get()) { random_generator_.reset(new rand_gen_type(RandSeed())); } return random_generator_.get(); } inline uint32_t RandSeed() { if (!random_seed_set_) { random_seed_ = RandomNumberSeed(); random_seed_set_ = true; } return static_cast(random_seed_); } inline static at::DataPtr New(size_t nbytes) { return GetCPUAllocator()->allocate(nbytes); } void CopyBytesSameDevice(size_t nbytes, const void* src, void* dst) override; void CopyBytesFromCPU(size_t nbytes, const void* src, void* dst) override { CopyBytesSameDevice(nbytes, src, dst); } void CopyBytesToCPU(size_t nbytes, const void* src, void* dst) override { CopyBytesSameDevice(nbytes, src, dst); } bool SupportsNonFundamentalTypes() const override { // CPU non fumdamental type copy OK return true; } template inline void CopyBytes(size_t nbytes, const void* src, void* dst); template inline void Copy(size_t n, const T* src, T* dst) { if (c10::guts::is_fundamental::value) { CopyBytes( n * sizeof(T), static_cast(src), static_cast(dst)); } else { for (size_t i = 0; i < n; ++i) { dst[i] = src[i]; } } } template inline void CopyItems(const TypeMeta meta, size_t n, const void* src, void* dst) { if (meta.copy()) { meta.copy()(src, dst, n); } else { CopyBytes(n * meta.itemsize(), src, dst); } } // By default CPU operators don't have async device parts static bool HasAsyncPartDefault() { return false; } static bool SupportsAsyncScheduling() { return false; } // CPU streams are not implemented and are silently ignored by CPU ops, // return true to signal executor to schedule a CPU op static bool IsStreamFree( const DeviceOption& /* option */, int /* stream_id */) { return true; } at::Device device() const override { // TODO: numa? return at::Device(CPU); } DeviceType device_type() const override { return CPU; } static constexpr DeviceType GetDeviceType() { return CPU; } protected: // TODO(jiayq): instead of hard-coding a generator, make it more flexible. int random_seed_{1701}; bool random_seed_set_{false}; std::unique_ptr random_generator_; }; template <> inline void CPUContext::CopyBytes( size_t nbytes, const void* src, void* dst) { if (nbytes == 0) { return; } CAFFE_ENFORCE(src); CAFFE_ENFORCE(dst); memcpy(dst, src, nbytes); } } // namespace caffe2 #endif // CAFFE2_CORE_CONTEXT_H_