pytorch/caffe2/core
Peter Bell d701357d92 Factor out TensorBase that doesn't depend on native operators (#63612)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/63612

This makes Tensor inherit from a new class TensorBase, that provides a subset of Tensor that doesn't
directly depend on native_functions.yaml. Code that only includes TensorBase.h with thus not need to
be rebuilt every time someone changes an operator signature.

Making `Tensor` inherit from this class means that `const TensorBase&` parameters will be callable
with an ordinary `Tensor`. I've also made `Tensor` constructible and assignable from `TensorBase` to
minimize friction in code mixing the two types.

To help enforce that `Tensor.h` and `Functions.h` aren't accidentally included, I've added an error
into `Operators.h` if `TORCH_ASSERT_NO_OPERATORS` is defined. We can either set this in the build
system for certain folders, or just define it at the top of any file.

I've also included an example of manually special-casing the commonly used `contiguous` operator.
The inline function's slow path defers to `TensorBase::__dispatch_contiguous` which is defined in
`Tensor.cpp`. I've made it so `OptionalTensorRef` is constructible from `TensorBase`, so I can
materialize a `Tensor` for use in dispatch without actually increasing its refcount.

Test Plan: Imported from OSS

Reviewed By: gchanan

Differential Revision: D30728580

Pulled By: ezyang

