From 849395ec02a35afd3eab1f291a3dc1f795ff0fe7 Mon Sep 17 00:00:00 2001 From: Ben Sander Date: Mon, 21 Mar 2016 09:33:32 -0500 Subject: [PATCH 1/9] fix nvcc for hipHostMalloc* flags. [ROCm/clr commit: d495ffb1d3612971f390cf53380b36b096e3f54b] --- projects/clr/hipamd/include/nvcc_detail/hip_runtime_api.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/projects/clr/hipamd/include/nvcc_detail/hip_runtime_api.h b/projects/clr/hipamd/include/nvcc_detail/hip_runtime_api.h index edf2568687..89b5a2dfee 100644 --- a/projects/clr/hipamd/include/nvcc_detail/hip_runtime_api.h +++ b/projects/clr/hipamd/include/nvcc_detail/hip_runtime_api.h @@ -50,10 +50,10 @@ hipMemcpyHostToHost } hipTextureFilterMode;*/ #define hipFilterModePoint cudaFilterModePoint -#define hipHostAllocDefault cudaHostAllocDefault -#define hipHostAllocPortable cudaHostAllocPortable -#define hipHostAllocMapped cudaHostAllocMapped -#define hipHostAllocWriteCombined cudaHostAllocWriteCombined +#define hipHostMallocDefault cudaHostAllocDefault +#define hipHostMallocPortable cudaHostAllocPortable +#define hipHostMallocMapped cudaHostAllocMapped +#define hipHostMallocWriteCombined cudaHostAllocWriteCombined #define hipHostRegisterPortable cudaHostRegisterPortable #define hipHostRegisterMapped cudaHostRegisterMapped From 0a91b906f1eebe713b761225aca2dd59c0e2cc61 Mon Sep 17 00:00:00 2001 From: Aditya Atluri Date: Mon, 21 Mar 2016 14:42:23 -0500 Subject: [PATCH 2/9] Disabling default-stream per-thread tests [ROCm/clr commit: 93e6362104c0237903a5fc64f7b399cf63ffd4a2] --- projects/clr/hipamd/tests/src/CMakeLists.txt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/projects/clr/hipamd/tests/src/CMakeLists.txt b/projects/clr/hipamd/tests/src/CMakeLists.txt index 84b1dfee0b..bbbb3c52ed 100644 --- a/projects/clr/hipamd/tests/src/CMakeLists.txt +++ b/projects/clr/hipamd/tests/src/CMakeLists.txt @@ -109,8 +109,8 @@ macro (make_test_matches exe match_string) ) endmacro() -make_hip_executable (hipAPIStreamEnable hipAPIStreamEnable.cpp) -make_hip_executable (hipAPIStreamDisable hipAPIStreamDisable.cpp) +#make_hip_executable (hipAPIStreamEnable hipAPIStreamEnable.cpp) +#make_hip_executable (hipAPIStreamDisable hipAPIStreamDisable.cpp) make_hip_executable (hip_ballot hip_ballot.cpp) make_hip_executable (hip_anyall hip_anyall.cpp) make_hip_executable (hip_popc hip_popc.cpp) @@ -168,6 +168,6 @@ make_test(hipHcc " " ) make_test(hipHostRegister " ") make_test(hipStreamL5 " ") make_test(hipRandomMemcpyAsync " ") -make_test(hipAPIStreamEnable " ") -make_test(hipAPIStreamDisable " ") +#make_test(hipAPIStreamEnable " ") +#make_test(hipAPIStreamDisable " ") make_hipify_test(specialFunc.cu ) From 805dbd6d90bf9494164bf72f2d05b03576b20786 Mon Sep 17 00:00:00 2001 From: Aditya Atluri Date: Mon, 21 Mar 2016 10:32:30 -0500 Subject: [PATCH 3/9] fixed memory free apis [ROCm/clr commit: 71a6b5cb6c5413cf0141f2063813369523b6a9eb] --- .../include/hcc_detail/hip_runtime_api.h | 4 +- projects/clr/hipamd/include/hip_runtime_api.h | 2 + projects/clr/hipamd/src/hip_hcc.cpp | 27 ++++++++-- projects/clr/hipamd/tests/src/CMakeLists.txt | 4 ++ .../hipamd/tests/src/hipMemoryAllocate.cpp | 51 +++++++++++++++++++ 5 files changed, 81 insertions(+), 7 deletions(-) create mode 100644 projects/clr/hipamd/tests/src/hipMemoryAllocate.cpp diff --git a/projects/clr/hipamd/include/hcc_detail/hip_runtime_api.h b/projects/clr/hipamd/include/hcc_detail/hip_runtime_api.h index ef5ad4927c..4c854e72f1 100644 --- a/projects/clr/hipamd/include/hcc_detail/hip_runtime_api.h +++ b/projects/clr/hipamd/include/hcc_detail/hip_runtime_api.h @@ -688,10 +688,10 @@ hipError_t hipHostAlloc(void** ptr, size_t size, unsigned int flags) __attribute * * @param[out] dstPtr Device Pointer mapped to passed host pointer * @param[in] hstPtr Host Pointer allocated through hipHostAlloc - * @param[in] size Requested memory size + * @param[in] flags Flags to be passed for extension * @return Error code */ -hipError_t hipHostGetDevicePointer(void** devPtr, void* hstPtr, size_t size) ; +hipError_t hipHostGetDevicePointer(void** devPtr, void* hstPtr, unsigned int flags) ; /** * @brief Get flags associated with host pointer diff --git a/projects/clr/hipamd/include/hip_runtime_api.h b/projects/clr/hipamd/include/hip_runtime_api.h index c7d9f3fa8b..3a0a4b399a 100644 --- a/projects/clr/hipamd/include/hip_runtime_api.h +++ b/projects/clr/hipamd/include/hip_runtime_api.h @@ -149,6 +149,8 @@ typedef enum hipError_t { ,hipErrorInvalidResourceHandle ///< Resource handle (hipEvent_t or hipStream_t) invalid. ,hipErrorInvalidDevice ///< DeviceID must be in range 0...#compute-devices. ,hipErrorInvalidMemcpyDirection ///< Invalid memory copy direction + ,hipErrorInvalidDevicePointer ///< Invalid Device Pointer + ,hipErrorInitializationError ///< TODO comment from hipErrorInitializationError ,hipErrorNoDevice ///< Call to hipGetDeviceCount returned 0 devices ,hipErrorNotReady ///< Indicates that asynchronous operations enqueued earlier are not ready. This is not actually an error, but is used to distinguish from hipSuccess (which indicates completion). APIs that return this error include hipEventQuery and hipStreamQuery. diff --git a/projects/clr/hipamd/src/hip_hcc.cpp b/projects/clr/hipamd/src/hip_hcc.cpp index 7aa7ae4482..23481e27b3 100644 --- a/projects/clr/hipamd/src/hip_hcc.cpp +++ b/projects/clr/hipamd/src/hip_hcc.cpp @@ -2603,15 +2603,24 @@ hipError_t hipFree(void* ptr) // TODO - ensure this pointer was created by hipMalloc and not hipMallocHost std::call_once(hip_initialized, ihipInit); + hipError_t hipStatus = hipErrorInvalidDevicePointer; // Synchronize to ensure all work has finished. ihipGetTlsDefaultDevice()->waitAllStreams(); // ignores non-blocking streams, this waits for all activity to finish. if (ptr) { - hc::am_free(ptr); + hc::accelerator acc; + hc::AmPointerInfo amPointerInfo(NULL, NULL, 0, acc, 0, 0); + am_status_t status = hc::am_memtracker_getinfo(&amPointerInfo, ptr); + if(status == AM_SUCCESS){ + if(amPointerInfo._hostPointer == NULL){ + hc::am_free(ptr); + hipStatus = hipSuccess; + } + } } - return ihipLogStatus(hipSuccess); + return ihipLogStatus(hipStatus); } @@ -2620,12 +2629,20 @@ hipError_t hipHostFree(void* ptr) // TODO - ensure this pointer was created by hipMallocHost and not hipMalloc std::call_once(hip_initialized, ihipInit); + hipError_t hipStatus = hipErrorInvalidDevicePointer; if (ptr) { - tprintf (DB_MEM, " %s: %p\n", __func__, ptr); - hc::am_free(ptr); + hc::accelerator acc; + hc::AmPointerInfo amPointerInfo(NULL, NULL, 0, acc, 0, 0); + am_status_t status = hc::am_memtracker_getinfo(&amPointerInfo, ptr); + if(status == AM_SUCCESS){ + if(amPointerInfo._hostPointer == ptr){ + hc::am_free(ptr); + hipStatus = hipSuccess; + } + } } - return ihipLogStatus(hipSuccess); + return ihipLogStatus(hipStatus); }; diff --git a/projects/clr/hipamd/tests/src/CMakeLists.txt b/projects/clr/hipamd/tests/src/CMakeLists.txt index bbbb3c52ed..ab9c41d545 100644 --- a/projects/clr/hipamd/tests/src/CMakeLists.txt +++ b/projects/clr/hipamd/tests/src/CMakeLists.txt @@ -140,6 +140,8 @@ make_hip_executable (hipStreamL5 hipStreamL5.cpp) make_hip_executable (hipHostGetFlags hipHostGetFlags.cpp) make_hip_executable (hipHostRegister hipHostRegister.cpp) make_hip_executable (hipRandomMemcpyAsync hipRandomMemcpyAsync.cpp) +make_hip_executable (hipMemoryAllocate hipMemoryAllocate.cpp) + make_test(hip_ballot " " ) make_test(hip_anyall " " ) make_test(hip_popc " " ) @@ -170,4 +172,6 @@ make_test(hipStreamL5 " ") make_test(hipRandomMemcpyAsync " ") #make_test(hipAPIStreamEnable " ") #make_test(hipAPIStreamDisable " ") +make_test(hipMemoryAllocate " ") + make_hipify_test(specialFunc.cu ) diff --git a/projects/clr/hipamd/tests/src/hipMemoryAllocate.cpp b/projects/clr/hipamd/tests/src/hipMemoryAllocate.cpp new file mode 100644 index 0000000000..30da822eaf --- /dev/null +++ b/projects/clr/hipamd/tests/src/hipMemoryAllocate.cpp @@ -0,0 +1,51 @@ +/* +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"test_common.h" + +#define SIZE 1024*1024*256 + +int main(){ + float *Ad, *B, *Bd, *Bm, *C, *Cd; + B = (float*)malloc(SIZE); + hipMalloc((void**)&Ad, SIZE); + hipHostMalloc((void**)&B, SIZE); + hipHostMalloc((void**)&Bd, SIZE, hipHostMallocDefault); + hipHostMalloc((void**)&Bm, SIZE, hipHostMallocMapped); + hipHostMalloc((void**)&C, SIZE, hipHostMallocMapped); + hipHostGetDevicePointer((void**)&Cd, C, SIZE); + + HIPASSERT(hipFree(Ad) == hipSuccess); + HIPASSERT(hipHostFree(Ad) == hipErrorInvalidDevicePointer); + + HIPASSERT(hipFree(B) == hipErrorInvalidDevicePointer); + HIPASSERT(hipFree(Bd) == hipErrorInvalidDevicePointer); + HIPASSERT(hipFree(Bm) == hipErrorInvalidDevicePointer); + HIPASSERT(hipHostFree(Bd) == hipSuccess); + HIPASSERT(hipHostFree(Bm) == hipSuccess); + + HIPASSERT(hipFree(C) == hipErrorInvalidDevicePointer); + HIPASSERT(hipFree(Cd) == hipErrorInvalidDevicePointer); + HIPASSERT(hipHostFree(C) == hipSuccess); + HIPASSERT(hipHostFree(Cd) == hipErrorInvalidDevicePointer); + HIPASSERT(hipFree(Cd) == hipErrorInvalidDevicePointer); + + HIPASSERT(hipFree(NULL) == hipErrorInvalidDevicePointer); + HIPASSERT(hipHostFree(NULL) == hipErrorInvalidDevicePointer); + passed(); +} From 70d2a03efdd5ada58b3951ed0ecc16e261e5384c Mon Sep 17 00:00:00 2001 From: Aditya Atluri Date: Mon, 21 Mar 2016 10:36:11 -0500 Subject: [PATCH 4/9] Revert "fixed memory free apis" This reverts commit 805dbd6d90bf9494164bf72f2d05b03576b20786. [ROCm/clr commit: 1fa4d0d4b9e112c56ab166b0c3d670305343f016] --- .../include/hcc_detail/hip_runtime_api.h | 4 +- projects/clr/hipamd/include/hip_runtime_api.h | 2 - projects/clr/hipamd/src/hip_hcc.cpp | 27 ++-------- projects/clr/hipamd/tests/src/CMakeLists.txt | 4 -- .../hipamd/tests/src/hipMemoryAllocate.cpp | 51 ------------------- 5 files changed, 7 insertions(+), 81 deletions(-) delete mode 100644 projects/clr/hipamd/tests/src/hipMemoryAllocate.cpp diff --git a/projects/clr/hipamd/include/hcc_detail/hip_runtime_api.h b/projects/clr/hipamd/include/hcc_detail/hip_runtime_api.h index 4c854e72f1..ef5ad4927c 100644 --- a/projects/clr/hipamd/include/hcc_detail/hip_runtime_api.h +++ b/projects/clr/hipamd/include/hcc_detail/hip_runtime_api.h @@ -688,10 +688,10 @@ hipError_t hipHostAlloc(void** ptr, size_t size, unsigned int flags) __attribute * * @param[out] dstPtr Device Pointer mapped to passed host pointer * @param[in] hstPtr Host Pointer allocated through hipHostAlloc - * @param[in] flags Flags to be passed for extension + * @param[in] size Requested memory size * @return Error code */ -hipError_t hipHostGetDevicePointer(void** devPtr, void* hstPtr, unsigned int flags) ; +hipError_t hipHostGetDevicePointer(void** devPtr, void* hstPtr, size_t size) ; /** * @brief Get flags associated with host pointer diff --git a/projects/clr/hipamd/include/hip_runtime_api.h b/projects/clr/hipamd/include/hip_runtime_api.h index 3a0a4b399a..c7d9f3fa8b 100644 --- a/projects/clr/hipamd/include/hip_runtime_api.h +++ b/projects/clr/hipamd/include/hip_runtime_api.h @@ -149,8 +149,6 @@ typedef enum hipError_t { ,hipErrorInvalidResourceHandle ///< Resource handle (hipEvent_t or hipStream_t) invalid. ,hipErrorInvalidDevice ///< DeviceID must be in range 0...#compute-devices. ,hipErrorInvalidMemcpyDirection ///< Invalid memory copy direction - ,hipErrorInvalidDevicePointer ///< Invalid Device Pointer - ,hipErrorInitializationError ///< TODO comment from hipErrorInitializationError ,hipErrorNoDevice ///< Call to hipGetDeviceCount returned 0 devices ,hipErrorNotReady ///< Indicates that asynchronous operations enqueued earlier are not ready. This is not actually an error, but is used to distinguish from hipSuccess (which indicates completion). APIs that return this error include hipEventQuery and hipStreamQuery. diff --git a/projects/clr/hipamd/src/hip_hcc.cpp b/projects/clr/hipamd/src/hip_hcc.cpp index 23481e27b3..7aa7ae4482 100644 --- a/projects/clr/hipamd/src/hip_hcc.cpp +++ b/projects/clr/hipamd/src/hip_hcc.cpp @@ -2603,24 +2603,15 @@ hipError_t hipFree(void* ptr) // TODO - ensure this pointer was created by hipMalloc and not hipMallocHost std::call_once(hip_initialized, ihipInit); - hipError_t hipStatus = hipErrorInvalidDevicePointer; // Synchronize to ensure all work has finished. ihipGetTlsDefaultDevice()->waitAllStreams(); // ignores non-blocking streams, this waits for all activity to finish. if (ptr) { - hc::accelerator acc; - hc::AmPointerInfo amPointerInfo(NULL, NULL, 0, acc, 0, 0); - am_status_t status = hc::am_memtracker_getinfo(&amPointerInfo, ptr); - if(status == AM_SUCCESS){ - if(amPointerInfo._hostPointer == NULL){ - hc::am_free(ptr); - hipStatus = hipSuccess; - } - } + hc::am_free(ptr); } - return ihipLogStatus(hipStatus); + return ihipLogStatus(hipSuccess); } @@ -2629,20 +2620,12 @@ hipError_t hipHostFree(void* ptr) // TODO - ensure this pointer was created by hipMallocHost and not hipMalloc std::call_once(hip_initialized, ihipInit); - hipError_t hipStatus = hipErrorInvalidDevicePointer; if (ptr) { - hc::accelerator acc; - hc::AmPointerInfo amPointerInfo(NULL, NULL, 0, acc, 0, 0); - am_status_t status = hc::am_memtracker_getinfo(&amPointerInfo, ptr); - if(status == AM_SUCCESS){ - if(amPointerInfo._hostPointer == ptr){ - hc::am_free(ptr); - hipStatus = hipSuccess; - } - } + tprintf (DB_MEM, " %s: %p\n", __func__, ptr); + hc::am_free(ptr); } - return ihipLogStatus(hipStatus); + return ihipLogStatus(hipSuccess); }; diff --git a/projects/clr/hipamd/tests/src/CMakeLists.txt b/projects/clr/hipamd/tests/src/CMakeLists.txt index ab9c41d545..bbbb3c52ed 100644 --- a/projects/clr/hipamd/tests/src/CMakeLists.txt +++ b/projects/clr/hipamd/tests/src/CMakeLists.txt @@ -140,8 +140,6 @@ make_hip_executable (hipStreamL5 hipStreamL5.cpp) make_hip_executable (hipHostGetFlags hipHostGetFlags.cpp) make_hip_executable (hipHostRegister hipHostRegister.cpp) make_hip_executable (hipRandomMemcpyAsync hipRandomMemcpyAsync.cpp) -make_hip_executable (hipMemoryAllocate hipMemoryAllocate.cpp) - make_test(hip_ballot " " ) make_test(hip_anyall " " ) make_test(hip_popc " " ) @@ -172,6 +170,4 @@ make_test(hipStreamL5 " ") make_test(hipRandomMemcpyAsync " ") #make_test(hipAPIStreamEnable " ") #make_test(hipAPIStreamDisable " ") -make_test(hipMemoryAllocate " ") - make_hipify_test(specialFunc.cu ) diff --git a/projects/clr/hipamd/tests/src/hipMemoryAllocate.cpp b/projects/clr/hipamd/tests/src/hipMemoryAllocate.cpp deleted file mode 100644 index 30da822eaf..0000000000 --- a/projects/clr/hipamd/tests/src/hipMemoryAllocate.cpp +++ /dev/null @@ -1,51 +0,0 @@ -/* -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"test_common.h" - -#define SIZE 1024*1024*256 - -int main(){ - float *Ad, *B, *Bd, *Bm, *C, *Cd; - B = (float*)malloc(SIZE); - hipMalloc((void**)&Ad, SIZE); - hipHostMalloc((void**)&B, SIZE); - hipHostMalloc((void**)&Bd, SIZE, hipHostMallocDefault); - hipHostMalloc((void**)&Bm, SIZE, hipHostMallocMapped); - hipHostMalloc((void**)&C, SIZE, hipHostMallocMapped); - hipHostGetDevicePointer((void**)&Cd, C, SIZE); - - HIPASSERT(hipFree(Ad) == hipSuccess); - HIPASSERT(hipHostFree(Ad) == hipErrorInvalidDevicePointer); - - HIPASSERT(hipFree(B) == hipErrorInvalidDevicePointer); - HIPASSERT(hipFree(Bd) == hipErrorInvalidDevicePointer); - HIPASSERT(hipFree(Bm) == hipErrorInvalidDevicePointer); - HIPASSERT(hipHostFree(Bd) == hipSuccess); - HIPASSERT(hipHostFree(Bm) == hipSuccess); - - HIPASSERT(hipFree(C) == hipErrorInvalidDevicePointer); - HIPASSERT(hipFree(Cd) == hipErrorInvalidDevicePointer); - HIPASSERT(hipHostFree(C) == hipSuccess); - HIPASSERT(hipHostFree(Cd) == hipErrorInvalidDevicePointer); - HIPASSERT(hipFree(Cd) == hipErrorInvalidDevicePointer); - - HIPASSERT(hipFree(NULL) == hipErrorInvalidDevicePointer); - HIPASSERT(hipHostFree(NULL) == hipErrorInvalidDevicePointer); - passed(); -} From 0978c92dbcbd0a5d8671bf8a93bfab26ef7dc9f2 Mon Sep 17 00:00:00 2001 From: Aditya Atluri Date: Mon, 21 Mar 2016 10:36:14 -0500 Subject: [PATCH 5/9] Revert "fix nvcc for hipHostMalloc* flags." This reverts commit 849395ec02a35afd3eab1f291a3dc1f795ff0fe7. [ROCm/clr commit: 83fee90e83153ea6c53baad4f394e4874c418bfa] --- projects/clr/hipamd/include/nvcc_detail/hip_runtime_api.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/projects/clr/hipamd/include/nvcc_detail/hip_runtime_api.h b/projects/clr/hipamd/include/nvcc_detail/hip_runtime_api.h index 89b5a2dfee..edf2568687 100644 --- a/projects/clr/hipamd/include/nvcc_detail/hip_runtime_api.h +++ b/projects/clr/hipamd/include/nvcc_detail/hip_runtime_api.h @@ -50,10 +50,10 @@ hipMemcpyHostToHost } hipTextureFilterMode;*/ #define hipFilterModePoint cudaFilterModePoint -#define hipHostMallocDefault cudaHostAllocDefault -#define hipHostMallocPortable cudaHostAllocPortable -#define hipHostMallocMapped cudaHostAllocMapped -#define hipHostMallocWriteCombined cudaHostAllocWriteCombined +#define hipHostAllocDefault cudaHostAllocDefault +#define hipHostAllocPortable cudaHostAllocPortable +#define hipHostAllocMapped cudaHostAllocMapped +#define hipHostAllocWriteCombined cudaHostAllocWriteCombined #define hipHostRegisterPortable cudaHostRegisterPortable #define hipHostRegisterMapped cudaHostRegisterMapped From 399994788f6d326cbc3a5ba05152bb2d781a1b19 Mon Sep 17 00:00:00 2001 From: Aditya Atluri Date: Mon, 21 Mar 2016 10:39:49 -0500 Subject: [PATCH 6/9] Revert "Revert "fix nvcc for hipHostMalloc* flags."" This reverts commit 0978c92dbcbd0a5d8671bf8a93bfab26ef7dc9f2. [ROCm/clr commit: bde1e6182db0fb365e5d4eebbf3caeb66e9b5011] --- projects/clr/hipamd/include/nvcc_detail/hip_runtime_api.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/projects/clr/hipamd/include/nvcc_detail/hip_runtime_api.h b/projects/clr/hipamd/include/nvcc_detail/hip_runtime_api.h index edf2568687..89b5a2dfee 100644 --- a/projects/clr/hipamd/include/nvcc_detail/hip_runtime_api.h +++ b/projects/clr/hipamd/include/nvcc_detail/hip_runtime_api.h @@ -50,10 +50,10 @@ hipMemcpyHostToHost } hipTextureFilterMode;*/ #define hipFilterModePoint cudaFilterModePoint -#define hipHostAllocDefault cudaHostAllocDefault -#define hipHostAllocPortable cudaHostAllocPortable -#define hipHostAllocMapped cudaHostAllocMapped -#define hipHostAllocWriteCombined cudaHostAllocWriteCombined +#define hipHostMallocDefault cudaHostAllocDefault +#define hipHostMallocPortable cudaHostAllocPortable +#define hipHostMallocMapped cudaHostAllocMapped +#define hipHostMallocWriteCombined cudaHostAllocWriteCombined #define hipHostRegisterPortable cudaHostRegisterPortable #define hipHostRegisterMapped cudaHostRegisterMapped From cb2b9495f8d6e6b01f7a9ca4a37261232667840d Mon Sep 17 00:00:00 2001 From: Aditya Atluri Date: Mon, 21 Mar 2016 10:40:42 -0500 Subject: [PATCH 7/9] Revert "Revert "fixed memory free apis"" This reverts commit 70d2a03efdd5ada58b3951ed0ecc16e261e5384c. [ROCm/clr commit: 8af8ee2476d9f5ed1c6821269a12e70ae37f344c] --- .../include/hcc_detail/hip_runtime_api.h | 4 +- projects/clr/hipamd/include/hip_runtime_api.h | 2 + projects/clr/hipamd/src/hip_hcc.cpp | 27 ++++++++-- projects/clr/hipamd/tests/src/CMakeLists.txt | 4 ++ .../hipamd/tests/src/hipMemoryAllocate.cpp | 51 +++++++++++++++++++ 5 files changed, 81 insertions(+), 7 deletions(-) create mode 100644 projects/clr/hipamd/tests/src/hipMemoryAllocate.cpp diff --git a/projects/clr/hipamd/include/hcc_detail/hip_runtime_api.h b/projects/clr/hipamd/include/hcc_detail/hip_runtime_api.h index ef5ad4927c..4c854e72f1 100644 --- a/projects/clr/hipamd/include/hcc_detail/hip_runtime_api.h +++ b/projects/clr/hipamd/include/hcc_detail/hip_runtime_api.h @@ -688,10 +688,10 @@ hipError_t hipHostAlloc(void** ptr, size_t size, unsigned int flags) __attribute * * @param[out] dstPtr Device Pointer mapped to passed host pointer * @param[in] hstPtr Host Pointer allocated through hipHostAlloc - * @param[in] size Requested memory size + * @param[in] flags Flags to be passed for extension * @return Error code */ -hipError_t hipHostGetDevicePointer(void** devPtr, void* hstPtr, size_t size) ; +hipError_t hipHostGetDevicePointer(void** devPtr, void* hstPtr, unsigned int flags) ; /** * @brief Get flags associated with host pointer diff --git a/projects/clr/hipamd/include/hip_runtime_api.h b/projects/clr/hipamd/include/hip_runtime_api.h index c7d9f3fa8b..3a0a4b399a 100644 --- a/projects/clr/hipamd/include/hip_runtime_api.h +++ b/projects/clr/hipamd/include/hip_runtime_api.h @@ -149,6 +149,8 @@ typedef enum hipError_t { ,hipErrorInvalidResourceHandle ///< Resource handle (hipEvent_t or hipStream_t) invalid. ,hipErrorInvalidDevice ///< DeviceID must be in range 0...#compute-devices. ,hipErrorInvalidMemcpyDirection ///< Invalid memory copy direction + ,hipErrorInvalidDevicePointer ///< Invalid Device Pointer + ,hipErrorInitializationError ///< TODO comment from hipErrorInitializationError ,hipErrorNoDevice ///< Call to hipGetDeviceCount returned 0 devices ,hipErrorNotReady ///< Indicates that asynchronous operations enqueued earlier are not ready. This is not actually an error, but is used to distinguish from hipSuccess (which indicates completion). APIs that return this error include hipEventQuery and hipStreamQuery. diff --git a/projects/clr/hipamd/src/hip_hcc.cpp b/projects/clr/hipamd/src/hip_hcc.cpp index 7aa7ae4482..23481e27b3 100644 --- a/projects/clr/hipamd/src/hip_hcc.cpp +++ b/projects/clr/hipamd/src/hip_hcc.cpp @@ -2603,15 +2603,24 @@ hipError_t hipFree(void* ptr) // TODO - ensure this pointer was created by hipMalloc and not hipMallocHost std::call_once(hip_initialized, ihipInit); + hipError_t hipStatus = hipErrorInvalidDevicePointer; // Synchronize to ensure all work has finished. ihipGetTlsDefaultDevice()->waitAllStreams(); // ignores non-blocking streams, this waits for all activity to finish. if (ptr) { - hc::am_free(ptr); + hc::accelerator acc; + hc::AmPointerInfo amPointerInfo(NULL, NULL, 0, acc, 0, 0); + am_status_t status = hc::am_memtracker_getinfo(&amPointerInfo, ptr); + if(status == AM_SUCCESS){ + if(amPointerInfo._hostPointer == NULL){ + hc::am_free(ptr); + hipStatus = hipSuccess; + } + } } - return ihipLogStatus(hipSuccess); + return ihipLogStatus(hipStatus); } @@ -2620,12 +2629,20 @@ hipError_t hipHostFree(void* ptr) // TODO - ensure this pointer was created by hipMallocHost and not hipMalloc std::call_once(hip_initialized, ihipInit); + hipError_t hipStatus = hipErrorInvalidDevicePointer; if (ptr) { - tprintf (DB_MEM, " %s: %p\n", __func__, ptr); - hc::am_free(ptr); + hc::accelerator acc; + hc::AmPointerInfo amPointerInfo(NULL, NULL, 0, acc, 0, 0); + am_status_t status = hc::am_memtracker_getinfo(&amPointerInfo, ptr); + if(status == AM_SUCCESS){ + if(amPointerInfo._hostPointer == ptr){ + hc::am_free(ptr); + hipStatus = hipSuccess; + } + } } - return ihipLogStatus(hipSuccess); + return ihipLogStatus(hipStatus); }; diff --git a/projects/clr/hipamd/tests/src/CMakeLists.txt b/projects/clr/hipamd/tests/src/CMakeLists.txt index bbbb3c52ed..ab9c41d545 100644 --- a/projects/clr/hipamd/tests/src/CMakeLists.txt +++ b/projects/clr/hipamd/tests/src/CMakeLists.txt @@ -140,6 +140,8 @@ make_hip_executable (hipStreamL5 hipStreamL5.cpp) make_hip_executable (hipHostGetFlags hipHostGetFlags.cpp) make_hip_executable (hipHostRegister hipHostRegister.cpp) make_hip_executable (hipRandomMemcpyAsync hipRandomMemcpyAsync.cpp) +make_hip_executable (hipMemoryAllocate hipMemoryAllocate.cpp) + make_test(hip_ballot " " ) make_test(hip_anyall " " ) make_test(hip_popc " " ) @@ -170,4 +172,6 @@ make_test(hipStreamL5 " ") make_test(hipRandomMemcpyAsync " ") #make_test(hipAPIStreamEnable " ") #make_test(hipAPIStreamDisable " ") +make_test(hipMemoryAllocate " ") + make_hipify_test(specialFunc.cu ) diff --git a/projects/clr/hipamd/tests/src/hipMemoryAllocate.cpp b/projects/clr/hipamd/tests/src/hipMemoryAllocate.cpp new file mode 100644 index 0000000000..30da822eaf --- /dev/null +++ b/projects/clr/hipamd/tests/src/hipMemoryAllocate.cpp @@ -0,0 +1,51 @@ +/* +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"test_common.h" + +#define SIZE 1024*1024*256 + +int main(){ + float *Ad, *B, *Bd, *Bm, *C, *Cd; + B = (float*)malloc(SIZE); + hipMalloc((void**)&Ad, SIZE); + hipHostMalloc((void**)&B, SIZE); + hipHostMalloc((void**)&Bd, SIZE, hipHostMallocDefault); + hipHostMalloc((void**)&Bm, SIZE, hipHostMallocMapped); + hipHostMalloc((void**)&C, SIZE, hipHostMallocMapped); + hipHostGetDevicePointer((void**)&Cd, C, SIZE); + + HIPASSERT(hipFree(Ad) == hipSuccess); + HIPASSERT(hipHostFree(Ad) == hipErrorInvalidDevicePointer); + + HIPASSERT(hipFree(B) == hipErrorInvalidDevicePointer); + HIPASSERT(hipFree(Bd) == hipErrorInvalidDevicePointer); + HIPASSERT(hipFree(Bm) == hipErrorInvalidDevicePointer); + HIPASSERT(hipHostFree(Bd) == hipSuccess); + HIPASSERT(hipHostFree(Bm) == hipSuccess); + + HIPASSERT(hipFree(C) == hipErrorInvalidDevicePointer); + HIPASSERT(hipFree(Cd) == hipErrorInvalidDevicePointer); + HIPASSERT(hipHostFree(C) == hipSuccess); + HIPASSERT(hipHostFree(Cd) == hipErrorInvalidDevicePointer); + HIPASSERT(hipFree(Cd) == hipErrorInvalidDevicePointer); + + HIPASSERT(hipFree(NULL) == hipErrorInvalidDevicePointer); + HIPASSERT(hipHostFree(NULL) == hipErrorInvalidDevicePointer); + passed(); +} From 726ffa51247ef21c1343a8bb92cc9db0d228c127 Mon Sep 17 00:00:00 2001 From: Aditya Atluri Date: Mon, 21 Mar 2016 18:33:50 -0500 Subject: [PATCH 8/9] Update CUDA_Runtime_API_functions_supported_by_HIP.md [ROCm/clr commit: a8a255b6bceb0eeffd4d2a746d2bdb017bfd3080] --- .../clr/hipamd/CUDA_Runtime_API_functions_supported_by_HIP.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/projects/clr/hipamd/CUDA_Runtime_API_functions_supported_by_HIP.md b/projects/clr/hipamd/CUDA_Runtime_API_functions_supported_by_HIP.md index f1f0599626..f3485d3232 100644 --- a/projects/clr/hipamd/CUDA_Runtime_API_functions_supported_by_HIP.md +++ b/projects/clr/hipamd/CUDA_Runtime_API_functions_supported_by_HIP.md @@ -97,7 +97,7 @@ | `cudaGetMipmappedArrayLevel` | | Gets a mipmap level of a CUDA mipmapped array. | | `cudaGetSymbolAddress` | | Finds the address associated with a CUDA symbol. | | `cudaGetSymbolSize` | | Finds the size of the object associated with a CUDA symbol. | -| `cudaHostAlloc` | `hipHostAlloc` | Allocates page-locked memory on the host. | +| `cudaHostAlloc` | `hipHostMalloc` | Allocates page-locked memory on the host. | | `cudaHostGetDevicePointer` | `hipHostGetDevicePointer` | Passes back device pointer of mapped host memory allocated by cudaHostAlloc or registered by cudaHostRegister. | | `cudaHostGetFlags` | `hipHostGetFlags` | Passes back flags used to allocate pinned host memory allocated by cudaHostAlloc. | | `cudaHostRegister` | | Registers an existing host memory range for use by CUDA. | @@ -106,7 +106,7 @@ | `cudaMalloc3D` | | Allocates logical 1D, 2D, or 3D memory objects on the device. | | `cudaMalloc3DArray` | | Allocate an array on the device. | | `cudaMallocArray` | | Allocate an array on the device. | -| `cudaMallocHost` | `hipHostAlloc` | Allocates page-locked memory on the host. | +| `cudaMallocHost` | `hipHostMalloc` | Allocates page-locked memory on the host. | | `cudaMallocManaged` | | Allocates memory that will be automatically managed by the Unified Memory system. | | `cudaMallocMipmappedArray` | | Allocate a mipmapped array on the device. | | `cudaMallocPitch` | | Allocates pitched memory on the device. | From 52213587a76d416a3bb70cc1ca31dd18c9faad4e Mon Sep 17 00:00:00 2001 From: Aditya Atluri Date: Tue, 22 Mar 2016 10:42:34 -0500 Subject: [PATCH 9/9] Update CUDA_Runtime_API_functions_supported_by_HIP.md [ROCm/clr commit: 55291cc6545aeed2ab404e76dc8c062273c7250c] --- .../clr/hipamd/CUDA_Runtime_API_functions_supported_by_HIP.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/projects/clr/hipamd/CUDA_Runtime_API_functions_supported_by_HIP.md b/projects/clr/hipamd/CUDA_Runtime_API_functions_supported_by_HIP.md index f3485d3232..3ebb80b79e 100644 --- a/projects/clr/hipamd/CUDA_Runtime_API_functions_supported_by_HIP.md +++ b/projects/clr/hipamd/CUDA_Runtime_API_functions_supported_by_HIP.md @@ -18,7 +18,7 @@ | `cudaGetDevice` | `hipGetDevice` | Returns which device is currently being used. | | `cudaGetDeviceCount` | `hipGetDeviceCount` | Returns the number of compute-capable devices. | | `cudaGetDeviceFlags` | | Gets the flags for the current device. | -| `cudaGetDeviceProperties` | `hipDeviceGetProperties` | Returns information about the compute-device. | +| `cudaGetDeviceProperties` | `hipGetDeviceProperties` | Returns information about the compute-device. | | `cudaIpcCloseMemHandle` | | Close memory mapped with cudaIpcOpenMemHandle. | | `cudaIpcGetEventHandle` | | Gets an interprocess handle for a previously allocated event. | | `cudaIpcGetMemHandle` | | Gets an interprocess memory handle for an existing device memory allocation. |