Skip to content

Commit c18136e

Browse files
committed
Update on "Migrate CPU unary ops to c10::complex"
Differential Revision: [D21554156](https://our.internmc.facebook.com/intern/diff/D21554156) [ghstack-poisoned]
2 parents b457ae6 + c40b101 commit c18136e

102 files changed

Lines changed: 2026 additions & 1158 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.jenkins/caffe2/build.sh

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -165,11 +165,13 @@ if [[ $BUILD_ENVIRONMENT == *rocm* ]]; then
165165
build_args+=("USE_OPENCV=ON")
166166
# This is needed to read datasets from https://download.caffe2.ai/databases/resnet_trainer.zip
167167
build_args+=("USE_LMDB=ON")
168-
# When hcc runs out of memory, it silently exits without stopping
169-
# the build process, leaving undefined symbols in the shared lib
170-
# which will cause undefined symbol errors when later running
171-
# tests. Setting MAX_JOBS to smaller number to make CI less flaky.
172-
export MAX_JOBS=4
168+
# hcc used to run out of memory, silently exiting without stopping
169+
# the build process, leaving undefined symbols in the shared lib,
170+
# causing undefined symbol errors when later running tests.
171+
# We used to set MAX_JOBS to 4 to avoid, but this is no longer an issue.
172+
if [ -z "$MAX_JOBS" ]; then
173+
export MAX_JOBS=$(($(nproc) - 1))
174+
fi
173175

174176
########## HIPIFY Caffe2 operators
175177
${PYTHON} "${ROOT_DIR}/tools/amd_build/build_amd.py"

.jenkins/pytorch/build.sh

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -113,11 +113,13 @@ if [[ "${BUILD_ENVIRONMENT}" == *-android* ]]; then
113113
fi
114114

115115
if [[ "$BUILD_ENVIRONMENT" == *rocm* ]]; then
116-
# When hcc runs out of memory, it silently exits without stopping
117-
# the build process, leaving undefined symbols in the shared lib
118-
# which will cause undefined symbol errors when later running
119-
# tests. Setting MAX_JOBS to smaller number to make CI less flaky.
120-
export MAX_JOBS=4
116+
# hcc used to run out of memory, silently exiting without stopping
117+
# the build process, leaving undefined symbols in the shared lib,
118+
# causing undefined symbol errors when later running tests.
119+
# We used to set MAX_JOBS to 4 to avoid, but this is no longer an issue.
120+
if [ -z "$MAX_JOBS" ]; then
121+
export MAX_JOBS=$(($(nproc) - 1))
122+
fi
121123

122124
# ROCm CI is using Caffe2 docker images, which needs these wrapper
123125
# scripts to correctly use sccache.

BUILD.bazel

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
load("@rules_proto//proto:defs.bzl", "proto_library")
22
load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library", "cc_proto_library", "cc_test")
33
load("//third_party:substitution.bzl", "template_rule")
4-
load("//:tools/build_variables.bzl", "torch_cpp_srcs", "libtorch_core_sources", "libtorch_distributed_sources", "libtorch_extra_sources")
4+
load("//:tools/build_variables.bzl", "torch_cpp_srcs", "libtorch_core_sources", "libtorch_distributed_sources", "libtorch_extra_sources", "jit_core_sources")
55
load("//tools/rules:cu.bzl", "cu_library")
66
load("//tools/config:defs.bzl", "if_cuda")
77
load("//:aten.bzl", "intern_build_aten_ops")
@@ -1979,13 +1979,7 @@ cc_library(
19791979
"torch/csrc/cuda/python_nccl.cpp",
19801980
"torch/csrc/cuda/nccl.cpp",
19811981
],
1982-
)) + libtorch_core_sources + libtorch_distributed_sources + torch_cpp_srcs + libtorch_extra_sources + [
1983-
"torch/csrc/jit/frontend/error_report.cpp",
1984-
"torch/csrc/jit/frontend/lexer.cpp",
1985-
"torch/csrc/jit/frontend/function_schema_parser.cpp",
1986-
"torch/csrc/jit/frontend/strtod.cpp",
1987-
"torch/csrc/jit/frontend/source_range.cpp",
1988-
"torch/csrc/jit/frontend/schema_type_parser.cpp",
1982+
)) + libtorch_core_sources + libtorch_distributed_sources + torch_cpp_srcs + libtorch_extra_sources + jit_core_sources + [
19891983
":generated_code",
19901984
],
19911985
copts = TORCH_COPTS + if_cuda(["-DUSE_CUDA=1"]),

