From 08dfba38b99abcf12db39d6650e4e3758f1bd0b4 Mon Sep 17 00:00:00 2001 From: Gian Marco Iodice Date: Thu, 8 Jun 2023 15:59:28 +0100 Subject: Enable conversion of F32 NumPy files to F16 Resolves COMPMID-6277 Signed-off-by: Gian Marco Iodice Change-Id: Ibbe5eb0869f701d4329782101ee7336948350269 Reviewed-on: https://review.mlplatform.org/c/ml/ComputeLibrary/+/9747 Benchmark: Arm Jenkins Tested-by: Arm Jenkins Reviewed-by: Pablo Marquez Tello Comments-Addressed: Arm Jenkins --- utils/Utils.h | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) (limited to 'utils') diff --git a/utils/Utils.h b/utils/Utils.h index e3a5bb2c3c..d181022ffe 100644 --- a/utils/Utils.h +++ b/utils/Utils.h @@ -383,7 +383,22 @@ public: // Check if the typestring matches the given one std::string expect_typestr = get_typestring(tensor.info()->data_type()); - ARM_COMPUTE_ERROR_ON_MSG(_typestring != expect_typestr, "Typestrings mismatch"); + + bool enable_f32_to_f16_conversion = false; + if(_typestring != expect_typestr) + { + const std::string f32_typestring = "data_layout()); // Correct dimensions (Needs to match TensorShape dimension corrections) @@ -427,7 +442,7 @@ public: case arm_compute::DataType::F16: { // Read data - if(!are_layouts_different && !_fortran_order && tensor.info()->padding().empty()) + if(!are_layouts_different && !_fortran_order && tensor.info()->padding().empty() && !enable_f32_to_f16_conversion) { // If tensor has no padding read directly from stream. _fs.read(reinterpret_cast(tensor.buffer()), tensor.info()->total_size()); @@ -466,7 +481,17 @@ public: { Coordinates dst(id); arm_compute::permute(dst, perm); - _fs.read(reinterpret_cast(tensor.ptr_to_element(dst)), tensor.info()->element_size()); + if(enable_f32_to_f16_conversion) + { + float f32_val = 0; + _fs.read(reinterpret_cast(&f32_val), 4u); + half f16_val = half_float::half_cast(f32_val); + *(reinterpret_cast(tensor.ptr_to_element(dst))) = f16_val; + } + else + { + _fs.read(reinterpret_cast(tensor.ptr_to_element(dst)), tensor.info()->element_size()); + } }); } -- cgit v1.2.1