From 95cf8c34a7984615bdced5a52d66afdc6c95510f Mon Sep 17 00:00:00 2001 From: "Nam, David" Date: Tue, 14 Jan 2025 18:10:40 +0900 Subject: [PATCH] [GPU] Define to_type in jitter for reorder to support INT4 --- .../intel_gpu/src/kernel_selector/jitter.cpp | 1 + .../kernels/reorder/reorder_kernel.cpp | 1 + .../unit/test_cases/reorder_gpu_test.cpp | 31 +++++++++++++++++++ 3 files changed, 33 insertions(+) diff --git a/src/plugins/intel_gpu/src/kernel_selector/jitter.cpp b/src/plugins/intel_gpu/src/kernel_selector/jitter.cpp index db27b5e4b7368e..f41b233e761b89 100644 --- a/src/plugins/intel_gpu/src/kernel_selector/jitter.cpp +++ b/src/plugins/intel_gpu/src/kernel_selector/jitter.cpp @@ -1483,6 +1483,7 @@ JitConstants MakeTypeJitConstants(Datatype dataType, const std::string& macroNam break; case Datatype::INT4: type = "char"; + to_type = "convert_char(v)"; type_size = "0.5f"; is_fp = false; break; diff --git a/src/plugins/intel_gpu/src/kernel_selector/kernels/reorder/reorder_kernel.cpp b/src/plugins/intel_gpu/src/kernel_selector/kernels/reorder/reorder_kernel.cpp index ad4fe84ef84592..1e2c6fc65a7a49 100644 --- a/src/plugins/intel_gpu/src/kernel_selector/kernels/reorder/reorder_kernel.cpp +++ b/src/plugins/intel_gpu/src/kernel_selector/kernels/reorder/reorder_kernel.cpp @@ -12,6 +12,7 @@ ParamsKey ReorderKernelRef::GetSupportedKey() const { k.EnableInputDataType(Datatype::UINT8); k.EnableInputDataType(Datatype::UINT16); k.EnableInputDataType(Datatype::UINT32); + k.EnableInputDataType(Datatype::INT4); k.EnableInputDataType(Datatype::INT8); k.EnableInputDataType(Datatype::INT16); k.EnableInputDataType(Datatype::INT32); diff --git a/src/plugins/intel_gpu/tests/unit/test_cases/reorder_gpu_test.cpp b/src/plugins/intel_gpu/tests/unit/test_cases/reorder_gpu_test.cpp index 8caad2b576d734..add9e635c3db46 100644 --- a/src/plugins/intel_gpu/tests/unit/test_cases/reorder_gpu_test.cpp +++ b/src/plugins/intel_gpu/tests/unit/test_cases/reorder_gpu_test.cpp @@ -899,6 +899,37 @@ TEST(reorder_gpu, basic_convert_f16_f32_f16) { } } +TEST(reorder_gpu, basic_convert_i4_to_fp16) { + tests::random_generator rg(GET_SUITE_NAME); + auto& engine = get_test_engine(); + + layout in_layout = layout{ ov::PartialShape{ 1, 1, 3, 3 }, data_types::i4, format::bfyx }; + layout out_layout = layout{ ov::PartialShape{ 1, 1, 3, 3 }, data_types::f16, format::bfyx }; + + auto input = rg.generate_random_1d(9, -7, 7); + auto input_mem = engine.allocate_memory(in_layout); + set_values(input_mem, input); + + topology topology( + input_layout("input", in_layout), + reorder("convert", input_info("input"), out_layout) + ); + + ExecutionConfig config = get_test_default_config(engine); + config.set_property(ov::intel_gpu::optimize_data(true)); + network network(engine, topology, config); + + network.set_input_data("input", input_mem); + + auto outputs = network.execute(); + + auto output = outputs.begin()->second.get_memory(); + cldnn::mem_lock output_ptr(output, get_test_stream()); + for (size_t i = 0; i < output_ptr.size(); ++i) { + ASSERT_EQ(output_ptr[i], input[i]); + } +} + TEST(reorder_gpu, basic_convert_int8) { auto& engine = get_test_engine();