aten/src/ATen/CMakeLists.txt

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,13 @@ if(USE_ROCM)
3434
endif()
3535

3636
# NB: If you edit these globs, you'll have to update setup.py package_data as well
37+
file(GLOB_RECURSE ATen_CORE_HEADERS "core/*.h")
38+
file(GLOB_RECURSE ATen_CORE_SRCS "core/*.cpp")
39+
file(GLOB_RECURSE ATen_CORE_TEST_SRCS "core/*_test.cpp")
40+
EXCLUDE(ATen_CORE_SRCS "${ATen_CORE_SRCS}" ${ATen_CORE_TEST_SRCS})
41+
3742
file(GLOB base_h "*.h" "detail/*.h" "cpu/*.h" "cpu/vec256/*.h" "quantized/*.h")
3843
file(GLOB base_cpp "*.cpp" "detail/*.cpp" "cpu/*.cpp")
39-
add_subdirectory(core)
4044
file(GLOB cuda_h "cuda/*.h" "cuda/detail/*.h" "cuda/*.cuh" "cuda/detail/*.cuh")
4145
file(GLOB cuda_cpp "cuda/*.cpp" "cuda/detail/*.cpp")
4246
file(GLOB cuda_nvrtc_stub_h "cuda/nvrtc_stub/*.h")
@@ -89,6 +93,26 @@ file(GLOB native_quantized_hip_cpp "native/quantized/hip/*.cpp")
8993
# XNNPACK
9094
file(GLOB native_xnnpack "native/xnnpack/*.cpp")
9195

96+
# Add files needed from jit folders
97+
list(APPEND ATen_CORE_HEADERS
98+
${Caffe2_SOURCE_DIR}/torch/csrc/jit/frontend/source_range.h
99+
${Caffe2_SOURCE_DIR}/torch/csrc/jit/frontend/function_schema_parser.h
100+
${Caffe2_SOURCE_DIR}/torch/csrc/jit/frontend/lexer.h
101+
${Caffe2_SOURCE_DIR}/torch/csrc/jit/frontend/strtod.h
102+
${Caffe2_SOURCE_DIR}/torch/csrc/jit/frontend/parse_string_literal.h
103+
${Caffe2_SOURCE_DIR}/torch/csrc/jit/frontend/schema_type_parser.h
104+
${Caffe2_SOURCE_DIR}/torch/csrc/jit/frontend/error_report.h
105+
${Caffe2_SOURCE_DIR}/torch/csrc/jit/frontend/tree.h
106+
)
107+
list(APPEND ATen_CORE_SRCS
108+
${Caffe2_SOURCE_DIR}/torch/csrc/jit/frontend/error_report.cpp
109+
${Caffe2_SOURCE_DIR}/torch/csrc/jit/frontend/function_schema_parser.cpp
110+
${Caffe2_SOURCE_DIR}/torch/csrc/jit/frontend/lexer.cpp
111+
${Caffe2_SOURCE_DIR}/torch/csrc/jit/frontend/strtod.cpp
112+
${Caffe2_SOURCE_DIR}/torch/csrc/jit/frontend/schema_type_parser.cpp
113+
${Caffe2_SOURCE_DIR}/torch/csrc/jit/frontend/source_range.cpp
114+
)
115+
92116
add_subdirectory(quantized)
93117
set(all_cpu_cpp ${base_cpp} ${ATen_CORE_SRCS} ${native_cpp} ${native_sparse_cpp} ${native_quantized_cpp} ${native_mkl_cpp} ${native_mkldnn_cpp} ${native_xnnpack} ${generated_cpp} ${core_generated_cpp} ${ATen_CPU_SRCS} ${ATen_QUANTIZED_SRCS} ${cpu_kernel_cpp})
94118
if(AT_MKL_ENABLED)

