/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/ForeachUtils.h (5962B)
#pragma once #include #include namespace at { namespace native { namespace { // Check if tensor list has either a boolean tensor or a integer tensor bool has_integral_tensor(TensorList tensors, const bool includeBool) { return std::any_of(tensors.begin(), tensors.end(), [&includeBool](const auto & t) { return at::isIntegralType(t.scalar_type(), includeBool); }); } // check if tensor list has bool tensors bool has_bool_tensor(TensorList tensors) { return std::any_of(tensors.begin(), tensors.end(), [](const auto & t) -> bool { return t.scalar_type() == ScalarType::Bool; }); } // Check foreach API restrictions // - Tensor lists must be non-empty. // - All TensorLists and ScalarLists must have the same number of elements. // - Corresponding tensors must have the same size. void check_foreach_api_restrictions(TensorList tensors) { TORCH_CHECK(tensors.size() > 0, "Tensor list must have at least one tensor."); } void check_foreach_api_restrictions(TensorList tensors, ArrayRef scalars) { check_foreach_api_restrictions(tensors); TORCH_CHECK(tensors.size() == scalars.size(), "Tensor list must have same number of elements as scalar list."); } void check_foreach_api_restrictions(TensorList tensors1, TensorList tensors2) { TORCH_CHECK(tensors1.size() > 0, "Tensor list must have at least one tensor."); TORCH_CHECK(tensors2.size() > 0, "Tensor list must have at least one tensor."); TORCH_CHECK(tensors1.size() == tensors2.size(), "Tensor lists must have the same number of tensors, got ", tensors1.size(), " and ", tensors2.size()); } void check_foreach_api_restrictions(TensorList tensors1, TensorList tensors2, TensorList tensors3) { TORCH_CHECK(tensors1.size() > 0, "Tensor list must have at least one tensor."); TORCH_CHECK(tensors2.size() > 0, "Tensor list must have at least one tensor."); TORCH_CHECK(tensors3.size() > 0, "Tensor list must have at least one tensor."); TORCH_CHECK(tensors1.size() == tensors2.size(), "Tensor lists must have the same number of tensors, got ", tensors1.size(), " and ", tensors2.size()); TORCH_CHECK(tensors1.size() == tensors3.size(), "Tensor lists must have the same number of tensors, got ", tensors1.size(), " and ", tensors3.size()); } void check_foreach_api_restrictions(TensorList tensors1, TensorList tensors2, TensorList tensors3, ArrayRef scalars) { check_foreach_api_restrictions(tensors1, tensors2, tensors3); TORCH_CHECK(tensors1.size() == scalars.size(), "Tensor list must have same number of elements as scalar list, got ", tensors1.size(), " and ", scalars.size()); } // To go via 'fast' path, several conditions must be satisfied // - All tensors in all lists must have the same dtype. // - All tensors must be on the same device // - All tensors must have strided layout // - All tensors must be non-overlapping and dense // - Resulting tensor must have the same dtype as the input one // Please, make sure to call check_foreach_api_restrictions before calling this method. // There is a set of preconditions that have to be satisfied. bool check_fast_path_restrictions( ArrayRef tensorLists, ArrayRef scalarList = {}, bool does_op_promote_integer_inputs_to_float = false) { const auto expected_dtype = tensorLists[0][0].dtype(); const auto expected_device = tensorLists[0][0].device(); auto is_tensor_okay = [&](const Tensor& tensor) { return tensor.dtype() == expected_dtype && tensor.device() == expected_device && tensor.layout() == at::kStrided && tensor.is_non_overlapping_and_dense(); }; for (const auto& tensorList : tensorLists) { for (const auto& tensor : tensorList) { if (!is_tensor_okay(tensor)) { return false; } } } // Check if corresponding tensors in tensor lists have the same sizes and strides. for (const auto& tensor_list : tensorLists) { for (const auto j : c10::irange(tensorLists[0].size())) { if (tensorLists[0][j].sizes() != tensor_list[j].sizes()) { return false; } if (tensorLists[0][j].strides() != tensor_list[j].strides()) { return false; } } } // This function has already checked that `tensorList[j][i]` for all j, i has the same dtype // using `is_tensor_okay` function above. // This means we only need to check if {tensorList[0][0], tensorList[0][1], tensorList[0][2], ...} // do type promotion with scalarLIst. for (const auto i : c10::irange(tensorLists[0].size())) { // For division, integer inputs will result in float. if (does_op_promote_integer_inputs_to_float) { if (at::isIntegralType(tensorLists[0][i].scalar_type(), /*includeBool*/ true)) { return false; } } if (scalarList.size() > 0) { const auto& scalar = scalarList.size() == 1 ? scalarList[0] : scalarList[i]; const auto& tensor = tensorLists[0][i]; // note(mkozuki): This check might be responsible for `_foreach_add(bool_tensors, bool_tensors)` // being pushed to slow path. if (tensor.scalar_type() != at::native::result_type(scalar, tensor)) { return false; } } } return true; } bool can_use_fast_route(ArrayRef tensorLists, ArrayRef scalarList = {}, bool does_op_promote_integer_inputs_to_float = false) { #ifdef __HIP_PLATFORM_HCC__ return false; #else return check_fast_path_restrictions(tensorLists, scalarList, does_op_promote_integer_inputs_to_float); #endif } bool can_use_fast_route(TensorList tensors1, TensorList tensors2, bool does_op_promote_integer_inputs_to_float = false) { #ifdef __HIP_PLATFORM_HCC__ return false; #else return can_use_fast_route({tensors1, tensors2}, {}, does_op_promote_integer_inputs_to_float); #endif } } }} // at::native