Skip to content

Commit da607a8

Browse files
zonglinpengfacebook-github-bot
authored andcommitted
migrate jarvis quant-per-tensor hifi ops to oss (pytorch#6293)
Summary: - only migrated quant-per-tensor in this diff. will do the rest of 3 in the stack - solved the --start-lib --end-lib option not recognized in here - need to import libs from //executorch. Nothing do with the cxx wrapper in buck - aligned namespace to cadence::impl:HIFI::native - kernel to be removed after all ops are migrated Reviewed By: skrtskrtfb Differential Revision: D64194227
1 parent 3b8b28b commit da607a8

File tree

7 files changed

+21
-4
lines changed

7 files changed

+21
-4
lines changed

backends/cadence/hifi/kernels/kernels.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <xa_nnlib_common.h>
1111
#include <xa_nnlib_common_macros.h>
1212

13+
namespace cadence {
1314
namespace impl {
1415
namespace HiFi {
1516
namespace kernels {
@@ -231,3 +232,4 @@ typed_requantize_vec(uint8_t, int8_t);
231232
}; // namespace kernels
232233
}; // namespace HiFi
233234
}; // namespace impl
235+
}; // namespace cadence

backends/cadence/hifi/kernels/kernels.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <stddef.h>
1313
#include <xa_type_def.h>
1414

15+
namespace cadence {
1516
namespace impl {
1617
namespace HiFi {
1718
namespace kernels {
@@ -63,3 +64,4 @@ void dequantize(
6364
}; // namespace kernels
6465
}; // namespace HiFi
6566
}; // namespace impl
67+
}; // namespace cadence

backends/cadence/hifi/operators/dequantize_per_tensor.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <executorch/runtime/kernel/kernel_includes.h>
1111
#include <xa_nnlib_kernels_api.h>
1212

13+
namespace cadence {
1314
namespace impl {
1415
namespace HiFi {
1516
namespace native {
@@ -50,3 +51,4 @@ void dequantize_per_tensor_out(
5051
}; // namespace native
5152
}; // namespace HiFi
5253
}; // namespace impl
54+
}; // namespace cadence

backends/cadence/hifi/operators/quantize_per_tensor.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <executorch/runtime/kernel/kernel_includes.h>
1111
#include <xa_nnlib_kernels_api.h>
1212

13+
namespace cadence {
1314
namespace impl {
1415
namespace HiFi {
1516
namespace native {
@@ -21,16 +22,16 @@ using executorch::runtime::KernelRuntimeContext;
2122
// Quantize the input tensor (PT2 version). Note that quant_<min,max> are not
2223
// used in any computation.
2324
void quantize_per_tensor_out(
24-
KernelRuntimeContext& context,
25+
KernelRuntimeContext& ctx,
2526
const Tensor& input,
2627
double scale,
2728
int64_t zero_point,
28-
int64_t quant_min,
29-
int64_t quant_max,
29+
__ET_UNUSED int64_t quant_min,
30+
__ET_UNUSED int64_t quant_max,
3031
ScalarType dtype,
3132
Tensor& out) {
3233
const float* input_data = input.const_data_ptr<float>();
33-
size_t numel = out.numel();
34+
const size_t numel = out.numel();
3435

3536
if (out.scalar_type() == ScalarType::Byte) {
3637
uint8_t* out_data = out.mutable_data_ptr<uint8_t>();
@@ -40,6 +41,10 @@ void quantize_per_tensor_out(
4041
int8_t* out_data = out.mutable_data_ptr<int8_t>();
4142
xa_nn_elm_quantize_f32_asym8s(
4243
out_data, input_data, scale, zero_point, numel);
44+
} else if (out.scalar_type() == ScalarType::Short) {
45+
int16_t* out_data = out.mutable_data_ptr<int16_t>();
46+
impl::HiFi::kernels::quantize<int16_t>(
47+
out_data, input_data, 1. / scale, zero_point, numel);
4348
} else if (out.scalar_type() == ScalarType::Int) {
4449
int32_t* out_data = out.mutable_data_ptr<int32_t>();
4550
impl::HiFi::kernels::quantize<int32_t>(
@@ -52,3 +57,4 @@ void quantize_per_tensor_out(
5257
}; // namespace native
5358
}; // namespace HiFi
5459
}; // namespace impl
60+
}; // namespace cadence

backends/cadence/hifi/operators/quantized_layer_norm.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ using executorch::aten::Tensor;
1616
using executorch::runtime::getLeadingDims;
1717
using executorch::runtime::KernelRuntimeContext;
1818

19+
namespace cadence {
1920
namespace impl {
2021
namespace HiFi {
2122
namespace native {
@@ -157,3 +158,4 @@ void quantized_layer_norm_out(
157158
}; // namespace native
158159
}; // namespace HiFi
159160
}; // namespace impl
161+
}; // namespace cadence

backends/cadence/hifi/operators/quantized_linear_out.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <algorithm>
1212
#include <cmath>
1313

14+
namespace cadence {
1415
namespace impl {
1516
namespace HiFi {
1617
namespace native {
@@ -69,3 +70,4 @@ void quantized_linear_out(
6970
}; // namespace native
7071
}; // namespace HiFi
7172
}; // namespace impl
73+
}; // namespace cadence

backends/cadence/hifi/operators/targets.bzl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,6 @@ def define_common_targets():
2626
],
2727
visibility = [
2828
"//executorch/backends/cadence/...",
29+
"@EXECUTORCH_CLIENTS",
2930
],
3031
)

0 commit comments

Comments
 (0)