Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions src/plugins/intel_gpu/src/plugin/ops/constant.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,23 @@ static void create_data(ProgramBuilder& p, const ov::Shape& const_shape, const s
const auto* f64data = op->get_data_ptr<double>();
auto f32buf = reinterpret_cast<float*>(buf);
f32buf[0] = static_cast<float>(f64data[0]);
} else if (out_dtype == cldnn::data_types::f32 &&
(op->get_output_element_type(0) == ov::element::u16 ||
op->get_output_element_type(0) == ov::element::i16)) {
size_t count = ov::shape_size(const_shape);
auto f32buf = reinterpret_cast<float*>(buf);

if (op->get_output_element_type(0) == ov::element::u16) {
const auto* u16data = op->get_data_ptr<uint16_t>();
for (size_t i = 0; i < count; i++) {
f32buf[i] = static_cast<float>(u16data[i]);
}
} else {
const auto* i16data = op->get_data_ptr<int16_t>();
for (size_t i = 0; i < count; i++) {
f32buf[i] = static_cast<float>(i16data[i]);
}
}
} else {
std::memcpy(&buf[0], &data[0], bufSize);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class ConstantResultSubgraphTest : public testing::WithParamInterface<constResul

protected:
void SetUp() override;
void run() override;
};

} // namespace test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,5 +66,49 @@ void ConstantResultSubgraphTest::SetUp() {

createGraph(type, input_shape, input_type);
}

void ConstantResultSubgraphTest::run() {
compile_model();
inferRequest = compiledModel.create_infer_request();
ASSERT_TRUE(inferRequest);
inferRequest.infer();

const auto& [type, input_shape, input_type, _] = this->GetParam();
if (input_type == ov::element::i16 || input_type == ov::element::u16) {
auto outputs = function->get_results();
for (size_t i = 0; i < outputs.size(); ++i) {
auto result_tensor = inferRequest.get_tensor(outputs[i]);
ASSERT_TRUE(result_tensor);

auto constant_node = std::dynamic_pointer_cast<ov::op::v0::Constant>(
outputs[i]->get_input_node_shared_ptr(0));
ASSERT_TRUE(constant_node) << "Failed to get constant node for output " << i;

size_t num_elements = result_tensor.get_size();
ASSERT_EQ(result_tensor.get_element_type(), input_type)
<< "Output type mismatch for " << input_type;

if (input_type == ov::element::i16) {
auto expected_data = constant_node->get_data_ptr<int16_t>();
auto actual_data = result_tensor.data<int16_t>();
for (size_t j = 0; j < num_elements; ++j) {
EXPECT_EQ(actual_data[j], expected_data[j])
<< "Mismatch at element " << j << "/" << num_elements
<< ": expected " << expected_data[j]
<< ", got " << actual_data[j];
}
} else {
auto expected_data = constant_node->get_data_ptr<uint16_t>();
auto actual_data = result_tensor.data<uint16_t>();
for (size_t j = 0; j < num_elements; ++j) {
EXPECT_EQ(actual_data[j], expected_data[j])
<< "Mismatch at element " << j << "/" << num_elements
<< ": expected " << expected_data[j]
<< ", got " << actual_data[j];
}
}
}
}
}
} // namespace test
} // namespace ov
Loading