Skip to content

Commit dc5092b

Browse files
authored
Rename generic operator cpp/headers.
Differential Revision: D88079745 Pull Request resolved: pytorch#16022
1 parent 48cdc79 commit dc5092b

File tree

7 files changed

+130
-15
lines changed

7 files changed

+130
-15
lines changed

backends/cadence/generic/operators/dequantize_per_tensor.cpp renamed to backends/cadence/generic/operators/op_dequantize_per_tensor.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
* LICENSE file in the root directory of this source tree.
77
*/
88

9+
#include <executorch/backends/cadence/generic/operators/op_dequantize_per_tensor.h>
10+
911
#include <executorch/backends/cadence/generic/kernels/kernels.h>
1012
#include <executorch/runtime/kernel/kernel_includes.h>
1113

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the BSD-style license found in the
6+
* LICENSE file in the root directory of this source tree.
7+
*/
8+
9+
#pragma once
10+
11+
#include <executorch/runtime/core/exec_aten/exec_aten.h>
12+
#include <executorch/runtime/kernel/kernel_runtime_context.h>
13+
14+
namespace impl {
15+
namespace generic {
16+
namespace native {
17+
18+
::executorch::aten::Tensor& dequantize_per_tensor_out(
19+
::executorch::runtime::KernelRuntimeContext& context,
20+
const ::executorch::aten::Tensor& input,
21+
double scale,
22+
int64_t zero_point,
23+
int64_t quant_min,
24+
int64_t quant_max,
25+
::executorch::aten::ScalarType dtype,
26+
::executorch::aten::Tensor& out);
27+
28+
}
29+
} // namespace generic
30+
} // namespace impl

backends/cadence/generic/operators/im2row_out.cpp renamed to backends/cadence/generic/operators/op_im2row.cpp

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,18 @@
66
* LICENSE file in the root directory of this source tree.
77
*/
88

9-
#include <executorch/backends/cadence/generic/operators/operators.h>
9+
#include <executorch/backends/cadence/generic/operators/op_im2row.h>
1010

1111
#include <algorithm>
1212

