From: Jaeyun Date: Tue, 4 Dec 2018 10:16:47 +0000 (+0900) Subject: [Orc] add functions for typecast X-Git-Tag: v0.1.0~87 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=4406e155cb9fc766d1881f35bc38a9b9add849f4;p=platform%2Fupstream%2Fnnstreamer.git [Orc] add functions for typecast 1. add typecast functions 2. add testcases for typecast Signed-off-by: Jaeyun Jung --- diff --git a/gst/tensor_transform/transform-orc.orc b/gst/tensor_transform/transform-orc.orc index a1d3e72..a0d5ecf 100644 --- a/gst/tensor_transform/transform-orc.orc +++ b/gst/tensor_transform/transform-orc.orc @@ -14,6 +14,67 @@ mulsbw t1, d1, p1 convssswb d1, t1 +.function nns_orc_conv_s8_to_u8 +.dest 1 d1 uint8_t +.source 1 s1 int8_t + +copyb d1, s1 + + +.function nns_orc_conv_s8_to_s16 +.dest 2 d1 int16_t +.source 1 s1 int8_t + +convsbw d1, s1 + + +.function nns_orc_conv_s8_to_u16 +.dest 2 d1 uint16_t +.source 1 s1 int8_t + +convsbw d1, s1 + + +.function nns_orc_conv_s8_to_s32 +.dest 4 d1 int32_t +.source 1 s1 int8_t +.temp 2 t1 + +convsbw t1, s1 +convswl d1, t1 + + +.function nns_orc_conv_s8_to_u32 +.dest 4 d1 uint32_t +.source 1 s1 int8_t +.temp 2 t1 + +convsbw t1, s1 +convswl d1, t1 + + +.function nns_orc_conv_s8_to_f32 +.dest 4 d1 float +.source 1 s1 int8_t +.temp 2 t1 +.temp 4 t2 + +convsbw t1, s1 +convswl t2, t1 +convlf d1, t2 + + +.function nns_orc_conv_s8_to_f64 +.dest 8 d1 double +.source 1 s1 int8_t +.temp 2 t1 +.temp 4 t2 + +convsbw t1, s1 +convswl t2, t1 +convld d1, t2 + + .function nns_orc_add_c_u8 .dest 1 d1 uint8_t .param 1 p1 uint8_t @@ -30,6 +91,67 @@ mulubw t1, d1, p1 convuuswb d1, t1 +.function nns_orc_conv_u8_to_s8 +.dest 1 d1 int8_t +.source 1 s1 uint8_t + +copyb d1, s1 + + +.function nns_orc_conv_u8_to_s16 +.dest 2 d1 int16_t +.source 1 s1 uint8_t + +convubw d1, s1 + + +.function nns_orc_conv_u8_to_u16 +.dest 2 d1 uint16_t +.source 1 s1 uint8_t + +convubw d1, s1 + + +.function nns_orc_conv_u8_to_s32 +.dest 4 d1 int32_t +.source 1 s1 uint8_t +.temp 2 t1 + +convubw t1, s1 +convuwl d1, t1 + + +.function nns_orc_conv_u8_to_u32 +.dest 4 d1 uint32_t +.source 1 s1 uint8_t +.temp 2 t1 + +convubw t1, s1 +convuwl d1, t1 + + +.function nns_orc_conv_u8_to_f32 +.dest 4 d1 float +.source 1 s1 uint8_t +.temp 2 t1 +.temp 4 t2 + +convubw t1, s1 +convuwl t2, t1 +convlf d1, t2 + + +.function nns_orc_conv_u8_to_f64 +.dest 8 d1 double +.source 1 s1 uint8_t +.temp 2 t1 +.temp 4 t2 + +convubw t1, s1 +convuwl t2, t1 +convld d1, t2 + + .function nns_orc_add_c_s16 .dest 2 d1 int16_t .param 2 p1 int16_t @@ -46,6 +168,60 @@ mulswl t1, d1, p1 convssslw d1, t1 +.function nns_orc_conv_s16_to_s8 +.dest 1 d1 int8_t +.source 2 s1 int16_t + +convssswb d1, s1 + + +.function nns_orc_conv_s16_to_u8 +.dest 1 d1 uint8_t +.source 2 s1 int16_t + +convssswb d1, s1 + + +.function nns_orc_conv_s16_to_u16 +.dest 2 d1 uint16_t +.source 2 s1 int16_t + +copyw d1, s1 + + +.function nns_orc_conv_s16_to_s32 +.dest 4 d1 int32_t +.source 2 s1 int16_t + +convswl d1, s1 + + +.function nns_orc_conv_s16_to_u32 +.dest 4 d1 uint32_t +.source 2 s1 int16_t +.temp 4 t1 + +convswl d1, s1 + + +.function nns_orc_conv_s16_to_f32 +.dest 4 d1 float +.source 2 s1 int16_t +.temp 4 t1 + +convswl t1, s1 +convlf d1, t1 + + +.function nns_orc_conv_s16_to_f64 +.dest 8 d1 double +.source 2 s1 int16_t +.temp 4 t1 + +convswl t1, s1 +convld d1, t1 + + .function nns_orc_add_c_u16 .dest 2 d1 uint16_t .param 2 p1 uint16_t @@ -62,6 +238,59 @@ muluwl t1, d1, p1 convuuslw d1, t1 +.function nns_orc_conv_u16_to_s8 +.dest 1 d1 int8_t +.source 2 s1 uint16_t + +convssswb d1, s1 + + +.function nns_orc_conv_u16_to_u8 +.dest 1 d1 uint8_t +.source 2 s1 uint16_t + +convssswb d1, s1 + + +.function nns_orc_conv_u16_to_s16 +.dest 2 d1 int16_t +.source 2 s1 uint16_t + +copyw d1, s1 + + +.function nns_orc_conv_u16_to_s32 +.dest 4 d1 int32_t +.source 2 s1 uint16_t + +convuwl d1, s1 + + +.function nns_orc_conv_u16_to_u32 +.dest 4 d1 uint32_t +.source 2 s1 uint16_t + +convuwl d1, s1 + + +.function nns_orc_conv_u16_to_f32 +.dest 4 d1 float +.source 2 s1 uint16_t +.temp 4 t1 + +convuwl t1, s1 +convlf d1, t1 + + +.function nns_orc_conv_u16_to_f64 +.dest 8 d1 double +.source 2 s1 uint16_t +.temp 4 t1 + +convuwl t1, s1 +convld d1, t1 + + .function nns_orc_add_c_s32 .dest 4 d1 int32_t .param 4 p1 int32_t @@ -78,6 +307,60 @@ mulslq t1, d1, p1 convsssql d1, t1 +.function nns_orc_conv_s32_to_s8 +.dest 1 d1 int8_t +.source 4 s1 int32_t +.temp 2 t1 + +convssslw t1, s1 +convssswb d1, t1 + + +.function nns_orc_conv_s32_to_u8 +.dest 1 d1 uint8_t +.source 4 s1 int32_t +.temp 2 t1 + +convssslw t1, s1 +convssswb d1, t1 + + +.function nns_orc_conv_s32_to_s16 +.dest 2 d1 int16_t +.source 4 s1 int32_t + +convssslw d1, s1 + + +.function nns_orc_conv_s32_to_u16 +.dest 2 d1 uint16_t +.source 4 s1 int32_t +.temp 2 t1 + +convssslw d1, s1 + + +.function nns_orc_conv_s32_to_u32 +.dest 4 d1 uint32_t +.source 4 s1 int32_t + +copyl d1, s1 + + +.function nns_orc_conv_s32_to_f32 +.dest 4 d1 float +.source 4 s1 int32_t + +convlf d1, s1 + + +.function nns_orc_conv_s32_to_f64 +.dest 8 d1 double +.source 4 s1 int32_t + +convld d1, s1 + + .function nns_orc_add_c_u32 .dest 4 d1 uint32_t .param 4 p1 uint32_t @@ -94,6 +377,59 @@ mululq t1, d1, p1 convuusql d1, t1 +.function nns_orc_conv_u32_to_s8 +.dest 1 d1 int8_t +.source 4 s1 uint32_t +.temp 2 t1 + +convssslw t1, s1 +convssswb d1, t1 + + +.function nns_orc_conv_u32_to_u8 +.dest 1 d1 uint8_t +.source 4 s1 uint32_t +.temp 2 t1 + +convssslw t1, s1 +convssswb d1, t1 + + +.function nns_orc_conv_u32_to_s16 +.dest 2 d1 int16_t +.source 4 s1 uint32_t + +convssslw d1, s1 + + +.function nns_orc_conv_u32_to_u16 +.dest 2 d1 uint16_t +.source 4 s1 uint32_t + +convssslw d1, s1 + + +.function nns_orc_conv_u32_to_s32 +.dest 4 d1 int32_t +.source 4 s1 uint32_t + +copyl d1, s1 + + +.function nns_orc_conv_u32_to_f32 +.dest 4 d1 float +.source 4 s1 uint32_t + +convlf d1, s1 + + +.function nns_orc_conv_u32_to_f64 +.dest 8 d1 double +.source 4 s1 uint32_t + +convld d1, s1 + + .function nns_orc_add_c_f32 .dest 4 d1 float .floatparam 4 p1 float @@ -108,6 +444,67 @@ addf d1, d1, p1 mulf d1, d1, p1 +.function nns_orc_conv_f32_to_s8 +.dest 1 d1 int8_t +.source 4 s1 float +.temp 4 t1 +.temp 2 t2 + +convfl t1, s1 +convssslw t2, t1 +convssswb d1, t2 + + +.function nns_orc_conv_f32_to_u8 +.dest 1 d1 uint8_t +.source 4 s1 float +.temp 4 t1 +.temp 2 t2 + +convfl t1, s1 +convssslw t2, t1 +convssswb d1, t2 + + +.function nns_orc_conv_f32_to_s16 +.dest 2 d1 int16_t +.source 4 s1 float +.temp 4 t1 + +convfl t1, s1 +convssslw d1, t1 + + +.function nns_orc_conv_f32_to_u16 +.dest 2 d1 uint16_t +.source 4 s1 float +.temp 4 t1 + +convfl t1, s1 +convssslw d1, t1 + + +.function nns_orc_conv_f32_to_s32 +.dest 4 d1 int32_t +.source 4 s1 float + +convfl d1, s1 + + +.function nns_orc_conv_f32_to_u32 +.dest 4 d1 uint32_t +.source 4 s1 float + +convfl d1, s1 + + +.function nns_orc_conv_f32_to_f64 +.dest 8 d1 double +.source 4 s1 float + +convfd d1, s1 + + .function nns_orc_add_c_f64 .dest 8 d1 double .doubleparam 8 p1 double @@ -120,3 +517,64 @@ addd d1, d1, p1 .doubleparam 8 p1 double muld d1, d1, p1 + + +.function nns_orc_conv_f64_to_s8 +.dest 1 d1 int8_t +.source 8 s1 double +.temp 4 t1 +.temp 2 t2 + +convdl t1, s1 +convssslw t2, t1 +convssswb d1, t2 + + +.function nns_orc_conv_f64_to_u8 +.dest 1 d1 uint8_t +.source 8 s1 double +.temp 4 t1 +.temp 2 t2 + +convdl t1, s1 +convssslw t2, t1 +convssswb d1, t2 + + +.function nns_orc_conv_f64_to_s16 +.dest 2 d1 int16_t +.source 8 s1 double +.temp 4 t1 + +convdl t1, s1 +convssslw d1, t1 + + +.function nns_orc_conv_f64_to_u16 +.dest 2 d1 uint16_t +.source 8 s1 double +.temp 4 t1 + +convdl t1, s1 +convssslw d1, t1 + + +.function nns_orc_conv_f64_to_s32 +.dest 4 d1 int32_t +.source 8 s1 double + +convdl d1, s1 + + +.function nns_orc_conv_f64_to_u32 +.dest 4 d1 uint32_t +.source 8 s1 double + +convdl d1, s1 + + +.function nns_orc_conv_f64_to_f32 +.dest 4 d1 float +.source 8 s1 double + +convdf d1, s1 diff --git a/tests/nnstreamer_plugins/unittest_plugins.cpp b/tests/nnstreamer_plugins/unittest_plugins.cpp index 2943bfb..dc6a275 100644 --- a/tests/nnstreamer_plugins/unittest_plugins.cpp +++ b/tests/nnstreamer_plugins/unittest_plugins.cpp @@ -856,6 +856,750 @@ TEST (test_tensor_transform, orc_mul) EXPECT_DOUBLE_EQ (data_f64[i], (i + .2) * 20.5); } } + +/** + * @brief Test for tensor_transform orc functions (convert s8 to other type) + */ +TEST (test_tensor_transform, orc_conv_s8) +{ + const guint array_size = 10; + guint i; + + int8_t data_s8[array_size] = { 0, }; + + for (i = 0; i < array_size; i++) { + data_s8[i] = (i + 1) * -1; + } + + /* convert u8 */ + uint8_t res_u8[array_size] = { 0, }; + + nns_orc_conv_s8_to_u8 (res_u8, data_s8, array_size); + + for (i = 0; i < array_size; i++) { + EXPECT_EQ (res_u8[i], (uint8_t) data_s8[i]); + } + + /* convert s16 */ + int16_t res_s16[array_size] = { 0, }; + + nns_orc_conv_s8_to_s16 (res_s16, data_s8, array_size); + + for (i = 0; i < array_size; i++) { + EXPECT_EQ (res_s16[i], (int16_t) data_s8[i]); + } + + /* convert u16 */ + uint16_t res_u16[array_size] = { 0, }; + + nns_orc_conv_s8_to_u16 (res_u16, data_s8, array_size); + + for (i = 0; i < array_size; i++) { + EXPECT_EQ (res_u16[i], (uint16_t) data_s8[i]); + } + + /* convert s32 */ + int32_t res_s32[array_size] = { 0, }; + + nns_orc_conv_s8_to_s32 (res_s32, data_s8, array_size); + + for (i = 0; i < array_size; i++) { + EXPECT_EQ (res_s32[i], (int32_t) data_s8[i]); + } + + /* convert u32 */ + uint32_t res_u32[array_size] = { 0, }; + + nns_orc_conv_s8_to_u32 (res_u32, data_s8, array_size); + + for (i = 0; i < array_size; i++) { + EXPECT_EQ (res_u32[i], (uint32_t) data_s8[i]); + } + + /* convert f32 */ + float res_f32[array_size] = { 0, }; + + nns_orc_conv_s8_to_f32 (res_f32, data_s8, array_size); + + for (i = 0; i < array_size; i++) { + EXPECT_FLOAT_EQ (res_f32[i], (float) data_s8[i]); + } + + /* convert f64 */ + double res_f64[array_size] = { 0, }; + + nns_orc_conv_s8_to_f64 (res_f64, data_s8, array_size); + + for (i = 0; i < array_size; i++) { + EXPECT_DOUBLE_EQ (res_f64[i], (double) data_s8[i]); + } +} + +/** + * @brief Test for tensor_transform orc functions (convert u8 to other type) + */ +TEST (test_tensor_transform, orc_conv_u8) +{ + const guint array_size = 10; + guint i; + + uint8_t data_u8[array_size] = { 0, }; + + for (i = 0; i < array_size; i++) { + data_u8[i] = G_MAXUINT8 - i; + } + + /* convert s8 */ + int8_t res_s8[array_size] = { 0, }; + + nns_orc_conv_u8_to_s8 (res_s8, data_u8, array_size); + + for (i = 0; i < array_size; i++) { + EXPECT_EQ (res_s8[i], (int8_t) data_u8[i]); + } + + /* convert s16 */ + int16_t res_s16[array_size] = { 0, }; + + nns_orc_conv_u8_to_s16 (res_s16, data_u8, array_size); + + for (i = 0; i < array_size; i++) { + EXPECT_EQ (res_s16[i], (int16_t) data_u8[i]); + } + + /* convert u16 */ + uint16_t res_u16[array_size] = { 0, }; + + nns_orc_conv_u8_to_u16 (res_u16, data_u8, array_size); + + for (i = 0; i < array_size; i++) { + EXPECT_EQ (res_u16[i], (uint16_t) data_u8[i]); + } + + /* convert s32 */ + int32_t res_s32[array_size] = { 0, }; + + nns_orc_conv_u8_to_s32 (res_s32, data_u8, array_size); + + for (i = 0; i < array_size; i++) { + EXPECT_EQ (res_s32[i], (int32_t) data_u8[i]); + } + + /* convert u32 */ + uint32_t res_u32[array_size] = { 0, }; + + nns_orc_conv_u8_to_u32 (res_u32, data_u8, array_size); + + for (i = 0; i < array_size; i++) { + EXPECT_EQ (res_u32[i], (uint32_t) data_u8[i]); + } + + /* convert f32 */ + float res_f32[array_size] = { 0, }; + + nns_orc_conv_u8_to_f32 (res_f32, data_u8, array_size); + + for (i = 0; i < array_size; i++) { + EXPECT_FLOAT_EQ (res_f32[i], (float) data_u8[i]); + } + + /* convert f64 */ + double res_f64[array_size] = { 0, }; + + nns_orc_conv_u8_to_f64 (res_f64, data_u8, array_size); + + for (i = 0; i < array_size; i++) { + EXPECT_DOUBLE_EQ (res_f64[i], (double) data_u8[i]); + } +} + +/** + * @brief Test for tensor_transform orc functions (convert s16 to other type) + */ +TEST (test_tensor_transform, orc_conv_s16) +{ + const guint array_size = 10; + guint i; + + int16_t data_s16[array_size] = { 0, }; + + for (i = 0; i < array_size; i++) { + data_s16[i] = (i + 1) * -1; + } + + /* convert s8 */ + int8_t res_s8[array_size] = { 0, }; + + nns_orc_conv_s16_to_s8 (res_s8, data_s16, array_size); + + for (i = 0; i < array_size; i++) { + EXPECT_EQ (res_s8[i], (int8_t) data_s16[i]); + } + + /* convert u8 */ + uint8_t res_u8[array_size] = { 0, }; + + nns_orc_conv_s16_to_u8 (res_u8, data_s16, array_size); + + for (i = 0; i < array_size; i++) { + EXPECT_EQ (res_u8[i], (uint8_t) data_s16[i]); + } + + /* convert u16 */ + uint16_t res_u16[array_size] = { 0, }; + + nns_orc_conv_s16_to_u16 (res_u16, data_s16, array_size); + + for (i = 0; i < array_size; i++) { + EXPECT_EQ (res_u16[i], (uint16_t) data_s16[i]); + } + + /* convert s32 */ + int32_t res_s32[array_size] = { 0, }; + + nns_orc_conv_s16_to_s32 (res_s32, data_s16, array_size); + + for (i = 0; i < array_size; i++) { + EXPECT_EQ (res_s32[i], (int32_t) data_s16[i]); + } + + /* convert u32 */ + uint32_t res_u32[array_size] = { 0, }; + + nns_orc_conv_s16_to_u32 (res_u32, data_s16, array_size); + + for (i = 0; i < array_size; i++) { + EXPECT_EQ (res_u32[i], (uint32_t) data_s16[i]); + } + + /* convert f32 */ + float res_f32[array_size] = { 0, }; + + nns_orc_conv_s16_to_f32 (res_f32, data_s16, array_size); + + for (i = 0; i < array_size; i++) { + EXPECT_FLOAT_EQ (res_f32[i], (float) data_s16[i]); + } + + /* convert f64 */ + double res_f64[array_size] = { 0, }; + + nns_orc_conv_s16_to_f64 (res_f64, data_s16, array_size); + + for (i = 0; i < array_size; i++) { + EXPECT_DOUBLE_EQ (res_f64[i], (double) data_s16[i]); + } +} + +/** + * @brief Test for tensor_transform orc functions (convert u16 to other type) + */ +TEST (test_tensor_transform, orc_conv_u16) +{ + const guint array_size = 10; + guint i; + + uint16_t data_u16[array_size] = { 0, }; + + for (i = 0; i < array_size; i++) { + data_u16[i] = G_MAXUINT16 - i; + } + + /* convert s8 */ + int8_t res_s8[array_size] = { 0, }; + + nns_orc_conv_u16_to_s8 (res_s8, data_u16, array_size); + + for (i = 0; i < array_size; i++) { + EXPECT_EQ (res_s8[i], (int8_t) data_u16[i]); + } + + /* convert u8 */ + uint8_t res_u8[array_size] = { 0, }; + + nns_orc_conv_u16_to_u8 (res_u8, data_u16, array_size); + + for (i = 0; i < array_size; i++) { + EXPECT_EQ (res_u8[i], (uint8_t) data_u16[i]); + } + + /* convert s16 */ + int16_t res_s16[array_size] = { 0, }; + + nns_orc_conv_u16_to_s16 (res_s16, data_u16, array_size); + + for (i = 0; i < array_size; i++) { + EXPECT_EQ (res_s16[i], (int16_t) data_u16[i]); + } + + /* convert s32 */ + int32_t res_s32[array_size] = { 0, }; + + nns_orc_conv_u16_to_s32 (res_s32, data_u16, array_size); + + for (i = 0; i < array_size; i++) { + EXPECT_EQ (res_s32[i], (int32_t) data_u16[i]); + } + + /* convert u32 */ + uint32_t res_u32[array_size] = { 0, }; + + nns_orc_conv_u16_to_u32 (res_u32, data_u16, array_size); + + for (i = 0; i < array_size; i++) { + EXPECT_EQ (res_u32[i], (uint32_t) data_u16[i]); + } + + /* convert f32 */ + float res_f32[array_size] = { 0, }; + + nns_orc_conv_u16_to_f32 (res_f32, data_u16, array_size); + + for (i = 0; i < array_size; i++) { + EXPECT_FLOAT_EQ (res_f32[i], (float) data_u16[i]); + } + + /* convert f64 */ + double res_f64[array_size] = { 0, }; + + nns_orc_conv_u16_to_f64 (res_f64, data_u16, array_size); + + for (i = 0; i < array_size; i++) { + EXPECT_DOUBLE_EQ (res_f64[i], (double) data_u16[i]); + } +} + +/** + * @brief Test for tensor_transform orc functions (convert s32 to other type) + */ +TEST (test_tensor_transform, orc_conv_s32) +{ + const guint array_size = 10; + guint i; + + int32_t data_s32[array_size] = { 0, }; + + for (i = 0; i < array_size; i++) { + data_s32[i] = (i + 1) * -1; + } + + /* convert s8 */ + int8_t res_s8[array_size] = { 0, }; + + nns_orc_conv_s32_to_s8 (res_s8, data_s32, array_size); + + for (i = 0; i < array_size; i++) { + EXPECT_EQ (res_s8[i], (int8_t) data_s32[i]); + } + + /* convert u8 */ + uint8_t res_u8[array_size] = { 0, }; + + nns_orc_conv_s32_to_u8 (res_u8, data_s32, array_size); + + for (i = 0; i < array_size; i++) { + EXPECT_EQ (res_u8[i], (uint8_t) data_s32[i]); + } + + /* convert s16 */ + int16_t res_s16[array_size] = { 0, }; + + nns_orc_conv_s32_to_s16 (res_s16, data_s32, array_size); + + for (i = 0; i < array_size; i++) { + EXPECT_EQ (res_s16[i], (int16_t) data_s32[i]); + } + + /* convert u16 */ + uint16_t res_u16[array_size] = { 0, }; + + nns_orc_conv_s32_to_u16 (res_u16, data_s32, array_size); + + for (i = 0; i < array_size; i++) { + EXPECT_EQ (res_u16[i], (uint16_t) data_s32[i]); + } + + /* convert u32 */ + uint32_t res_u32[array_size] = { 0, }; + + nns_orc_conv_s32_to_u32 (res_u32, data_s32, array_size); + + for (i = 0; i < array_size; i++) { + EXPECT_EQ (res_u32[i], (uint32_t) data_s32[i]); + } + + /* convert f32 */ + float res_f32[array_size] = { 0, }; + + nns_orc_conv_s32_to_f32 (res_f32, data_s32, array_size); + + for (i = 0; i < array_size; i++) { + EXPECT_FLOAT_EQ (res_f32[i], (float) data_s32[i]); + } + + /* convert f64 */ + double res_f64[array_size] = { 0, }; + + nns_orc_conv_s32_to_f64 (res_f64, data_s32, array_size); + + for (i = 0; i < array_size; i++) { + EXPECT_DOUBLE_EQ (res_f64[i], (double) data_s32[i]); + } +} + +/** + * @brief Test for tensor_transform orc functions (convert u32 to other type) + */ +TEST (test_tensor_transform, orc_conv_u32) +{ + const guint array_size = 10; + guint i; + + uint32_t data_u32[array_size] = { 0, }; + + for (i = 0; i < array_size; i++) { + data_u32[i] = G_MAXUINT32 - i; + } + + /* convert s8 */ + int8_t res_s8[array_size] = { 0, }; + + nns_orc_conv_u32_to_s8 (res_s8, data_u32, array_size); + + for (i = 0; i < array_size; i++) { + EXPECT_EQ (res_s8[i], (int8_t) data_u32[i]); + } + + /* convert u8 */ + uint8_t res_u8[array_size] = { 0, }; + + nns_orc_conv_u32_to_u8 (res_u8, data_u32, array_size); + + for (i = 0; i < array_size; i++) { + EXPECT_EQ (res_u8[i], (uint8_t) data_u32[i]); + } + + /* convert s16 */ + int16_t res_s16[array_size] = { 0, }; + + nns_orc_conv_u32_to_s16 (res_s16, data_u32, array_size); + + for (i = 0; i < array_size; i++) { + EXPECT_EQ (res_s16[i], (int16_t) data_u32[i]); + } + + /* convert u16 */ + uint16_t res_u16[array_size] = { 0, }; + + nns_orc_conv_u32_to_u16 (res_u16, data_u32, array_size); + + for (i = 0; i < array_size; i++) { + EXPECT_EQ (res_u16[i], (uint16_t) data_u32[i]); + } + + /* convert s32 */ + int32_t res_s32[array_size] = { 0, }; + + nns_orc_conv_u32_to_s32 (res_s32, data_u32, array_size); + + for (i = 0; i < array_size; i++) { + EXPECT_EQ (res_s32[i], (int32_t) data_u32[i]); + } + + /* convert f32 */ + float res_f32[array_size] = { 0, }; + + nns_orc_conv_u32_to_f32 (res_f32, data_u32, array_size); + + for (i = 0; i < array_size; i++) { + EXPECT_FLOAT_EQ (res_f32[i], (float) ((int32_t) data_u32[i])); + } + + /* convert f64 */ + double res_f64[array_size] = { 0, }; + + nns_orc_conv_u32_to_f64 (res_f64, data_u32, array_size); + + for (i = 0; i < array_size; i++) { + EXPECT_DOUBLE_EQ (res_f64[i], (double) ((int32_t) data_u32[i])); + } +} + +/** + * @brief Test for tensor_transform orc functions (convert f32 to other type) + */ +TEST (test_tensor_transform, orc_conv_f32) +{ + const guint array_size = 10; + guint i; + + float data_f32[array_size] = { 0, }; + + for (i = 0; i < array_size; i++) { + data_f32[i] = (i + 1.) * -1.; + } + + /* convert s8 */ + int8_t res_s8[array_size] = { 0, }; + + nns_orc_conv_f32_to_s8 (res_s8, data_f32, array_size); + + for (i = 0; i < array_size; i++) { + EXPECT_EQ (res_s8[i], (int8_t) data_f32[i]); + } + + /* convert u8 */ + uint8_t res_u8[array_size] = { 0, }; + + nns_orc_conv_f32_to_u8 (res_u8, data_f32, array_size); + + for (i = 0; i < array_size; i++) { + int8_t val = (int8_t) data_f32[i]; + EXPECT_EQ (res_u8[i], (uint8_t) val); + } + + /* convert s16 */ + int16_t res_s16[array_size] = { 0, }; + + nns_orc_conv_f32_to_s16 (res_s16, data_f32, array_size); + + for (i = 0; i < array_size; i++) { + EXPECT_EQ (res_s16[i], (int16_t) data_f32[i]); + } + + /* convert u16 */ + uint16_t res_u16[array_size] = { 0, }; + + nns_orc_conv_f32_to_u16 (res_u16, data_f32, array_size); + + for (i = 0; i < array_size; i++) { + int16_t val = (int16_t) data_f32[i]; + EXPECT_EQ (res_u16[i], (uint16_t) val); + } + + /* convert s32 */ + int32_t res_s32[array_size] = { 0, }; + + nns_orc_conv_f32_to_s32 (res_s32, data_f32, array_size); + + for (i = 0; i < array_size; i++) { + EXPECT_EQ (res_s32[i], (int32_t) data_f32[i]); + } + + /* convert u32 */ + uint32_t res_u32[array_size] = { 0, }; + + nns_orc_conv_f32_to_u32 (res_u32, data_f32, array_size); + + for (i = 0; i < array_size; i++) { + int32_t val = (int32_t) data_f32[i]; + EXPECT_EQ (res_u32[i], (uint32_t) val); + } + + /* convert f64 */ + double res_f64[array_size] = { 0, }; + + nns_orc_conv_f32_to_f64 (res_f64, data_f32, array_size); + + for (i = 0; i < array_size; i++) { + EXPECT_DOUBLE_EQ (res_f64[i], (double) data_f32[i]); + } +} + +/** + * @brief Test for tensor_transform orc functions (convert f64 to other type) + */ +TEST (test_tensor_transform, orc_conv_f64) +{ + const guint array_size = 10; + guint i; + + double data_f64[array_size] = { 0, }; + + for (i = 0; i < array_size; i++) { + data_f64[i] = (i + 1.) * -1.; + } + + /* convert s8 */ + int8_t res_s8[array_size] = { 0, }; + + nns_orc_conv_f64_to_s8 (res_s8, data_f64, array_size); + + for (i = 0; i < array_size; i++) { + EXPECT_EQ (res_s8[i], (int8_t) data_f64[i]); + } + + /* convert u8 */ + uint8_t res_u8[array_size] = { 0, }; + + nns_orc_conv_f64_to_u8 (res_u8, data_f64, array_size); + + for (i = 0; i < array_size; i++) { + int8_t val = (int8_t) data_f64[i]; + EXPECT_EQ (res_u8[i], (uint8_t) val); + } + + /* convert s16 */ + int16_t res_s16[array_size] = { 0, }; + + nns_orc_conv_f64_to_s16 (res_s16, data_f64, array_size); + + for (i = 0; i < array_size; i++) { + EXPECT_EQ (res_s16[i], (int16_t) data_f64[i]); + } + + /* convert u16 */ + uint16_t res_u16[array_size] = { 0, }; + + nns_orc_conv_f64_to_u16 (res_u16, data_f64, array_size); + + for (i = 0; i < array_size; i++) { + int16_t val = (int16_t) data_f64[i]; + EXPECT_EQ (res_u16[i], (uint16_t) val); + } + + /* convert s32 */ + int32_t res_s32[array_size] = { 0, }; + + nns_orc_conv_f64_to_s32 (res_s32, data_f64, array_size); + + for (i = 0; i < array_size; i++) { + EXPECT_EQ (res_s32[i], (int32_t) data_f64[i]); + } + + /* convert u32 */ + uint32_t res_u32[array_size] = { 0, }; + + nns_orc_conv_f64_to_u32 (res_u32, data_f64, array_size); + + for (i = 0; i < array_size; i++) { + int32_t val = (int32_t) data_f64[i]; + EXPECT_EQ (res_u32[i], (uint32_t) val); + } + + /* convert f32 */ + float res_f32[array_size] = { 0, }; + + nns_orc_conv_f64_to_f32 (res_f32, data_f64, array_size); + + for (i = 0; i < array_size; i++) { + EXPECT_FLOAT_EQ (res_f32[i], (float) data_f64[i]); + } +} + +/** + * @brief Test for tensor_transform orc functions (performance) + */ +TEST (test_tensor_transform, orc_performance_u8) +{ + const guint array_size = 80000; + guint i; + + gint64 start_ts, stop_ts, diff_loop, diff_orc; + + uint8_t *data_u8 = (uint8_t *) g_malloc0 (sizeof (uint8_t) * array_size); + float *data_float = (float *) g_malloc0 (sizeof (float) * array_size); + + /* orc add */ + start_ts = g_get_real_time (); + nns_orc_add_c_u8 (data_u8, 2, array_size); + stop_ts = g_get_real_time (); + + diff_orc = stop_ts - start_ts; + _print_log ("add u8 orc: %" G_GINT64_FORMAT, diff_orc); + + for (i = 0; i < array_size; ++i) { + EXPECT_EQ (data_u8[i], 2); + } + + /* loop */ + start_ts = g_get_real_time (); + for (i = 0; i < array_size; ++i) { + data_u8[i] += 2; + } + stop_ts = g_get_real_time (); + + diff_loop = stop_ts - start_ts; + _print_log ("add u8 loop: %" G_GINT64_FORMAT, diff_loop); + + /* orc mul */ + start_ts = g_get_real_time (); + nns_orc_mul_c_u8 (data_u8, 2, array_size); + stop_ts = g_get_real_time (); + + diff_orc = stop_ts - start_ts; + _print_log ("mul u8 orc: %" G_GINT64_FORMAT, diff_orc); + + for (i = 0; i < array_size; ++i) { + EXPECT_EQ (data_u8[i], 8); + } + + /* loop */ + start_ts = g_get_real_time (); + for (i = 0; i < array_size; ++i) { + data_u8[i] *= 2; + } + stop_ts = g_get_real_time (); + + diff_loop = stop_ts - start_ts; + _print_log ("mul u8 loop: %" G_GINT64_FORMAT, diff_loop); + + /* orc typecast to float */ + start_ts = g_get_real_time (); + nns_orc_conv_u8_to_f32 (data_float, data_u8, array_size); + stop_ts = g_get_real_time (); + + diff_orc = stop_ts - start_ts; + _print_log ("conv u8 orc: %" G_GINT64_FORMAT, diff_orc); + + for (i = 0; i < array_size; ++i) { + EXPECT_FLOAT_EQ (data_float[i], 16.); + } + + /* loop */ + start_ts = g_get_real_time (); + for (i = 0; i < array_size; ++i) { + data_float[i] = (float) data_u8[i]; + } + stop_ts = g_get_real_time (); + + diff_loop = stop_ts - start_ts; + _print_log ("conv u8 loop: %" G_GINT64_FORMAT, diff_loop); + + /* init data */ + for (i = 0; i < array_size; ++i) { + data_u8[i] = 1; + } + + /* orc typecast - add - mul */ + start_ts = g_get_real_time (); + nns_orc_conv_u8_to_f32 (data_float, data_u8, array_size); + nns_orc_add_c_f32 (data_float, .2, array_size); + nns_orc_mul_c_f32 (data_float, 1.2, array_size); + stop_ts = g_get_real_time (); + + diff_orc = stop_ts - start_ts; + _print_log ("combined u8 orc: %" G_GINT64_FORMAT, diff_orc); + + for (i = 0; i < array_size; ++i) { + EXPECT_FLOAT_EQ (data_float[i], (1 + .2) * 1.2); + } + + /* loop */ + start_ts = g_get_real_time (); + for (i = 0; i < array_size; ++i) { + data_float[i] = (float) data_u8[i]; + data_float[i] += .2; + data_float[i] *= 1.2; + } + stop_ts = g_get_real_time (); + + diff_loop = stop_ts - start_ts; + _print_log ("combined u8 loop: %" G_GINT64_FORMAT, diff_loop); + + g_free (data_u8); + g_free (data_float); +} #endif /* HAVE_ORC */ /**