fbshipit-source-id: 2cbc8eee08043382ee6904ea8e743b1286921c03
2021-09-08 13:28:54 -07:00
..
hip
nomnigraph Revert D30279364: [codemod][lint][fbcode/c*] Enable BLACK by default 2021-08-12 11:45:01 -07:00
__init__.py
allocator.cc
allocator.h
blob.h
blob_gpu_test.cc
blob_serialization.cc Disable avoid-non-const-global-variables lint check (#62008) 2021-07-22 18:04:40 -07:00
blob_serialization.h [caffe2] add an EstimateAllBlobSizes operator (#59775) 2021-06-24 16:55:22 -07:00
blob_serialization_gpu.cc
blob_serializer_base.h [caffe2] add an EstimateAllBlobSizes operator (#59775) 2021-06-24 16:55:22 -07:00
blob_stats.cc
blob_stats.h
blob_test.cc Stop exporting symbols in anonymous namespaces (#62952) 2021-08-09 12:52:12 -07:00
CMakeLists.txt
common.cc Disable avoid-non-const-global-variables lint check (#62008) 2021-07-22 18:04:40 -07:00
common.h [caffe2] Avoid attempt to use undefined preprocessor directive 2021-06-05 09:22:52 -07:00
common_cudnn.cc
common_cudnn.h
common_gpu.cc
common_gpu.h
common_omp.h
common_test.cc Disable avoid-non-const-global-variables lint check (#62008) 2021-07-22 18:04:40 -07:00
context.cc Disable avoid-non-const-global-variables lint check (#62008) 2021-07-22 18:04:40 -07:00
context.h [caffe2] break one circular dependency between Caffe2 and ATen-cpu (#62632) 2021-08-02 22:40:56 -07:00
context_base.cc Disable avoid-non-const-global-variables lint check (#62008) 2021-07-22 18:04:40 -07:00
context_base.h External stream (#59527) 2021-06-14 13:46:11 -07:00
context_gpu.cu use device methods (#52899) 2021-03-02 20:14:23 -08:00
context_gpu.h cast return of cudaGetLastError() to void when discarding (#62518) 2021-08-03 11:17:22 -07:00
context_gpu_test.cc
context_test.cc Disable avoid-non-const-global-variables lint check (#62008) 2021-07-22 18:04:40 -07:00
cudnn_wrappers.h
db.cc Disable avoid-non-const-global-variables lint check (#62008) 2021-07-22 18:04:40 -07:00
db.h [caffe2] update db::Transaction::Put() to accept the value by rvalue reference (#60208) 2021-06-23 22:12:53 -07:00
distributions_stubs.h
event.cc Disable avoid-non-const-global-variables lint check (#62008) 2021-07-22 18:04:40 -07:00
event.h
event_cpu.h
event_gpu.cc cast return of cudaGetLastError() to void when discarding (#62518) 2021-08-03 11:17:22 -07:00
event_gpu_test.cc
event_test.cc Disable avoid-non-const-global-variables lint check (#62008) 2021-07-22 18:04:40 -07:00
export_c10_op_to_caffe2.cc Disable avoid-non-const-global-variables lint check (#62008) 2021-07-22 18:04:40 -07:00
export_c10_op_to_caffe2.h Make PyTorch code-base clang-tidy compliant (#56892) 2021-04-28 14:10:25 -07:00
export_caffe2_op_to_c10.h Don't switch streams when running Caffe2 ops from c10. (#55121) 2021-04-08 13:21:11 -07:00
flags.h
graph.cc Make PyTorch code-base clang-tidy compliant (#56892) 2021-04-28 14:10:25 -07:00
graph.h
graph_test.cc Disable avoid-non-const-global-variables lint check (#62008) 2021-07-22 18:04:40 -07:00
init.cc [PyTorch] Remove unnecessary iostream includes in headers (#61500) 2021-08-19 18:54:51 -07:00
init.h
init_denormals.cc Disable avoid-non-const-global-variables lint check (#62008) 2021-07-22 18:04:40 -07:00
init_intrinsics_check.cc Disable avoid-non-const-global-variables lint check (#62008) 2021-07-22 18:04:40 -07:00
init_omp.cc Disable avoid-non-const-global-variables lint check (#62008) 2021-07-22 18:04:40 -07:00
init_test.cc Disable avoid-non-const-global-variables lint check (#62008) 2021-07-22 18:04:40 -07:00
int8_serialization.cc Disable avoid-non-const-global-variables lint check (#62008) 2021-07-22 18:04:40 -07:00
logging.h
macros.h
macros.h.in
memonger.cc [clang-tidy] Exclude cppcoreguidelines-avoid-magic-numbers (#57841) 2021-05-07 20:02:33 -07:00
memonger.h
module.cc
module.h
module_test.cc Disable avoid-non-const-global-variables lint check (#62008) 2021-07-22 18:04:40 -07:00
net.cc Disable avoid-non-const-global-variables lint check (#62008) 2021-07-22 18:04:40 -07:00
net.h
net_async_base.cc Disable avoid-non-const-global-variables lint check (#62008) 2021-07-22 18:04:40 -07:00
net_async_base.h
net_async_scheduling.cc Disable avoid-non-const-global-variables lint check (#62008) 2021-07-22 18:04:40 -07:00
net_async_scheduling.h
net_async_task.cc Make PyTorch code-base clang-tidy compliant (#56892) 2021-04-28 14:10:25 -07:00
net_async_task.h
net_async_task_future.cc Make PyTorch code-base clang-tidy compliant (#56892) 2021-04-28 14:10:25 -07:00
net_async_task_future.h
net_async_task_graph.cc
net_async_task_graph.h
net_async_tracing.cc Disable avoid-non-const-global-variables lint check (#62008) 2021-07-22 18:04:40 -07:00
net_async_tracing.h Make PyTorch code-base clang-tidy compliant (#56892) 2021-04-28 14:10:25 -07:00
net_async_tracing_test.cc Disable avoid-non-const-global-variables lint check (#62008) 2021-07-22 18:04:40 -07:00
net_dag_utils.cc
net_dag_utils.h
net_dag_utils_test.cc Fix warnings (#62930) 2021-08-11 14:07:10 -07:00
net_gpu_test.cc
net_parallel.cc Disable avoid-non-const-global-variables lint check (#62008) 2021-07-22 18:04:40 -07:00
net_parallel.h
net_simple.cc Disable avoid-non-const-global-variables lint check (#62008) 2021-07-22 18:04:40 -07:00
net_simple.h [Caffe2] Implement BlackBoxPredictor::BenchmarkIndividualOps (#52903) 2021-02-27 19:49:22 -08:00
net_simple_refcount.cc Disable avoid-non-const-global-variables lint check (#62008) 2021-07-22 18:04:40 -07:00
net_simple_refcount.h
net_simple_refcount_test.cc Disable avoid-non-const-global-variables lint check (#62008) 2021-07-22 18:04:40 -07:00
net_test.cc Disable avoid-non-const-global-variables lint check (#62008) 2021-07-22 18:04:40 -07:00
numa.cc
numa.h
observer.h
observer_test.cc Disable avoid-non-const-global-variables lint check (#62008) 2021-07-22 18:04:40 -07:00
operator.cc [Caffe2] Create fewer strings during argument fetching (#64285) 2021-09-01 13:30:54 -07:00
operator.h [Caffe2] Create fewer strings during argument fetching (#64285) 2021-09-01 13:30:54 -07:00
operator_gpu_test.cc
operator_gradient.h
operator_schema.cc [PyTorch] Remove unnecessary iostream includes in headers (#61500) 2021-08-19 18:54:51 -07:00
operator_schema.h Fix bytes_written and bytes_read (#64244) 2021-09-01 13:35:41 -07:00
operator_schema_test.cc Disable avoid-non-const-global-variables lint check (#62008) 2021-07-22 18:04:40 -07:00
operator_test.cc Disable avoid-non-const-global-variables lint check (#62008) 2021-07-22 18:04:40 -07:00
parallel_net_test.cc Disable avoid-non-const-global-variables lint check (#62008) 2021-07-22 18:04:40 -07:00
plan_executor.cc Disable avoid-non-const-global-variables lint check (#62008) 2021-07-22 18:04:40 -07:00
plan_executor.h
plan_executor_test.cc Fix broken caffe2 test: PlanExecutorTest.BlockingErrorPlan (#64401) 2021-09-02 08:30:29 -07:00
prof_dag_counters.cc [clang-tidy] Exclude cppcoreguidelines-avoid-magic-numbers (#57841) 2021-05-07 20:02:33 -07:00
prof_dag_counters.h
qtensor.cc
qtensor.h Make PyTorch code-base clang-tidy compliant (#56892) 2021-04-28 14:10:25 -07:00
qtensor_serialization.cc Disable avoid-non-const-global-variables lint check (#62008) 2021-07-22 18:04:40 -07:00
qtensor_serialization.h
scope_guard.h
serialization_test.cc Disable avoid-non-const-global-variables lint check (#62008) 2021-07-22 18:04:40 -07:00
static_tracepoint.h
static_tracepoint_elfx86.h
stats.cc Make PyTorch code-base clang-tidy compliant (#56892) 2021-04-28 14:10:25 -07:00
stats.h
stats_test.cc Disable avoid-non-const-global-variables lint check (#62008) 2021-07-22 18:04:40 -07:00
storage.h
tensor.cc Factor out TensorBase that doesn't depend on native operators (#63612) 2021-09-08 13:28:54 -07:00
tensor.h [caffe2] Don't call TensorImpl::size() in dim32() (#53852) 2021-03-12 16:22:29 -08:00
tensor_impl.h
tensor_int8.cc
tensor_int8.h
test_utils.cc [Caffe2][Testing] Check for equality first in assertTensorEqualsWithType<float> (#61006) 2021-06-29 23:31:37 -07:00
test_utils.h Make PyTorch code-base clang-tidy compliant (#56892) 2021-04-28 14:10:25 -07:00
timer.h
timer_test.cc Disable avoid-non-const-global-variables lint check (#62008) 2021-07-22 18:04:40 -07:00
transform.cc Disable avoid-non-const-global-variables lint check (#62008) 2021-07-22 18:04:40 -07:00
transform.h
transform_test.cc Disable avoid-non-const-global-variables lint check (#62008) 2021-07-22 18:04:40 -07:00
types.cc
types.h
workspace.cc Disable avoid-non-const-global-variables lint check (#62008) 2021-07-22 18:04:40 -07:00
workspace.h [caffe2] Avoid some double (and triple) lookups in workspace (#53319) 2021-03-04 22:57:02 -08:00
workspace_test.cc Disable avoid-non-const-global-variables lint check (#62008) 2021-07-22 18:04:40 -07:00