Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[INTEL MKL] Adding support for quantized type gather nd op registration #28278

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions tensorflow/core/kernels/gather_nd_op.cc
Expand Up @@ -71,6 +71,7 @@ class GatherNdOp : public OpKernel {
//
// Same for the GPU kernel.
TF_CALL_ALL_TYPES(REGISTER_GATHER_ND_CPU);
TF_CALL_QUANTIZED_TYPES(REGISTER_GATHER_ND_CPU);

#undef REGISTER_GATHER_ND_CPU

Expand Down
6 changes: 3 additions & 3 deletions tensorflow/core/kernels/gather_nd_op.h
Expand Up @@ -100,9 +100,9 @@ Status DoGatherNd(OpKernelContext* c, const Tensor& params,
}

if (slice_size_big > std::numeric_limits<Index>::max()) {
return errors::InvalidArgument(
"slice size is too large for indexing: ", slice_size_big, " > ",
std::numeric_limits<Index>::max());
return errors::InvalidArgument("slice size is too large for indexing: ",
cuixiaom marked this conversation as resolved.
Show resolved Hide resolved
slice_size_big, " > ",
std::numeric_limits<Index>::max());
}

const Index slice_size = static_cast<Index>(slice_size_big);
Expand Down
1 change: 1 addition & 0 deletions tensorflow/core/kernels/gather_nd_op_cpu_impl.h
Expand Up @@ -152,6 +152,7 @@ struct GatherNdSlice<CPUDevice, T, Index, IXDIM> {
REGISTER_GATHER_ND_FULL(type, int64)

TF_CALL_ALL_TYPES(REGISTER_GATHER_ND_CPU);
TF_CALL_QUANTIZED_TYPES(REGISTER_GATHER_ND_CPU);

} // namespace functor

Expand Down
32 changes: 29 additions & 3 deletions tensorflow/core/kernels/gather_nd_op_test.cc
Expand Up @@ -57,17 +57,17 @@ namespace {

class GatherNdOpTest : public OpsTestBase {
protected:
void MakeOp(DataType index_type) {
void MakeOp(DataType param_type, DataType index_type) {
TF_ASSERT_OK(NodeDefBuilder("myop", "GatherNd")
.Input(FakeInput(DT_FLOAT))
.Input(FakeInput(param_type))
.Input(FakeInput(index_type))
.Finalize(node_def()));
TF_ASSERT_OK(InitOp());
}
};

TEST_F(GatherNdOpTest, Simple) {
MakeOp(DT_INT32);
MakeOp(DT_FLOAT, DT_INT32);

// Feed and run
AddInputFromArray<float>(TensorShape({5}), {0, 1, 2, 8, 4});
Expand All @@ -80,6 +80,32 @@ TEST_F(GatherNdOpTest, Simple) {
test::ExpectTensorEqual<float>(expected, *GetOutput(0));
}

TEST_F(GatherNdOpTest, Quantized_UINT8) {
MakeOp(DT_QUINT8, DT_INT32);

// Feed and run
AddInputFromArray<quint8>(TensorShape({5}), {0, 1, 2, 8, 4});
AddInputFromArray<int32>(TensorShape({2, 1}), {3, 4});
TF_ASSERT_OK(RunOpKernel());

// Check the output.
Tensor expected(allocator(), DT_QUINT8, TensorShape({2}));
test::FillValues<quint8>(&expected, {8, 4});
test::ExpectTensorEqual<quint8>(expected, *GetOutput(0));
}

TEST_F(GatherNdOpTest, Quantized_INT8) {
MakeOp(DT_QINT8, DT_INT32);

AddInputFromArray<qint8>(TensorShape({5}), {0, 1, 2, 8, 4});
AddInputFromArray<int32>(TensorShape({2, 1}), {3, 4});
TF_ASSERT_OK(RunOpKernel());

Tensor expected(allocator(), DT_QINT8, TensorShape({2}));
test::FillValues<qint8>(&expected, {8, 4});
test::ExpectTensorEqual<qint8>(expected, *GetOutput(0));
}

constexpr int kLookups = 2000;

template <typename Index>
Expand Down