aten/src/ATen/Declarations.cwrap

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -334,34 +334,6 @@
334334
- bool largest
335335
- bool sorted
336336
]]
337-
[[
338-
name: _th_exp
339-
cname: exp
340-
types:
341-
- floating_point
342-
backends:
343-
- CUDA
344-
variants: function
345-
return: argument 0
346-
arguments:
347-
- arg: THTensor* result
348-
output: True
349-
- THTensor* self
350-
]]
351-
[[
352-
name: _th_erfc
353-
cname: erfc
354-
types:
355-
- floating_point
356-
backends:
357-
- CUDA
358-
variants: function
359-
return: argument 0
360-
arguments:
361-
- arg: THTensor* result
362-
output: True
363-
- THTensor* self
364-
]]
365337
[[
366338
name: _th_var
367339
types:

aten/src/ATen/core/CMakeLists.txt

Lines changed: 0 additions & 36 deletions
This file was deleted.

aten/src/ATen/core/ivalue_inl.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -310,12 +310,11 @@ struct C10_EXPORT ivalue::Future final : c10::intrusive_ptr_target {
310310
return value_;
311311
}
312312

313+
// This accessor should only be used if we know that the future is
314+
// completed() with no error.
313315
const IValue& constValue() {
314316
std::unique_lock<std::mutex> lock(mutex_);
315317
AT_ASSERT(completed());
316-
if (error_) {
317-
throw *error_;
318-
}
319318
return value_;
320319
}
321320

aten/src/ATen/native/TensorCompare.cpp

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -115,13 +115,9 @@ Tensor isfinite(const Tensor& self) {
115115

116116
bool is_nonzero(const Tensor& self) {
117117
auto n = self.numel();
118-
AT_ASSERT(n >= 0);
119-
if (n == 0) {
120-
AT_ERROR("bool value of Tensor with no values is ambiguous");
121-
}
122-
if (n > 1) {
123-
AT_ERROR("bool value of Tensor with more than one value is ambiguous");
124-
}
118+
TORCH_CHECK(n != 0, "Boolean value of Tensor with no values is ambiguous");
119+
TORCH_CHECK(n < 2, "Boolean value of Tensor with more than one value is ambiguous");
120+
125121
Scalar localScalar = self.item();
126122
if (localScalar.isFloatingPoint()) {
127123
return localScalar.to<double>() != 0;
@@ -132,18 +128,17 @@ bool is_nonzero(const Tensor& self) {
132128
} else if (localScalar.isBoolean()) {
133129
return localScalar.to<bool>();
134130
}
135-
AT_ERROR("expected non-Tensor backend scalar");
131+
TORCH_INTERNAL_ASSERT(false, "Expected non-Tensor backend scalar");
136132
}
137133

138134
Tensor where(const Tensor& condition, const Tensor& self, const Tensor& other) {
139135
TORCH_CHECK(condition.device() == self.device() && self.device() == other.device(),
140-
"expected condition, x and y to be on the same device, but condition is on ",
136+
"Expected condition, x and y to be on the same device, but condition is on ",
141137
condition.device(), " and x and y are on ", self.device(), " and ", other.device(),
142138
" respectively");
143-
if (condition.scalar_type() != ScalarType::Byte && condition.scalar_type() != ScalarType::Bool) {
144-
AT_ERROR("Expected condition to have ScalarType Byte, but got ScalarType ",
145-
toString(condition.scalar_type()));
146-
}
139+
TORCH_CHECK(condition.scalar_type() == ScalarType::Byte || condition.scalar_type() == ScalarType::Bool,
140+
"Expected condition to have ScalarType Byte, but got ScalarType ",
141+
toString(condition.scalar_type()));
147142
Tensor b_condition, b_self, b_other;
148143
std::tie(b_condition, b_self, b_other) = expand_outplace(condition, self, other, "where");
149144
return at::_s_where(b_condition, b_self, b_other);

aten/src/ATen/native/TensorIterator.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <ATen/ExpandUtils.h>
55
#include <ATen/Parallel.h>
66
#include <ATen/native/TypeProperties.h>
7+
#include <ATen/MemoryOverlap.h>
78

89
namespace at {
910

aten/src/ATen/native/TensorIterator.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
#include <c10/util/TypeCast.h>
77
#include <ATen/core/Range.h>
88
#include <bitset>
9-
#include <c10/util/Optional.h>
10-
#include <ATen/MemoryOverlap.h>
119
#include <ATen/NamedTensorUtils.h>
1210
#include <ATen/Parallel.h>
1311

0 commit comments

Comments
 (0)