diff --git a/hipamd/CMakeLists.txt b/hipamd/CMakeLists.txt index 5508c902ae..7f80325779 100644 --- a/hipamd/CMakeLists.txt +++ b/hipamd/CMakeLists.txt @@ -126,6 +126,7 @@ if(HIP_PLATFORM STREQUAL "hcc") src/hip_memory.cpp src/hip_peer.cpp src/hip_stream.cpp + src/hip_fp16.cpp src/staging_buffer.cpp) if(${HIP_USE_SHARED_LIBRARY} EQUAL 1) diff --git a/hipamd/bin/hipcc b/hipamd/bin/hipcc index 9c7e23d0e7..2c95a21a99 100755 --- a/hipamd/bin/hipcc +++ b/hipamd/bin/hipcc @@ -222,7 +222,7 @@ if ($needHipHcc) { if ($HIP_USE_SHARED_LIBRARY) { $HIPLDFLAGS .= " -L$HIP_PATH/lib -Wl,--rpath=$HIP_PATH/lib -lhip_hcc"; } else { - $HIPLDFLAGS .= " $HIP_PATH/lib/device_util.cpp.o $HIP_PATH/lib/hip_device.cpp.o $HIP_PATH/lib/hip_error.cpp.o $HIP_PATH/lib/hip_event.cpp.o $HIP_PATH/lib/hip_hcc.cpp.o $HIP_PATH/lib/hip_memory.cpp.o $HIP_PATH/lib/hip_peer.cpp.o $HIP_PATH/lib/hip_stream.cpp.o $HIP_PATH/lib/staging_buffer.cpp.o $HIP_PATH/lib/hip_ldg.cpp.o"; + $HIPLDFLAGS .= " $HIP_PATH/lib/device_util.cpp.o $HIP_PATH/lib/hip_device.cpp.o $HIP_PATH/lib/hip_error.cpp.o $HIP_PATH/lib/hip_event.cpp.o $HIP_PATH/lib/hip_hcc.cpp.o $HIP_PATH/lib/hip_memory.cpp.o $HIP_PATH/lib/hip_peer.cpp.o $HIP_PATH/lib/hip_stream.cpp.o $HIP_PATH/lib/staging_buffer.cpp.o $HIP_PATH/lib/hip_ldg.cpp.o $HIP_PATH/lib/hip_fp16.cpp.o"; } } diff --git a/hipamd/include/hcc_detail/hip_fp16.h b/hipamd/include/hcc_detail/hip_fp16.h new file mode 100644 index 0000000000..f6d3f2311a --- /dev/null +++ b/hipamd/include/hcc_detail/hip_fp16.h @@ -0,0 +1,181 @@ +/* +Copyright (c) 2015-2016 Advanced Micro Devices, Inc. All rights reserved. +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANNTY OF ANY KIND, EXPRESS OR +IMPLIED, INNCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANNY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER INN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR INN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + +#ifndef HIP_FP16_H +#define HIP_FP16_H + +#include "hip_runtime.h" + +typedef struct{ + unsigned x: 16; +} __half; + + +typedef struct __attribute__((aligned(4))){ + __half p,q; +} __half2; + +typedef __half half; +typedef __half2 half2; + +typedef struct{ + union{ + float f; + unsigned u; + }; +} struct_float; + +/* +Arithmetic functions +*/ + +__device__ __half __hadd(const __half a, const __half b); + +__device__ __half __hadd_sat(const __half a, const __half b); + +__device__ __half __hfma(const __half a, const __half b, const __half c); + +__device__ __half __hfma_sat(const __half a, const __half b, const __half c); + +__device__ __half __hmul(const __half a, const __half b); + +__device__ __half __hmul_sat(const __half a, const __half b); + +__device__ __half __hneq(const __half a); + +__device__ __half __hsub(const __half a, const __half b); + +__device__ __half __hsub_sat(const __half a, const __half b); + + + +/* +Half2 Arithmetic Instructions +*/ + +__device__ __half2 __hadd2(const __half2 a, const __half2 b); + +__device__ __half2 __hadd2_sat(const __half2 a, const __half2 b); + +__device__ __half2 __hfma2(const __half2 a, const __half2 b, const __half2 c); + +__device__ __half2 __hfma2_sat(const __half2 a, const __half2 b, const __half2 c); + +__device__ __half2 __hmul2(const __half2 a, const __half2 b); + +__device__ __half2 __hmul2_sat(const __half2 a, const __half2 b); + +__device__ __half2 __hneq2(const __half2 a); + +__device__ __half2 __hsub2(const __half2 a, const __half2 b); + +__device__ __half2 __hsub2_sat(const __half2 a, const __half2 b); + +/* +Half Cmps +*/ + +__device__ bool __heq(const __half a, const __half b); + +__device__ bool __hge(const __half a, const __half b); + +__device__ bool __hgt(const __half a, const __half b); + +__device__ bool __hisinf(const __half a); + +__device__ bool __hisnan(const __half a); + +__device__ bool __hle(const __half a, const __half b); + +__device__ bool __hlt(const __half a, const __half b); + +__device__ bool __hne(const __half a, const __half b); + +/* +Half2 Cmps +*/ + +__device__ bool __hbeq2(const __half2 a, const __half2 b); + +__device__ bool __hbge2(const __half2 a, const __half2 b); + +__device__ bool __hbgt2(const __half2 a, const __half2 b); + +__device__ bool __hble2(const __half2 a, const __half2 b); + +__device__ bool __hblt2(const __half2 a, const __half2 b); + +__device__ bool __hbne2(const __half2 a, const __half2 b); + +__device__ __half2 __heq2(const __half2 a, const __half2 b); + +__device__ __half2 __hge2(const __half2 a, const __half2 b); + +__device__ __half2 __hgt2(const __half2 a, const __half2 b); + +__device__ __half2 __hisnan2(const __half2 a); + +__device__ __half2 __hle2(const __half2 a, const __half2 b); + +__device__ __half2 __hlt2(const __half2 a, const __half2 b); + +__device__ __half2 __hne2(const __half2 a, const __half2 b); + + +/* +Half Cnvs and Data Mvmnt +*/ + +__device__ __half2 __float22half2_rn(const float2 a); + +__device__ __half __float2half(const float a); + +__device__ __half2 __float2half2_rn(const float a); + +__device__ __half2 __floats2half2_rn(const float a, const float b); + +__device__ float2 __half22float2(const __half2 a); + +__device__ float __half2float(const __half a); + +__device__ __half2 __half2half2(const __half a); + +__device__ __half2 __halves2half2(const __half a, const __half b); + +__device__ float __high2float(const __half2 a); + +__device__ __half __high2half(const __half2 a); + +__device__ __half2 __high2half2(const __half2 a); + +__device__ __half2 __highs2half2(const __half2 a, const __half2 b); + +__device__ float __low2float(const __half2 a); + +__device__ __half __low2half(const __half2 a); + +__device__ __half2 __low2half2(const __half2 a); + +__device__ __half2 __lows2half2(const __half2 a, const __half2 b); + +__device__ __half2 __lowhigh2highlow(const __half2 a); + +__device__ __half2 __low2half2(const __half2 a, const __half2 b); + +#endif diff --git a/hipamd/include/hip_fp16.h b/hipamd/include/hip_fp16.h new file mode 100644 index 0000000000..6df481270b --- /dev/null +++ b/hipamd/include/hip_fp16.h @@ -0,0 +1,30 @@ +/* +Copyright (c) 2015-2016 Advanced Micro Devices, Inc. All rights reserved. +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANNTY OF ANY KIND, EXPRESS OR +IMPLIED, INNCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANNY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER INN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR INN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + +#pragma once + +#include + +#if defined(__HIP_PLATFORM_HCC__) && !defined (__HIP_PLATFORM_NVCC__) +#include +#elif defined(__HIP_PLATFORM_NVCC__) && !defined (__HIP_PLATFORM_HCC__) +#include "cuda_fp16.h" +#else +#error("Must define exactly one of __HIP_PLATFORM_HCC__ or __HIP_PLATFORM_NVCC__"); +#endif diff --git a/hipamd/src/hip_fp16.cpp b/hipamd/src/hip_fp16.cpp new file mode 100644 index 0000000000..5b179b9ba5 --- /dev/null +++ b/hipamd/src/hip_fp16.cpp @@ -0,0 +1,365 @@ +/* +Copyright (c) 2015-2016 Advanced Micro Devices, Inc. All rights reserved. +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANNTY OF ANY KIND, EXPRESS OR +IMPLIED, INNCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANNY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER INN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR INN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + +#include"hip/hip_fp16.h" + +static const unsigned sign_val = 0x8000; +static const __half __half_value_one_float = {0x3C00}; +static const __half __half_value_zero_float = {0x0}; +static const unsigned __half_pos_inf = 0x7C00; +static const unsigned __half_neg_inf = 0xFC00; + +static __device__ float cvt_half_to_float(__half a){ + struct_float ret = {0}; + if(a.x == 0){ + return 0.0f; + } + if(a.x == 0x8000){ + return -0.0f; + } + ret.u = ((a.x&0x8000)<<16) | (((a.x&0x7c00)+0x1C000)<<13) | ((a.x&0x03FF)<<13); + return ret.f; +} + +static __device__ __half cvt_float_to_half(float b){ + struct_float f = {0}; + __half ret = {0}; + f.f = b; + if(f.f == 0.0f){ + ret.x = 0; + return ret; + } + if(f.f == -0.0f){ + ret.x = 0x8000; + return ret; + } + ret.x = ((f.u>>16)&0x8000)|((((f.u&0x7f800000)-0x38000000)>>13)&0x7c00)|((f.u>>13)&0x03ff); + return ret; +} + + +__device__ __half __hadd(const __half a, const __half b){ + return cvt_float_to_half(cvt_half_to_float(a)+cvt_half_to_float(b)); +} + +__device__ __half __hadd_sat(const __half a, const __half b){ + float f = cvt_half_to_float(a) + cvt_half_to_float(b); + return (f < 0.0f ? __half_value_zero_float : (f > 1.0f ? __half_value_one_float: cvt_float_to_half(f))); +} + +__device__ __half __hfma(const __half a, const __half b, const __half c){ + return cvt_float_to_half(fmaf(cvt_half_to_float(a), cvt_half_to_float(b), cvt_half_to_float(c))); +} + +__device__ __half __hfma_sat(const __half a, const __half b, const __half c){ + float f = fmaf(cvt_half_to_float(a), cvt_half_to_float(b), cvt_half_to_float(c)); + return (f < 0.0f ? __half_value_zero_float : (f > 1.0f ? __half_value_one_float: cvt_float_to_half(f))); +} + +__device__ __half __hmul(const __half a, const __half b){ + return cvt_float_to_half(cvt_half_to_float(a)*cvt_half_to_float(b)); +} + +__device__ __half __hmul_sat(const __half a, const __half b){ + float f = cvt_half_to_float(a) * cvt_half_to_float(b); + return (f < 0.0f ? __half_value_zero_float : (f > 1.0f ? __half_value_one_float: cvt_float_to_half(f))); +} + +__device__ __half __hneq(const __half a){ + __half ret = {a.x}; + ret.x ^= 1 << 15; + return ret; +} + +__device__ __half __hsub(const __half a, const __half b){ + return cvt_float_to_half(cvt_half_to_float(a)-cvt_half_to_float(b)); +} + +__device__ __half __hsub_sat(const __half a, const __half b){ + float f = cvt_half_to_float(a) - cvt_half_to_float(b); + return (f < 0.0f ? __half_value_zero_float : (f > 1.0f ? __half_value_one_float: cvt_float_to_half(f))); +} + + +/* +Half2 Arithmetic Instructions +*/ + +__device__ __half2 __hadd2(const __half2 a, const __half2 b){ + __half2 ret; + ret.p = __hadd(a.p, b.p); + ret.q = __hadd(a.q, b.q); + return ret; +} + +__device__ __half2 __hadd2_sat(const __half2 a, const __half2 b){ + __half2 ret; + ret.p = __hadd_sat(a.p, b.p); + ret.q = __hadd_sat(a.q, b.q); + return ret; +} + +__device__ __half2 __hfma2(const __half2 a, const __half2 b, const __half2 c){ + __half2 ret; + ret.p = __hfma(a.p, b.p, c.p); + ret.q = __hfma(a.q, b.q, c.q); + return ret; +} + +__device__ __half2 __hfma2_sat(const __half2 a, const __half2 b, const __half2 c){ + __half2 ret; + ret.p = __hfma_sat(a.p, b.p, c.p); + ret.q = __hfma_sat(a.q, b.q, c.q); + return ret; +} + +__device__ __half2 __hmul2(const __half2 a, const __half2 b){ + __half2 ret; + ret.p = __hmul(a.p, b.p); + ret.q = __hmul(a.q, b.q); + return ret; +} + +__device__ __half2 __hmul2_sat(const __half2 a, const __half2 b){ + __half2 ret; + ret.p = __hmul_sat(a.p, b.p); + ret.q = __hmul_sat(a.q, b.q); + return ret; +} + +__device__ __half2 __hneq2(const __half2 a){ + __half2 ret; + ret.p = __hneq(a.p); + ret.q = __hneq(a.q); + return ret; +} + +__device__ __half2 __hsub2(const __half2 a, const __half2 b){ + __half2 ret; + ret.p = __hsub(a.p, b.p); + ret.q = __hsub(a.q, b.q); + return ret; +} + +__device__ __half2 __hsub2_sat(const __half2 a, const __half2 b){ + __half2 ret; + ret.p = __hsub_sat(a.p, b.p); + ret.q = __hsub_sat(a.q, b.q); + return ret; +} + +/* +Half Cmps +*/ + +__device__ bool __heq(const __half a, const __half b){ + return (a.x == b.x ? true:false); +} + +__device__ bool __hge(const __half a, const __half b){ + return (cvt_half_to_float(a) >= cvt_half_to_float(b)); +} + +__device__ bool __hgt(const __half a, const __half b){ + return (cvt_half_to_float(a) > cvt_half_to_float(b)); +} + +__device__ bool __hisinf(const __half a){ + return ((a.x == __half_neg_inf) ? -1 : (a.x == __half_pos_inf) ? 1 : 0); +} + +__device__ bool __hisnan(const __half a){ + if(((a.x & __half_pos_inf) == a.x) || ((a.x & __half_neg_inf) == a.x)){ + return true; + }else{ + return false; + } +} + +__device__ bool __hle(const __half a, const __half b){ + return (cvt_half_to_float(a) <= cvt_half_to_float(b)); +} + +__device__ bool __hlt(const __half a, const __half b){ + return (cvt_half_to_float(a) < cvt_half_to_float(b)); +} + +__device__ bool __hne(const __half a, const __half b){ + return a.x == b.x ? false : true; +} + +/* +Half2 Cmps +*/ + +__device__ bool __hbeq2(const __half2 a, const __half2 b){ + return __heq(a.p, b.p) && __heq(a.q, b.q); +} + +__device__ bool __hbge2(const __half2 a, const __half2 b){ + return __hge(a.p, b.p) && __hge(a.q, b.q); +} + +__device__ bool __hbgt2(const __half2 a, const __half2 b){ + return __hgt(a.p, b.p) && __hgt(a.q, b.q); +} + +__device__ bool __hble2(const __half2 a, const __half2 b){ + return __hle(a.p, b.p) && __hle(a.q, b.q); +} + +__device__ bool __hblt2(const __half2 a, const __half2 b){ + return __hlt(a.p, b.p) && __hlt(a.q, b.q); +} + +__device__ bool __hbne2(const __half2 a, const __half2 b){ + return __hne(a.p, b.p) && __hne(a.q, b.q); +} + + + +__device__ __half2 __heq2(const __half2 a, const __half2 b){ + __half2 ret = {0}; + ret.p = (__heq(a.p, b.p)) ? __half_value_one_float : __half_value_zero_float; + ret.q = (__heq(a.q, b.q)) ? __half_value_one_float : __half_value_zero_float; + return ret; +} + +__device__ __half2 __hge2(const __half2 a, const __half2 b){ + __half2 ret = {0}; + ret.p = (__hge(a.p, b.p)) ? __half_value_one_float : __half_value_zero_float; + ret.q = (__hge(a.q, b.q)) ? __half_value_one_float : __half_value_zero_float; + return ret; +} + +__device__ __half2 __hgt2(const __half2 a, const __half2 b){ + __half2 ret = {0}; + ret.p = (__hgt(a.p, b.p)) ? __half_value_one_float : __half_value_zero_float; + ret.q = (__hgt(a.q, b.q)) ? __half_value_one_float : __half_value_zero_float; + return ret; +} + +__device__ __half2 __hisnan2(const __half2 a){ + __half2 ret = {0}; + ret.p = __hisnan(a.p) ? __half_value_one_float : __half_value_zero_float; + ret.q = __hisnan(a.q) ? __half_value_one_float : __half_value_zero_float; + return ret; +} + +__device__ __half2 __hle2(const __half2 a, const __half2 b){ + __half2 ret = {0}; + ret.p = (__hle(a.p, b.p)) ? __half_value_one_float : __half_value_zero_float; + ret.q = (__hle(a.q, b.q)) ? __half_value_one_float : __half_value_zero_float; + return ret; +} + +__device__ __half2 __hlt2(const __half2 a, const __half2 b){ + __half2 ret = {0}; + ret.p = (__hlt(a.p, b.p)) ? __half_value_one_float : __half_value_zero_float; + ret.q = (__hlt(a.q, b.q)) ? __half_value_one_float : __half_value_zero_float; + return ret; +} + +__device__ __half2 __hne2(const __half2 a, const __half2 b){ + __half2 ret = {0}; + ret.p = (__hne(a.p, b.p)) ? __half_value_one_float : __half_value_zero_float; + ret.q = (__hne(a.q, b.q)) ? __half_value_one_float : __half_value_zero_float; + return ret; +} + +/* +Half Cnvs and Data Mvmnt +*/ + +__device__ __half2 __float22half2_rn(const float2 a){ + __half2 ret = {0}; + ret.p = cvt_float_to_half(a.x); + ret.q = cvt_float_to_half(a.y); + return ret; +} + +__device__ __half __float2half(const float a){ + return cvt_float_to_half(a); +} + +__device__ __half2 __float2half2_rn(const float a){ + __half ret = cvt_float_to_half(a); + return {ret, ret}; +} + +__device__ __half2 __floats2half2_rn(const float a, const float b){ + return {cvt_float_to_half(a), cvt_float_to_half(b)}; +} + +__device__ float2 __half22float2(const __half2 a){ + return {cvt_half_to_float(a.p), cvt_half_to_float(a.q)}; +} + +__device__ float __half2float(const __half a){ + return cvt_half_to_float(a); +} + +__device__ __half2 __half2half2(const __half a){ + return {a,a}; +} + +__device__ __half2 __halves2half2(const __half a, const __half b){ + return {a,b}; +} + +__device__ float __high2float(const __half2 a){ + return cvt_half_to_float(a.p); +} + +__device__ __half __high2half(const __half2 a){ + return a.p; +} + +__device__ __half2 __high2half2(const __half2 a){ + return {a.p, a.p}; +} + +__device__ __half2 __highs2half2(const __half2 a, const __half2 b){ + return {a.p, b.p}; +} + +__device__ float __low2float(const __half2 a){ + return cvt_half_to_float(a.q); +} + +__device__ __half __low2half(const __half2 a){ + return a.q; +} + +__device__ __half2 __low2half2(const __half2 a){ + return {a.q, a.q}; +} + +__device__ __half2 __lows2half2(const __half2 a, const __half2 b){ + return {a.q, b.q}; +} + +__device__ __half2 __lowhigh2highlow(const __half2 a){ + return {a.q, a.p}; +} + +__device__ __half2 __low2half2(const __half2 a, const __half2 b){ + return {a.q, b.q}; +} + diff --git a/hipamd/src/hip_hcc.cpp b/hipamd/src/hip_hcc.cpp index 75cbb7172c..a80db8fd2e 100644 --- a/hipamd/src/hip_hcc.cpp +++ b/hipamd/src/hip_hcc.cpp @@ -1403,7 +1403,7 @@ void ihipStream_t::copySync(LockedAccessor_StreamCrit_t &crit, void* dst, const void *devPtrSrc = srcPtrInfo._devicePointer; tprintf(DB_COPY1, "HSA Async_copy dst=%p src=%p sz=%zu\n", dst, src, sizeBytes); - hsa_status_t hsa_status = hsa_amd_memory_async_copy(dst, dstAgent, devPtrSrc, srcAgent, sizeBytes, depSignalCnt, depSignalCnt ? &depSignal:0x0, copyCompleteSignal); + hsa_status_t hsa_status = hsa_amd_memory_async_copy(dst, dstAgent, devPtrSrc, g_cpu_agent, sizeBytes, depSignalCnt, depSignalCnt ? &depSignal:0x0, copyCompleteSignal); // This is sync copy, so let's wait for copy right here: if (hsa_status == HSA_STATUS_SUCCESS) { @@ -1443,7 +1443,7 @@ void ihipStream_t::copySync(LockedAccessor_StreamCrit_t &crit, void* dst, const void *devPtrDst = dstPtrInfo._devicePointer; tprintf(DB_COPY1, "HSA Async_copy dst=%p src=%p sz=%zu\n", dst, src, sizeBytes); - hsa_status_t hsa_status = hsa_amd_memory_async_copy(devPtrDst, dstAgent, src, srcAgent, sizeBytes, depSignalCnt, depSignalCnt ? &depSignal:0x0, copyCompleteSignal); + hsa_status_t hsa_status = hsa_amd_memory_async_copy(devPtrDst, g_cpu_agent, src, srcAgent, sizeBytes, depSignalCnt, depSignalCnt ? &depSignal:0x0, copyCompleteSignal); // This is sync copy, so let's wait for copy right here: if (hsa_status == HSA_STATUS_SUCCESS) { diff --git a/hipamd/tests/src/hipTestHalf.cpp b/hipamd/tests/src/hipTestHalf.cpp new file mode 100644 index 0000000000..249a6cbce2 --- /dev/null +++ b/hipamd/tests/src/hipTestHalf.cpp @@ -0,0 +1,56 @@ +/* +Copyright (c) 2015-2016 Advanced Micro Devices, Inc. All rights reserved. +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + +#include +#include +#include "hip_runtime_api.h" + +#define DSIZE 4 +#define SCF 0.5f +#define nTPB 256 +__global__ void half_scale_kernel(hipLaunchParm lp, float *din, float *dout, int dsize){ + + int idx = hipThreadIdx_x+ hipBlockDim_x*hipBlockIdx_x; + if (idx < dsize){ + __half scf = __float2half(SCF); + __half kin = __float2half(din[idx]); + __half kout; + + kout = __hmul(kin, scf); + +// kout = cvt_float_to_half(cvt_half_to_float(kin)*cvt_half_to_float(scf)); + + dout[idx] = __half2float(kout); + } +} + +int main(){ + + float *hin, *hout, *din, *dout; + hin = (float *)malloc(DSIZE*sizeof(float)); + hout = (float *)malloc(DSIZE*sizeof(float)); + for (int i = 0; i < DSIZE; i++) hin[i] = i; + hipMalloc(&din, DSIZE*sizeof(float)); + hipMalloc(&dout, DSIZE*sizeof(float)); + hipMemcpy(din, hin, DSIZE*sizeof(float), hipMemcpyHostToDevice); + hipLaunchKernel(half_scale_kernel, dim3((DSIZE+nTPB-1)/nTPB),dim3(nTPB), 0, 0, din, dout, DSIZE); + hipMemcpy(hout, dout, DSIZE*sizeof(float), hipMemcpyDeviceToHost); + for (int i = 0; i < DSIZE; i++) printf("%f\n", hout[i]); + return 0; +}