/
usr
/
local
/
lib64
/
python3.6
/
site-packages
/
torch
/
include
/
caffe2
/
core
/
/usr/local/lib64/python3.6/site-packages/torch/include/caffe2/core
mkdir
upload
Name
Size
Mode
Actions
allocator.h
136
0644
edit
dl
rm
blob.h
4168
0644
edit
dl
rm
blob_serialization.h
10791
0644
edit
dl
rm
blob_serializer_base.h
3905
0644
edit
dl
rm
blob_stats.h
1127
0644
edit
dl
rm
common.h
4329
0644
edit
dl
rm
common_cudnn.h
9893
0644
edit
dl
rm
common_gpu.h
21414
0644
edit
dl
rm
common_omp.h
156
0644
edit
dl
rm
context.h
6174
0644
edit
dl
rm
context_base.h
4382
0644
edit
dl
rm
context_gpu.h
11014
0644
edit
dl
rm
cudnn_wrappers.h
6956
0644
edit
dl
rm
db.h
9352
0644
edit
dl
rm
distributions_stubs.h
2161
0644
edit
dl
rm
event.h
12420
0644
edit
dl
rm
event_cpu.h
1192
0644
edit
dl
rm
export_c10_op_to_caffe2.h
9487
0644
edit
dl
rm
export_caffe2_op_to_c10.h
11101
0644
edit
dl
rm
flags.h
74
0644
edit
dl
rm
graph.h
5258
0644
edit
dl
rm
init.h
6496
0644
edit
dl
rm
logging.h
75
0644
edit
dl
rm
macros.h
3426
0644
edit
dl
rm
memonger.h
817
0644
edit
dl
rm
module.h
2473
0644
edit
dl
rm
net.h
4634
0644
edit
dl
rm
net_async_base.h
7397
0644
edit
dl
rm
net_async_scheduling.h
993
0644
edit
dl
rm
net_async_task.h
833
0644
edit
dl
rm
net_async_task_future.h
1925
0644
edit
dl
rm
net_async_task_graph.h
2253
0644
edit
dl
rm
net_async_tracing.h
5093
0644
edit
dl
rm
net_dag_utils.h
2146
0644
edit
dl
rm
net_parallel.h
2144
0644
edit
dl
rm
net_simple.h
2606
0644
edit
dl
rm
net_simple_refcount.h
2097
0644
edit
dl
rm
numa.h
72
0644
edit
dl
rm
observer.h
3809
0644
edit
dl
rm
operator.h
58872
0644
edit
dl
rm
operator_gradient.h
10222
0644
edit
dl
rm
operator_schema.h
18477
0644
edit
dl
rm
plan_executor.h
219
0644
edit
dl
rm
prof_dag_counters.h
2751
0644
edit
dl
rm
qtensor.h
6615
0644
edit
dl
rm
qtensor_serialization.h
2624
0644
edit
dl
rm
scope_guard.h
4675
0644
edit
dl
rm
static_tracepoint.h
398
0644
edit
dl
rm
static_tracepoint_elfx86.h
5555
0644
edit
dl
rm
stats.h
10365
0644
edit
dl
rm
storage.h
733
0644
edit
dl
rm
tensor.h
18668
0644
edit
dl
rm
tensor_impl.h
351
0644
edit
dl
rm
tensor_int8.h
450
0644
edit
dl
rm
test_utils.h
6285
0644
edit
dl
rm
timer.h
1218
0644
edit
dl
rm
transform.h
5741
0644
edit
dl
rm
types.h
2248
0644
edit
dl
rm
workspace.h
11305
0644
edit
dl
rm
Edit:
/usr/local/lib64/python3.6/site-packages/torch/include/caffe2/core/test_utils.h
(6285B)
#ifndef CAFFE2_UTILS_TEST_UTILS_H_ #define CAFFE2_UTILS_TEST_UTILS_H_ #include "caffe2/core/tensor.h" #include "caffe2/core/workspace.h" #include "caffe2/utils/proto_utils.h" #include <c10/macros/Macros.h> #include <cmath> #include <string> #include <vector> // Utilities that make it easier to write caffe2 C++ unit tests. // These utils are designed to be concise and easy to use. They may sacrifice // performance and should only be used in tests/non production code. namespace caffe2 { namespace testing { // Asserts that the values of two tensors are the same. TORCH_API void assertTensorEquals( const TensorCPU& tensor1, const TensorCPU& tensor2, float eps = 1e-6); // Asserts that two float values are close within epsilon. TORCH_API void assertNear(float value1, float value2, float epsilon); // Asserts that the numeric values of a tensor is equal to a data vector. template <typename T> void assertTensorEquals( const TensorCPU& tensor, const std::vector<T>& data, float epsilon = 0.1f) { CAFFE_ENFORCE(tensor.IsType<T>()); CAFFE_ENFORCE_EQ(tensor.numel(), data.size()); for (auto idx = 0; idx < tensor.numel(); ++idx) { if (tensor.IsType<float>()) { assertNear(tensor.data<T>()[idx], data[idx], epsilon); } else { CAFFE_ENFORCE_EQ(tensor.data<T>()[idx], data[idx]); } } } // Assertion for tensor sizes and values. template <typename T> void assertTensor( const TensorCPU& tensor, const std::vector<int64_t>& sizes, const std::vector<T>& data, float epsilon = 0.1f) { CAFFE_ENFORCE_EQ(tensor.sizes(), sizes); assertTensorEquals(tensor, data, epsilon); } // Asserts a list of tensors presented in two workspaces are equal. TORCH_API void assertTensorListEquals( const std::vector<std::string>& tensorNames, const Workspace& workspace1, const Workspace& workspace2); // Read a tensor from the workspace. TORCH_API const caffe2::Tensor& getTensor( const caffe2::Workspace& workspace, const std::string& name); // Create a new tensor in the workspace. TORCH_API caffe2::Tensor* createTensor( const std::string& name, caffe2::Workspace* workspace); // Create a new operator in the net. TORCH_API caffe2::OperatorDef* createOperator( const std::string& type, const std::vector<std::string>& inputs, const std::vector<std::string>& outputs, caffe2::NetDef* net); // Fill a buffer with randomly generated numbers given range [min, max) // T can only be float, double or long double template <typename RealType = float> void randomFill( RealType* data, size_t size, const double min = 0.0, const double max = 1.0) { std::mt19937 gen(42); std::uniform_real_distribution<RealType> dis( static_cast<RealType>(min), static_cast<RealType>(max)); for (size_t i = 0; i < size; i++) { data[i] = dis(gen); } } // Fill data from a vector to a tensor. template <typename T> void fillTensor( const std::vector<int64_t>& shape, const std::vector<T>& data, TensorCPU* tensor) { tensor->Resize(shape); CAFFE_ENFORCE_EQ(data.size(), tensor->numel()); auto ptr = tensor->mutable_data<T>(); for (int i = 0; i < tensor->numel(); ++i) { ptr[i] = data[i]; } } // Create a tensor and fill data. template <typename T> caffe2::Tensor* createTensorAndFill( const std::string& name, const std::vector<int64_t>& shape, const std::vector<T>& data, Workspace* workspace) { auto* tensor = createTensor(name, workspace); fillTensor<T>(shape, data, tensor); return tensor; } template <typename T> caffe2::Tensor createTensorAndFill( const std::vector<int64_t>& shape, const std::vector<T>& data) { Tensor tensor(caffe2::CPU); fillTensor<T>(shape, data, &tensor); return tensor; } // Fill a constant to a tensor. template <typename T> void constantFillTensor( const vector<int64_t>& shape, const T& data, TensorCPU* tensor) { tensor->Resize(shape); auto ptr = tensor->mutable_data<T>(); for (int i = 0; i < tensor->numel(); ++i) { ptr[i] = data; } } // Create a tensor and fill a constant. template <typename T> caffe2::Tensor* createTensorAndConstantFill( const std::string& name, const std::vector<int64_t>& shape, const T& data, Workspace* workspace) { auto* tensor = createTensor(name, workspace); constantFillTensor<T>(shape, data, tensor); return tensor; } // Concise util class to mutate a net in a chaining fashion. class TORCH_API NetMutator { public: // NOLINTNEXTLINE(clang-analyzer-optin.cplusplus.UninitializedObject) explicit NetMutator(caffe2::NetDef* net) : net_(net) {} NetMutator& newOp( const std::string& type, const std::vector<std::string>& inputs, const std::vector<std::string>& outputs); NetMutator& externalInputs(const std::vector<std::string>& externalInputs); NetMutator& externalOutputs(const std::vector<std::string>& externalOutputs); // Add argument to the last created op. template <typename T> NetMutator& addArgument(const std::string& name, const T& value) { CAFFE_ENFORCE(lastCreatedOp_ != nullptr); AddArgument(name, value, lastCreatedOp_); return *this; } // Set device name for the last created op. NetMutator& setDeviceOptionName(const std::string& name); private: caffe2::NetDef* net_; caffe2::OperatorDef* lastCreatedOp_; }; // Concise util class to mutate a workspace in a chaining fashion. class TORCH_API WorkspaceMutator { public: explicit WorkspaceMutator(caffe2::Workspace* workspace) : workspace_(workspace) {} // New tensor filled by a data vector. template <typename T> WorkspaceMutator& newTensor( const std::string& name, const std::vector<int64_t>& shape, const std::vector<T>& data) { createTensorAndFill<T>(name, shape, data, workspace_); return *this; } // New tensor filled by a constant. template <typename T> WorkspaceMutator& newTensorConst( const std::string& name, const std::vector<int64_t>& shape, const T& data) { createTensorAndConstantFill<T>(name, shape, data, workspace_); return *this; } private: caffe2::Workspace* workspace_; }; } // namespace testing } // namespace caffe2 #endif // CAFFE2_UTILS_TEST_UTILS_H_
Save
cmd:
run