Skip to content

Commit 77f2883

Browse files
cyyeverpytorchmergebot
authored andcommitted
[Reland2] fix missing-prototypes warnings in torch_cpu (Part 4) (pytorch#102228)
This PR relands the changes introduced in PR pytorch#100849. The old PR turnd nnc_* functions into static. We now add declarations for them and hope that inter builds will pass. Pull Request resolved: pytorch#102228 Approved by: https://github.com/albanD
1 parent 86c7652 commit 77f2883

File tree

138 files changed

+577
-773
lines changed

Some content is hidden

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

138 files changed

+577
-773
lines changed

BUILD.bazel

+1
Original file line numberDiff line numberDiff line change
@@ -1598,6 +1598,7 @@ TORCH_COPTS = COMMON_COPTS + [
15981598
"-fvisibility-inlines-hidden",
15991599
"-fno-math-errno ",
16001600
"-fno-trapping-math",
1601+
"-Wno-error=unused-function",
16011602
]
16021603

16031604
torch_sources = {

aten/src/ATen/core/ivalue.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -763,7 +763,7 @@ IValueComparator getGreaterThanComparator(const IValue& v) {
763763
};
764764
}
765765

766-
static std::ostream& operator<<(std::ostream& out, const ivalue::EnumHolder& v) {
766+
std::ostream& operator<<(std::ostream& out, const ivalue::EnumHolder& v) {
767767
out << v.qualifiedClassName() << "." << v.name();
768768
return out;
769769
}

aten/src/ATen/core/ivalue_inl.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -1622,7 +1622,7 @@ struct ivalue::EnumHolder : c10::intrusive_ptr_target {
16221622

16231623
TORCH_API friend std::ostream& operator<<(
16241624
std::ostream& out,
1625-
const EnumHolder& v);
1625+
const ivalue::EnumHolder& v);
16261626

16271627
TORCH_API const std::string qualifiedClassName() const;
16281628

aten/src/ATen/functorch/BatchRulesReduceOps.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ static std::tuple<Tensor,optional<int64_t>> searchsorted_batch_rule(
405405
TORCH_INTERNAL_ASSERT(false);
406406
}
407407

408-
Tensor bucketize_decomp_Tensor(
408+
static Tensor bucketize_decomp_Tensor(
409409
const Tensor& self,
410410
const Tensor& boundaries,
411411
bool out_int32,
@@ -415,7 +415,7 @@ Tensor bucketize_decomp_Tensor(
415415
return at::searchsorted(boundaries, self, out_int32, right, nullopt, nullopt);
416416
}
417417

418-
Tensor bucketize_decomp_Scalar(
418+
static Tensor bucketize_decomp_Scalar(
419419
const Scalar& self,
420420
const Tensor& boundaries,
421421
bool out_int32,

aten/src/ATen/native/Activation.cpp

+2-3
Original file line numberDiff line numberDiff line change
@@ -374,8 +374,8 @@ TORCH_IMPL_FUNC(softshrink_backward_out) (
374374
shrink_backward_stub(device_type(), *this, lambd);
375375
}
376376

377-
static bool use_mkldnn(const Tensor& input) {
378377
#if AT_MKLDNN_ENABLED()
378+
static bool use_mkldnn(const Tensor& input) {
379379
if (!at::globalContext().userEnabledMkldnn()) {
380380
return false;
381381
}
@@ -386,9 +386,8 @@ static bool use_mkldnn(const Tensor& input) {
386386
(input.device().is_cpu() &&
387387
(((input.scalar_type() == kBFloat16) && mkldnn_bf16_device_check()) ||
388388
(input.scalar_type() == kFloat))); // input is dense layout and bfloat16/float32
389-
#endif
390-
return false;
391389
}
390+
#endif
392391

393392
TORCH_IMPL_FUNC(gelu_out_cpu) (
394393
const Tensor& self, c10::string_view approximate, const Tensor& result

aten/src/ATen/native/BinaryOps.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -809,7 +809,7 @@ Tensor& arctan2_out(const Tensor& self, const Tensor& other, Tensor& result) {
809809
return at::atan2_out(result, self, other);
810810
}
811811

812-
Tensor& add_relu_impl(
812+
static Tensor& add_relu_impl(
813813
Tensor& result, const Tensor& self, const Tensor& other, const Scalar& alpha) {
814814
auto iter = TensorIterator::binary_op(result, self, other);
815815
Scalar min_val;
@@ -1003,7 +1003,7 @@ Tensor& mul__scalar_sparse_csr(Tensor& self, const Scalar& other) {
10031003
return self;
10041004
}
10051005

1006-
Device correct_out_device(const Tensor& self, const Tensor& other) {
1006+
static Device correct_out_device(const Tensor& self, const Tensor& other) {
10071007
if (self.device() == at::kCPU){
10081008
return other.device();
10091009
} else {
@@ -1049,7 +1049,7 @@ Tensor div_zerotensor(const Tensor& self, const Tensor& other) {
10491049
}
10501050
}
10511051

1052-
Tensor maybe_add_maybe_sub(const Tensor& self, const Tensor& other, const Scalar& alpha) {
1052+
static Tensor maybe_add_maybe_sub(const Tensor& self, const Tensor& other, const Scalar& alpha) {
10531053
auto out_device = correct_out_device(self, other);
10541054
// hack to use the TensorIterator to get the correct broadcasting and type promotion logic
10551055
auto device_ = Device(DeviceType::Meta);

aten/src/ATen/native/Convolution.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -771,6 +771,7 @@ static void check_input_same_type_as_parameters(
771771
check_input_same_type_as_parameters(input, weight, /*bias=*/ Tensor());
772772
}
773773

774+
#if AT_MKLDNN_ENABLED()
774775
static void check_input_same_type_as_parameters(
775776
const Tensor& input,
776777
const Tensor& weight,
@@ -789,6 +790,7 @@ static void check_input_same_type_as_parameters(
789790
check_input_same_type_as_parameters(input, weight, bias);
790791
}
791792
}
793+
#endif
792794

793795
static auto view4d(const at::Tensor& tensor) -> at::Tensor {
794796
TORCH_CHECK(tensor.ndimension() == 3,

aten/src/ATen/native/Copy.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include <ATen/NativeFunctions.h>
2222
#else
2323
#include <ATen/ops/_copy_from.h>
24+
#include <ATen/ops/_propagate_xla_data.h>
2425
#include <ATen/ops/copy_native.h>
2526
#include <ATen/ops/empty.h>
2627
#include <ATen/ops/expand_copy.h>

aten/src/ATen/native/LegacyBatching.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@
33
#include <ATen/WrapDimUtils.h>
44
#include <ATen/LegacyVmapTransforms.h>
55

6+
#ifdef AT_PER_OPERATOR_HEADERS
7+
#include <ATen/ops/_add_batch_dim_native.h>
8+
#include <ATen/ops/_remove_batch_dim_native.h>
9+
#endif
10+
611
namespace at { namespace native {
712

813
// Adds a batch dimension to the tensor `self` out-of-place

aten/src/ATen/native/LinearAlgebra.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1893,7 +1893,7 @@ The behavior depends on the dimensionality of the Tensors as follows:
18931893
- Otherwise, we return bmm, after broadcasting and folding the batched dimensions if
18941894
there's more than one
18951895
*/
1896-
Tensor _matmul_impl(
1896+
static Tensor _matmul_impl(
18971897
Tensor& out,
18981898
const Tensor& tensor1,
18991899
const Tensor& tensor2) {

aten/src/ATen/native/PackedSequence.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
namespace at { namespace native {
2222

23-
void checkLongTensor(const Tensor& tensor) {
23+
static void checkLongTensor(const Tensor& tensor) {
2424
TORCH_CHECK(tensor.dim() == 1 && tensor.device().type() == at::kCPU && tensor.scalar_type() == at::kLong,
2525
"'lengths' argument should be a 1D CPU int64 tensor, but got ",
2626
tensor.dim(), "D ", tensor.device().str(), " ", tensor.scalar_type(), " tensor");

aten/src/ATen/native/RNN.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1809,7 +1809,7 @@ std::tuple<Tensor, Tensor, Tensor> quantized_lstm_data(
18091809
std::move(std::get<2>(results)));
18101810
}
18111811

1812-
std::tuple<Tensor, Tensor, Tensor> quantized_lstm_data_legacy(
1812+
static std::tuple<Tensor, Tensor, Tensor> quantized_lstm_data_legacy(
18131813
const Tensor& data,
18141814
const Tensor& batch_sizes,
18151815
c10::List<at::Tensor> hx_,

aten/src/ATen/native/Resize.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <ATen/ops/resize_as_native.h>
1212
#include <ATen/ops/resize_native.h>
1313
#include <ATen/ops/resize.h>
14+
#include <ATen/ops/_resize_output.h>
1415
#endif
1516

1617
namespace at { namespace native {

aten/src/ATen/native/TensorAdvancedIndexing.cpp

+4-8
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ static void build_index_op(
400400
iter.build(config);
401401
}
402402

403-
void check_indices_on_cpu_or_selfdevice(
403+
static void check_indices_on_cpu_or_selfdevice(
404404
const Tensor& self,
405405
const at::MaterializedIOptTensorListRef& indices) {
406406
auto dev = self.device();
@@ -965,7 +965,7 @@ TORCH_IMPL_FUNC(index_add_cpu_out)
965965
}
966966
}
967967

968-
void index_reduce_func_impl(
968+
static void index_reduce_func_impl(
969969
const Tensor& self,
970970
int64_t dim,
971971
const Tensor& index,
@@ -1149,7 +1149,7 @@ static void check_indexarray_range(
11491149
}
11501150
}
11511151

1152-
Tensor & index_select_out_cpu_dim1_(
1152+
static Tensor & index_select_out_cpu_dim1_(
11531153
Tensor & result_contig, const Tensor & self, const Tensor & index_contig) {
11541154

11551155
auto self_contig = self.contiguous();
@@ -1379,10 +1379,6 @@ Tensor index_select_quantized_cpu_(const Tensor & self, int64_t dim, const Tenso
13791379
return at::native::index_select_out_cpu_(self, dim, index, result);
13801380
}
13811381

1382-
Tensor index_select_backward(const Tensor& grad, at::IntArrayRef self_sizes, int64_t dim, const Tensor& index) {
1383-
return at::native::index_select_backward_symint(grad, c10::fromIntArrayRefSlow(self_sizes), dim, index);
1384-
}
1385-
13861382
Tensor index_select_backward_symint(const Tensor& grad, c10::SymIntArrayRef self_sizes, int64_t dim, const Tensor& index) {
13871383
// for composite compliance, use out-of-place variant of
13881384
// `index_add` if index tensor is a Tensor Subclass.
@@ -1537,7 +1533,7 @@ static void scatter_reduce_exclude_self_helper(
15371533
});
15381534
}
15391535

1540-
void _scatter_via_index_put(
1536+
static void _scatter_via_index_put(
15411537
const Tensor& self,
15421538
int64_t dim,
15431539
const Tensor& index,

aten/src/ATen/native/TensorConversions.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -1009,7 +1009,7 @@ Tensor dense_to_sparse_bsc(const Tensor& self, IntArrayRef blocksize, c10::optio
10091009
return dense_to_sparse_compressed<Layout::SparseBsc>(self, blocksize, dense_dim_opt);
10101010
}
10111011

1012-
void _check_blocksize_matches(
1012+
static void _check_blocksize_matches(
10131013
const Tensor& self,
10141014
c10::optional<IntArrayRef> blocksize_opt,
10151015
const std::string& name) {
@@ -1023,7 +1023,7 @@ void _check_blocksize_matches(
10231023
}
10241024
}
10251025

1026-
Tensor sparse_compressed_clone(
1026+
static Tensor sparse_compressed_clone(
10271027
const Tensor& self,
10281028
c10::optional<IntArrayRef> blocksize,
10291029
const std::string& name) {
@@ -1046,7 +1046,7 @@ Tensor sparse_compressed_clone(
10461046
values.device());
10471047
}
10481048

1049-
Tensor sparse_compressed_to_flipped(
1049+
static Tensor sparse_compressed_to_flipped(
10501050
const Tensor& self,
10511051
c10::optional<IntArrayRef> blocksize,
10521052
const std::string& name) {

aten/src/ATen/native/Unfold3d.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#define TORCH_ASSERT_ONLY_METHOD_OPERATORS
22
#include <ATen/core/Tensor.h>
3+
#include <ATen/native/Unfold3d.h>
34
#include <ATen/Config.h>
45
#include <ATen/Dispatch.h>
56
#include <ATen/Parallel.h>

aten/src/ATen/native/WeightNorm.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
#else
1111
#include <ATen/ops/_weight_norm_differentiable_backward_native.h>
1212
#include <ATen/ops/_weight_norm_interface.h>
13+
#include <ATen/ops/_weight_norm_interface_backward_native.h>
14+
#include <ATen/ops/_weight_norm_interface_native.h>
1315
#include <ATen/ops/_weight_norm_native.h>
1416
#include <ATen/ops/empty_strided.h>
1517
#include <ATen/ops/norm_except_dim.h>

aten/src/ATen/native/cpu/PowKernel.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ namespace at::native {
1313

1414
inline namespace CPU_CAPABILITY {
1515

16-
void pow_tensor_tensor_kernel(TensorIteratorBase& iter) {
16+
static void pow_tensor_tensor_kernel(TensorIteratorBase& iter) {
1717
const auto dtype = iter.common_dtype();
1818
if (isFloatingType(dtype) || isComplexType(dtype)) {
1919
AT_DISPATCH_FLOATING_AND_COMPLEX_TYPES_AND2(kHalf, kBFloat16, dtype, "pow", [&]() {
@@ -90,7 +90,7 @@ void reciprocal_kernel(TensorIteratorBase& iter);
9090
void rsqrt_kernel(TensorIteratorBase& iter);
9191
void sqrt_kernel(TensorIteratorBase& iter);
9292

93-
void pow_tensor_scalar_kernel(
93+
static void pow_tensor_scalar_kernel(
9494
TensorIteratorBase& iter,
9595
const Scalar& exp_scalar) {
9696
// prevent multiple calls to iter.common_dtype()

aten/src/ATen/native/mkl/SparseBlasImpl.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ namespace mkl {
3232

3333
namespace {
3434

35+
#if AT_USE_MKL_SPARSE()
3536
c10::MaybeOwned<Tensor> prepare_dense_matrix_for_mkl(
3637
const Tensor& tensor) {
3738
if (tensor.is_non_overlapping_and_dense() ||
@@ -110,7 +111,6 @@ void inline col_indices_and_values_resize_(const Tensor& input, int64_t nnz) {
110111
/*
111112
Resizes `input` tensor and fills it with the data from MKL.
112113
*/
113-
#if AT_USE_MKL_SPARSE()
114114
template <typename scalar_t>
115115
void mkl_result_copy_(const Tensor& input, sparse_matrix_t mkl_desc) {
116116
sparse_index_base_t indexing = SPARSE_INDEX_BASE_ZERO;

aten/src/ATen/native/nested/NestedTensorFactories.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
namespace at {
77
namespace native {
88

9-
TensorOptions verify_empty_parameters(
9+
static TensorOptions verify_empty_parameters(
1010
const at::Tensor& self,
1111
c10::optional<ScalarType> dtype,
1212
c10::optional<Layout> layout,

aten/src/ATen/native/nested/NestedTensorMatmul.cpp

-58
Original file line numberDiff line numberDiff line change
@@ -79,64 +79,6 @@ Tensor bmm_nested(const Tensor& self, const Tensor& mat2) {
7979
return output;
8080
}
8181

82-
// utilities support `matmul_nested`
83-
namespace {
84-
// Args:
85-
// self_sizes: the sizes of `self` in `matmul_nested`
86-
// mat2_sizes: the sizes of `mat2` in `matmul_nested`
87-
// buffer_op: the options for new buffer
88-
// sizemat_op: the options for new size matrix
89-
// Returns:
90-
// the batch size of each input underlying tensor, i.e. the product of batch-dimension sizes
91-
// the empty output nested tensor
92-
inline std::tuple<std::vector<int64_t>, Tensor>
93-
matmul_nested_helper(
94-
const std::vector<IntArrayRef>& self_sizes,
95-
const std::vector<IntArrayRef>& mat2_sizes,
96-
const c10::TensorOptions& buffer_op,
97-
const c10::TensorOptions& sizemat_op) {
98-
int64_t ntensors = self_sizes.size(),
99-
ndims = self_sizes[0].size();
100-
std::vector<int64_t> batch_sizes(ntensors, 1);
101-
Tensor sizemat = at::empty({ntensors, ndims}, sizemat_op);
102-
int64_t* sizemat_ptr = sizemat.mutable_data_ptr<int64_t>();
103-
int64_t numel = 0;
104-
for (int64_t i = 0; i < ntensors; i++) {
105-
const IntArrayRef& self_size = self_sizes[i],
106-
& mat2_size = mat2_sizes[i];
107-
int64_t& batch_size = batch_sizes[i];
108-
// batch dimensions
109-
for (int64_t j = 0; j < ndims - 2; j++) {
110-
const int64_t& self_sizej = self_size[j],
111-
& mat2_sizej = mat2_size[j];
112-
TORCH_CHECK(
113-
self_sizej == mat2_sizej,
114-
"matmul: For nested tensors, no broadcasting is currently performed: ",
115-
i, "-th nested matrices in batch at dimension ", j + 1,
116-
" have mismatching sizes ", self_sizej, " and ", mat2_sizej);
117-
sizemat_ptr[j] = self_sizej;
118-
batch_size *= sizemat_ptr[j];
119-
}
120-
// matrix multiplication dimensions
121-
const int64_t& self_size0 = self_size[ndims - 2], & self_size1 = self_size[ndims - 1],
122-
& mat2_size0 = mat2_size[ndims - 2], & mat2_size1 = mat2_size[ndims - 1];
123-
TORCH_CHECK(
124-
self_size1 == mat2_size0,
125-
"matmul: ",
126-
i, "-th nested matrices in batch cannot be multiplied (",
127-
self_size0, "x", self_size1, " and ",
128-
mat2_size0, "x", mat2_size1, ")");
129-
sizemat_ptr[ndims - 2] = self_size0;
130-
sizemat_ptr[ndims - 1] = mat2_size1;
131-
sizemat_ptr += ndims;
132-
numel += batch_size * self_size0 * mat2_size1;
133-
}
134-
Tensor buffer = at::empty(numel, buffer_op);
135-
Tensor output = wrap_buffer(buffer, sizemat);
136-
return std::make_tuple(batch_sizes, output);
137-
}
138-
}
139-
14082
Tensor matmul_with_bmm_nested(const Tensor& self, const Tensor& mat2) {
14183
// Tensor self = self_.contiguous();
14284
// Tensor mat2 = mat2_.contiguous();

aten/src/ATen/native/quantized/FakeQuantPerChannelAffine.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ Tensor fake_quantize_per_channel_affine_cachemask_backward(
128128
return dY * mask;
129129
}
130130

131-
Tensor _get_rounded_zero_point(
131+
static Tensor _get_rounded_zero_point(
132132
const Tensor& zero_point,
133133
int64_t quant_min,
134134
int64_t quant_max) {

aten/src/ATen/native/quantized/FakeQuantPerTensorAffine.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ Tensor fake_quantize_per_tensor_affine_cachemask_backward(
133133
return dY * mask;
134134
}
135135

136-
int64_t _get_zero_point_from_tensor(
136+
static int64_t _get_zero_point_from_tensor(
137137
const Tensor& zero_point,
138138
int64_t quant_min,
139139
int64_t quant_max,

aten/src/ATen/native/quantized/QTensor.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ std::tuple<double, int64_t> _choose_qparams_per_tensor(
285285
return std::make_tuple(q_params.scale, q_params.zero_point);
286286
}
287287

288-
float calculate_quant_loss(
288+
static float calculate_quant_loss(
289289
const float* input,
290290
int numel,
291291
float xmin,

0 commit comments

Comments
 (0)