/usr/local/lib64/python3.6/site-packages/torch/include/ATen/native
NameSizeModeActions
cpu/-0755rm
cuda/-0755rm
quantized/-0755rm
Activation.h30690644editdlrm
AdaptivePooling.h11650644editdlrm
BatchLinearAlgebra.h82460644editdlrm
batch_norm.h12850644editdlrm
BinaryOps.h49160644editdlrm
BucketizationUtils.h42480644editdlrm
ComplexHelper.h37970644editdlrm
CompositeRandomAccessor.h8880644editdlrm
CompositeRandomAccessorCommon.h67130644editdlrm
ConvUtils.h53500644editdlrm
Copy.h3560644editdlrm
CPUBlas.h41990644editdlrm
CPUFallback.h24040644editdlrm
Cross.h2620644editdlrm
DilatedConvolutionUtils.h64160644editdlrm
DispatchStub.h76720644editdlrm
Distance.h7320644editdlrm
Distributions.h216540644editdlrm
DistributionTemplates.h186230644editdlrm
EmbeddingBag.h13200644editdlrm
Fill.h3840644editdlrm
ForeachUtils.h59620644editdlrm
FunctionOfAMatrixUtils.h4360644editdlrm
GridSampler.h105250644editdlrm
group_norm.h8960644editdlrm
Histogram.h4920644editdlrm
im2col.h28380644editdlrm
im2col_shape_check.h61810644editdlrm
IndexingUtils.h53730644editdlrm
layer_norm.h28920644editdlrm
Lerp.h5530644editdlrm
LinearAlgebra.h6030644editdlrm
LinearAlgebraUtils.h252360644editdlrm
LossMulti.h21970644editdlrm
Math.h913560644editdlrm
MathBitFallThroughLists.h40860644editdlrm
MathBitsFallback.h73260644editdlrm
MaxPooling.h12340644editdlrm
Normalization.h3020644editdlrm
PointwiseOps.h7490644editdlrm
Pool.h109220644editdlrm
Pow.h16940644editdlrm
ReduceAllOps.h3780644editdlrm
ReduceOps.h17450644editdlrm
ReduceOpsUtils.h122450644editdlrm
Repeat.h12860644editdlrm
Resize.h65010644editdlrm
ResizeCommon.h13210644editdlrm
RNN.h24670644editdlrm
ScatterGatherChecks.h36410644editdlrm
SegmentReduce.h6850644editdlrm
SharedReduceOps.h157850644editdlrm
SobolEngineOpsUtils.h17230644editdlrm
Sorting.h5360644editdlrm
SortingUtils.h57220644editdlrm
SpectralOpsUtils.h31460644editdlrm
StridedRandomAccessor.h68470644editdlrm
TensorAdvancedIndexing.h30720644editdlrm
TensorCompare.h13330644editdlrm
TensorDimApply.h18320644editdlrm
TensorFactories.h33820644editdlrm
TensorIterator.h460644editdlrm
TensorIteratorDynamicCasting.h20250644editdlrm
TensorShape.h10490644editdlrm
TensorTransformations.h9380644editdlrm
TriangularOpsUtils.h20000644editdlrm
TypeProperties.h4960644editdlrm
UnaryOps.h44640644editdlrm
Unfold2d.h5510644editdlrm
Unfold3d.h8520644editdlrm
UnfoldBackward.h53980644editdlrm
UpSample.h135990644editdlrm
vol2col.h36420644editdlrm
Edit: /usr/local/lib64/python3.6/site-packages/torch/include/ATen/native/MathBitsFallback.h (7326B)
#include #include #include #include #include #include #include #include namespace at { namespace native { // This fallback should only be used for operations that are self inverse and have a corresponding tensor // bit (internally implemented using DispatchKey) to maintain the state on tensor using tensor bit. // Currently there are two tensor bits that trigger this fallback: conjugate bit and negative bit. // Conjugate bit is set on a tensor when `.conj()` is called and neg bit is set on a tensor when `.conj().imag` is called. // NOTE: To use this fallback, `clone` and `copy_` should fully understand and be able to correctly handle the semantic of your math bit. struct MathOpFallback { MathOpFallback(DispatchKey key_, string op_name_) : key(key_), op_name(op_name_) {} virtual bool is_bit_set(const Tensor&) = 0; void fallback_impl(const c10::OperatorHandle& op, DispatchKeySet dispatch_keys, torch::jit::Stack* stack) { /* Situations to handle: 1. Out-of-place operation. Easy: materialize all inputs and call it a day. 2. Inplace operation. Desugar x.add_(2) into x.conj_().add_(2).conj_(). Materialize other inputs as in (1). 3. out= operation. Desugar add(x, 2, out=y) into y.copy_(add(x, 2)) Materialize other inputs as in (1). It is important to be able to tell if we READ from an argument and if we WRITE to an argument. Conservative approach is to assume that we always READ from an argument, but in out= operations you can skip conjugating inputs on entry that never get used. In the current schema we can't easily tell if the operation is in in-place or out= operation. Note: 1. Mutable tensorlists containing tensors whose math bit set to true are disallowed. 2. Mutable tensors with math bit set to true are unconditionally cloned to ensure correct behavior in the case when the mutable tensor shares memory with non mutable arguments. If we were to in-place resolve the math bit for mutable inputs, then the non-mutable inputs sharing partial or full memory with these mutable inputs would read into wrong values in the following cases: 1. Non mutable inputs have their math bit set to false. 2. Math bit for mutable input(s) is resolved before the non mutable inputs (with bit set to true and sharing memory with one or more mutable arg(s)) are cloned. At the end, the final value of the mutable arguments from the stack are copied into the original input mutable tensor inputs. */ const auto& arguments = op.schema().arguments(); const auto num_arguments = arguments.size(); const auto stack_start = stack->size() - num_arguments; c10::optional is_write; for (const auto i : c10::irange(num_arguments)) { // Three possible states: // 1. alias_info has no value --> out-of-place operation // 2. alias_info does have a value, alias_info->is_write=True --> in-place or out= operation // 3. alias_info does have a value, alias_info->is_write=False --> view operation const auto& alias_info = arguments[i].alias_info(); if (alias_info.has_value()) { if (is_write.has_value()) { TORCH_CHECK(*is_write == alias_info->isWrite(), "Unsupported operator for ", op_name, " fallback: ", op.schema().name(), op_name, " fallback doesn't work for operators with a mix " "mutable and non-mutable inputs that alias with outputs, " "this must be implemented manually. " "If you got this error on a core op, please report a bug to PyTorch."); } else { is_write = alias_info->isWrite(); } } } if (is_write.has_value() && !*is_write) { // We assume that view operators automatically handle the math bit // correctly by propagating the dispatch key in key_set. // This is not necessarily always right, so you should test these cases. op.redispatchBoxed(dispatch_keys & c10::DispatchKeySet(DispatchKeySet::FULL_AFTER, key), stack); return; } // Mutable inputs with math bit set to True and their clones std::vector> mutable_inputs_with_their_clones; for (const auto i : c10::irange(num_arguments)) { auto& ivalue = (*stack)[stack_start + i]; if (!(ivalue.isTensor() || ivalue.isTensorList())) { continue; } const auto& argument = arguments[i]; bool mut_arg = false; if (argument.alias_info()) { // Was already tested by is_write loop above TORCH_INTERNAL_ASSERT_DEBUG_ONLY(argument.alias_info()->isWrite()); mut_arg = true; } if (ivalue.isTensor()) { if (!is_bit_set(ivalue.toTensor())) { continue; } auto tensor = std::move(ivalue).toTensor(); TORCH_CHECK_NOT_IMPLEMENTED(!tensor.is_meta(), op_name, " fallback does not support meta tensors."); auto resolved_tensor = at::clone(tensor); if (mut_arg) { TORCH_CHECK(mutable_inputs_with_their_clones.empty(), op_name, " fallback does not support operators with more than one mutable tensors with ", op_name, "bit set to true."); mutable_inputs_with_their_clones.emplace_back(std::make_pair(std::move(tensor), resolved_tensor)); } (*stack)[stack_start + i] = std::move(resolved_tensor); } else if (ivalue.isTensorList()) { auto tensors = std::move(ivalue).toTensorList(); for(const auto j : c10::irange(tensors.size())) { const auto& tensor = tensors[j]; if (!is_bit_set(tensor)) { continue; } TORCH_CHECK(!mut_arg, " fallback doesn't currently support mutable TensorLists with ", op_name, " inputs. Please materialize all the ", op_name, " input tensor(s) in the mutable TensorList inputs before calling ", op.schema().name()); tensors[j] = at::clone(tensor); } (*stack)[stack_start + i] = std::move(tensors); } } op.redispatchBoxed(dispatch_keys & c10::DispatchKeySet(DispatchKeySet::FULL_AFTER, key), stack); TORCH_INTERNAL_ASSERT(mutable_inputs_with_their_clones.size() <= 1); for (std::pair mut_tensors: mutable_inputs_with_their_clones) { auto& mutable_input = mut_tensors.first; auto& cloned_mutable_input = mut_tensors.second; auto& ivalue = (*stack)[stack_start]; auto returned_output = std::move(ivalue).toTensor(); // sanity check to ensure that the tensor in stack aliases the cloned_mutable_input TORCH_INTERNAL_ASSERT(cloned_mutable_input.is_same(returned_output)); // necessary for out= arg at::native::resize_output(mutable_input, returned_output.sizes()); mutable_input.copy_(returned_output); (*stack)[stack_start] = std::move(mutable_input); } } virtual ~MathOpFallback() = default; DispatchKey key; string op_name; }; } }// namespace at