/
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/qtensor.h
(6615B)
#ifndef CAFFE2_CORE_QTENSOR_H_ #define CAFFE2_CORE_QTENSOR_H_ #include "caffe2/core/common.h" #include "caffe2/core/context.h" #include "caffe2/core/tensor.h" #include <c10/util/accumulate.h> #include <c10/util/typeid.h> #include <algorithm> #include <climits> #include <cstddef> #include <vector> namespace caffe2 { template <class Context> class C10_EXPORT QTensor { public: QTensor() {} virtual ~QTensor() {} /** * @brief Creates a quantized tensor of the given dimension. * * Note that the actual data allocation is not going to be carried out until * the first time mutable_data() is called. * * The underlying storage of the quantized tensor interleaves elements * by bit depth. * * Labeled memory for tensor of size 6, precision 3 * [ E1[0] E2[0] E3[0] E4[0] E5[0] E6[0] ] // Least significant Bits * [ E1[1] E2[1] E3[1] E4[1] E5[1] E6[1] ] * [ E1[2] E2[2] E3[2] E4[2] E5[2] E6[2] ] * * In the case of sign bits (see enable_sign argument), an extra bit * per element is added: * * Labeled memory for tensor of size 6, precision 3, sign bit enabled * [ E1[0] E2[0] E3[0] E4[0] E5[0] E6[0] ] * [ E1[1] E2[1] E3[1] E4[1] E5[1] E6[1] ] * [ E1[2] E2[2] E3[2] E4[2] E5[2] E6[2] ] * [ E1[s] E2[s] E3[s] E4[s] E5[s] E6[s] ] * Where 's' is 1 if E is negative * * The reason for this layout is the ability to efficiently multiply * many low precision integers as a sum of popcnt(A & B) * 1 << bit. * Explained here: https://arxiv.org/abs/1606.06160 */ // TODO: changing at::ArrayRef<int> to at::ArrayRef<int64_t>? explicit QTensor( at::ArrayRef<int> dims, const unsigned char precision, const bool signbit = false) : precision_(precision), signed_(signbit) { Resize(dims); } void Resize(at::ArrayRef<int> dim_source) { if (dims_ != dim_source) { const auto source_size = c10::multiply_integers(dim_source); // NOLINTNEXTLINE(clang-diagnostic-sign-compare) if ((source_size * (precision_ + signed_)) > capacity_) { data_ptr_.clear(); capacity_ = 0; } dims_ = dim_source.vec(); size_ = source_size; } } void SetBitAtIndex(const unsigned char bit, const size_t index, const bool value) { // Get the mutable data at bit depth `bit`. unsigned char* d = mutable_data(); CAFFE_ENFORCE( bit < precision_ + signed_, "Attempted to a set a bit that is not allocated."); CAFFE_ENFORCE(bit * aligned_size() < capacity_); auto idx = (aligned_size() * bit) / CHAR_BIT; d = &d[idx]; idx = index / CHAR_BIT; auto shift = CHAR_BIT - (index % CHAR_BIT) - 1; if (value) { d[idx] |= 1 << shift; } else { d[idx] &= ~(1 << shift); } } bool GetBitAtIndex(const unsigned char bit, const size_t index) const { // Get the data at bit depth `bit` const unsigned char* d = data(); auto idx = (aligned_size() * bit) / CHAR_BIT; d = &d[idx]; idx = index / CHAR_BIT; auto shift = CHAR_BIT - (index % CHAR_BIT) - 1; return d[idx] & (1 << shift); } void SetPrecision(const unsigned char precision) { precision_ = precision; data_ptr_.clear(); } void SetSigned(const bool make_signed = true) { signed_ = make_signed; data_ptr_.clear(); } void SetScale(const double scale) { scale_ = scale; } void SetBias(const double bias) { bias_ = bias; } unsigned char* mutable_data() { if (!data_ptr_) { data_ptr_ = Context::New(nbytes()); capacity_ = nbytes() * CHAR_BIT; } CAFFE_ENFORCE(capacity_ == nbytes() * CHAR_BIT); return static_cast<unsigned char*>(data_ptr_.get()); } inline const unsigned char* data() const { return static_cast<unsigned char*>(data_ptr_.get()); } inline size_t size() const { return size_; } inline unsigned char alignment() const { return alignment_; } inline unsigned char precision() const { return precision_; } inline at::ArrayRef<int> sizes() const { return dims_; } // TODO: deprecate? inline at::ArrayRef<int> dims() const { return dims_; } inline bool is_signed() const { return signed_; } /** * Returns the number of dimensions of the data. */ inline int ndim() const { return dims_.size(); } inline size_t aligned_size() const { return alignment_ * ((size_ + alignment_ - 1) / alignment_); } inline size_t nbytes() const { return (aligned_size() * (precision_ + signed_)) / CHAR_BIT; } inline double scale() const { return scale_; } inline double bias() const { return bias_; } /** * Returns the i-th dimension of the qtensor in int. */ inline int dim32(const int i) const { DCHECK_LT(i, dims_.size()) << "Exceeding ndim limit " << dims_.size(); DCHECK_GE(i, 0) << "Cannot have negative index"; CAFFE_ENFORCE_LT(dims_[i], std::numeric_limits<int>::max()); return static_cast<int>(dims_[i]); } /** * Returns the 'canonical' version of a (usually) user-specified axis, * allowing for negative indexing (e.g., -1 for the last axis). * * @param axis_index the axis index. * If 0 <= index < ndim(), return index. * If -ndim <= index <= -1, return (ndim() - (-index)), * e.g., the last axis index (ndim() - 1) if index == -1, * the second to last if index == -2, etc. * Dies on out of range index. */ inline int canonical_axis_index(int axis_index) const { CAFFE_ENFORCE_GE(axis_index, -ndim()); CAFFE_ENFORCE_LT(axis_index, ndim()); if (axis_index < 0) { return axis_index + ndim(); } return axis_index; } /** * Return product of all dimensions starting from K. */ inline int64_t size_from_dim(int k) const { int64_t r = 1; for (int i = k; i < dims_.size(); ++i) { r *= dims_[i]; } return r; } /** * Product of all dims up to. */ inline int64_t size_to_dim(int k) const { CAFFE_ENFORCE(k < dims_.size()); int64_t r = 1; for (int i = 0; i < k; ++i) { r *= dims_[i]; } return r; } protected: std::vector<int> dims_; size_t size_ = 0; // Precision in bits. unsigned char precision_ = CHAR_BIT; // Bit alignment. unsigned char alignment_ = CHAR_BIT; // Allocated data. at::DataPtr data_ptr_; // value = scale_ * (x + bias_) double scale_; double bias_; bool signed_ = false; // Capacity in bits. size_t capacity_ = 0; }; } // namespace caffe2 #endif // CAFFE2_CORE_QTENSOR_H_
Save
cmd:
run