13+
#include <executorch/runtime/core/exec_aten/util/scalar_type_util.h>
14+
15+
#ifndef DISABLE_ALWAYS_INLINE
16+
#define ALWAYS_INLINE __attribute__((always_inline))
17+
#else
18+
#define ALWAYS_INLINE inline
19+
#endif
20+
1321
namespace impl {
1422
namespace generic {
1523
namespace native {
@@ -20,7 +28,7 @@ using ::executorch::aten::Tensor;
2028
using ::executorch::runtime::KernelRuntimeContext;
2129

2230
template <typename T>
23-
__attribute__((always_inline)) void im2row_(
31+
ALWAYS_INLINE void im2row_(
2432
const T* __restrict__ data_im,
2533
const int32_t in_zero_point,
2634
/* input parameters*/
@@ -76,7 +84,7 @@ __attribute__((always_inline)) void im2row_(
7684
// 'channels' contiguous values. Otherwise we will fill the output
7785
// with 0's.
7886
if (h_im >= 0 && w_im >= 0 && h_im < height && w_im < width) {
79-
std::memcpy(slice_col, slice_im, channels * sizeof(T));
87+
memcpy(slice_col, slice_im, channels * sizeof(T));
8088
} else {
8189
std::fill_n(slice_col, channels, T(in_zero_point));
8290
}
@@ -115,8 +123,8 @@ __attribute__((always_inline)) void im2row_(
115123
}
116124
}
117125

118-
void im2row_out(
119-
__ET_UNUSED KernelRuntimeContext& ctx,
126+
Tensor& im2row_out(
127+
ET_UNUSED KernelRuntimeContext& ctx,
120128
const Tensor& input,
121129
IntArrayRef kernel_size,
122130
IntArrayRef dilation,
@@ -170,7 +178,7 @@ void im2row_out(
170178
in_zero_point.const_data_ptr<int32_t>(); \
171179
int32_t in_plane = in_c * in_h * in_w; \
172180
int32_t out_plane = kernel_h * kernel_w * in_c * out_h * out_w; \
173-
for (size_t n = 0; n < batch_size; ++n) { \
181+
for (int32_t n = 0; n < batch_size; ++n) { \
174182
im2row_<ctype>( \
175183
&in_data[n * in_plane], \
176184
per_tensor_quantized ? zero_point[0] : zero_point[n], \
@@ -205,10 +213,12 @@ void im2row_out(
205213
torch::executor::toString(dtype));
206214
}
207215
#undef typed_im2row
216+
217+
return out;
208218
}
209219

210-
void im2row_per_tensor_out(
211-
__ET_UNUSED KernelRuntimeContext& ctx,
220+
Tensor& im2row_per_tensor_out(
221+
ET_UNUSED KernelRuntimeContext& ctx,
212222
const Tensor& input,
213223
IntArrayRef kernel_size,
214224
IntArrayRef dilation,
@@ -291,6 +301,7 @@ void im2row_per_tensor_out(
291301
torch::executor::toString(dtype));
292302
}
293303
#undef typed_im2row_per_tensor
304+
return out;
294305
}
295306

296307
} // namespace native
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the BSD-style license found in the
6+
* LICENSE file in the root directory of this source tree.
7+
*/
8+
9+
#pragma once
10+
11+
#include <executorch/runtime/core/exec_aten/exec_aten.h>
12+
#include <executorch/runtime/kernel/kernel_runtime_context.h>
13+
14+
namespace impl {
15+
namespace generic {
16+
namespace native {
17+
18+
::executorch::aten::Tensor& im2row_out(
19+
__ET_UNUSED ::executorch::runtime::KernelRuntimeContext& ctx,
20+
const ::executorch::aten::Tensor& input,
21+
::executorch::aten::IntArrayRef kernel_size,
22+
::executorch::aten::IntArrayRef dilation,
23+
::executorch::aten::IntArrayRef padding,
24+
::executorch::aten::IntArrayRef stride,
25+
const ::executorch::aten::Tensor& in_zero_point,
26+
bool channel_last,
27+
::executorch::aten::Tensor& out);
28+
29+
::executorch::aten::Tensor& im2row_per_tensor_out(
30+
__ET_UNUSED ::executorch::runtime::KernelRuntimeContext& ctx,
31+
const ::executorch::aten::Tensor& input,
32+
::executorch::aten::IntArrayRef kernel_size,
33+
::executorch::aten::IntArrayRef dilation,
34+
::executorch::aten::IntArrayRef padding,
35+
::executorch::aten::IntArrayRef stride,
36+
int64_t in_zero_point,
37+
bool channel_last,
38+
::executorch::aten::Tensor& out);
39+
40+
} // namespace native
41+
} // namespace generic
42+
} // namespace impl

backends/cadence/generic/operators/quantize_per_tensor.cpp renamed to backends/cadence/generic/operators/op_quantize_per_tensor.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
* LICENSE file in the root directory of this source tree.
77
*/
88

9+
#include <executorch/backends/cadence/generic/operators/op_quantize_per_tensor.h>
10+
911
#include <executorch/backends/cadence/generic/kernels/kernels.h>
1012
#include <executorch/runtime/kernel/kernel_includes.h>
1113

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the BSD-style license found in the
6+
* LICENSE file in the root directory of this source tree.
7+
*/
8+
9+
#pragma once
10+
11+
#include <executorch/runtime/core/exec_aten/exec_aten.h>
12+
#include <executorch/runtime/kernel/kernel_runtime_context.h>
13+
14+
namespace impl {
15+
namespace generic {
16+
namespace native {
17+
18+
::executorch::aten::Tensor& quantize_per_tensor_out(
19+
::executorch::runtime::KernelRuntimeContext& context,
20+
const ::executorch::aten::Tensor& input,
21+
double scale,
22+
int64_t zero_point,
23+
int64_t quant_min,
24+
int64_t quant_max,
25+
::executorch::aten::ScalarType dtype,
26+
::executorch::aten::Tensor& out);
27+
}
28+
} // namespace generic
29+
} // namespace impl

backends/cadence/generic/operators/targets.bzl

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ def define_common_targets():
66

77
runtime.cxx_library(
88
name = "im2row_out",
9-
srcs = ["im2row_out.cpp"],
10-
exported_headers = ["operators.h"],
9+
srcs = ["op_im2row.cpp"],
10+
exported_headers = ["op_im2row.h"],
1111
platforms = CXX,
1212
deps = [
1313
"//executorch/runtime/kernel:kernel_includes",
@@ -32,11 +32,10 @@ def define_common_targets():
3232
],
3333
)
3434

35-
# Quantized operators that need cadence kernels for quantize/dequantize
3635
runtime.cxx_library(
3736
name = "dequantize_per_tensor",
38-
srcs = ["dequantize_per_tensor.cpp"],
39-
exported_headers = ["quantized_ops.h"],
37+
srcs = ["op_dequantize_per_tensor.cpp"],
38+
exported_headers = ["op_dequantize_per_tensor.h"],
4039
platforms = CXX,
4140
deps = [
4241
"//executorch/runtime/kernel:kernel_includes",
@@ -50,8 +49,8 @@ def define_common_targets():
5049

5150
runtime.cxx_library(
5251
name = "quantize_per_tensor",
53-
srcs = ["quantize_per_tensor.cpp"],
54-
exported_headers = ["quantized_ops.h"],
52+
srcs = ["op_quantize_per_tensor.cpp"],
53+
exported_headers = ["op_quantize_per_tensor.h"],
5554
platforms = CXX,
5655
deps = [
5756
"//executorch/runtime/kernel:kernel_includes",

0 commit comments

Comments
 (0)