From 8d7be2e4b4375242175e78a1190eea68a14f96a8 Mon Sep 17 00:00:00 2001 From: itrowbri Date: Thu, 12 Sep 2024 18:31:00 -0500 Subject: [PATCH] SWDEV-483130: Replace calls to deprecated functions hipHostMalloc/hipHostFree (#1070) * SWDEV-483130: Replace calls to deprecated functions hipHostMalloc/hipHostFree * SWDEV-483130: Replace calls to deprecated functions hipHostMalloc/hipHostFree. Moved definitions from lib/commons/defines.hpp to samples/common/defines.hpp and tests/common/defines.hpp * Updated comment for clarity * Update tests/rocprofv3/aborted-app/validate.py Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * Formatting * Formatting * Updated CHANGELOG --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- CHANGELOG.md | 1 + samples/api_buffered_tracing/CMakeLists.txt | 5 +++-- samples/api_buffered_tracing/main.cpp | 3 ++- samples/common/defines.hpp | 8 ++++++++ .../external_correlation_id_request/CMakeLists.txt | 2 +- samples/external_correlation_id_request/main.cpp | 3 ++- samples/pc_sampling/CMakeLists.txt | 6 ++++-- samples/pc_sampling/main.cpp | 3 ++- tests/bin/scratch-memory/CMakeLists.txt | 3 ++- tests/bin/scratch-memory/scratch-memory.cpp | 4 +++- tests/bin/vector-operations/CMakeLists.txt | 3 ++- tests/bin/vector-operations/vector-ops.cpp | 14 ++++++++------ tests/common/defines.hpp | 8 ++++++++ tests/lib/vector-operations/CMakeLists.txt | 3 ++- tests/lib/vector-operations/vector-ops.cpp | 14 ++++++++------ tests/rocprofv3/aborted-app/validate.py | 9 +++++++-- 16 files changed, 63 insertions(+), 26 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 603c02a7de..85ff07ce04 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -101,6 +101,7 @@ Full documentation for ROCprofiler-SDK is available at [Click Here](source/docs/ ### Changes - Support `--marker-trace` on application linked against old (roctracer) ROCTx (i.e. `libroctx64.so`) +- Replaced deprecated hipHostMalloc and hipHostFree functions with hipExtHostAlloc and hipFreeHost in when ROCm version is greater than or equal to 6.3 ### Fixes diff --git a/samples/api_buffered_tracing/CMakeLists.txt b/samples/api_buffered_tracing/CMakeLists.txt index 4f986ed028..d0479db013 100644 --- a/samples/api_buffered_tracing/CMakeLists.txt +++ b/samples/api_buffered_tracing/CMakeLists.txt @@ -40,8 +40,9 @@ find_package(Threads REQUIRED) add_executable(buffered-api-tracing) target_sources(buffered-api-tracing PRIVATE main.cpp) target_link_libraries( - buffered-api-tracing PRIVATE buffered-api-tracing-client Threads::Threads - rocprofiler-sdk::samples-build-flags) + buffered-api-tracing + PRIVATE buffered-api-tracing-client Threads::Threads + rocprofiler-sdk::samples-build-flags rocprofiler-sdk::samples-common-library) rocprofiler_samples_get_preload_env(PRELOAD_ENV buffered-api-tracing-client) rocprofiler_samples_get_ld_library_path_env(LIBRARY_PATH_ENV) diff --git a/samples/api_buffered_tracing/main.cpp b/samples/api_buffered_tracing/main.cpp index de8b42cede..8accf55abb 100644 --- a/samples/api_buffered_tracing/main.cpp +++ b/samples/api_buffered_tracing/main.cpp @@ -22,6 +22,7 @@ #include "client.hpp" +#include "common/defines.hpp" #include "hip/hip_runtime.h" #include @@ -315,7 +316,7 @@ run_scratch(int rank, int tid, hipStream_t stream, int, char** argv) const auto* exe_name = ::basename(argv[0]); uint64_t* data_ptr = nullptr; - HIP_API_CALL(hipHostMalloc(&data_ptr, sizeof(uint64_t), 0)); + HIP_API_CALL(HIP_HOST_ALLOC_FUNC(&data_ptr, sizeof(uint64_t), 0)); *data_ptr = 0; test_kern_small<<<1000, 1, 0, stream>>>(data_ptr); diff --git a/samples/common/defines.hpp b/samples/common/defines.hpp index 0137e597cf..37b3558909 100644 --- a/samples/common/defines.hpp +++ b/samples/common/defines.hpp @@ -68,3 +68,11 @@ throw std::runtime_error(errmsg.str()); \ } \ } + +#if HIP_VERSION >= 60300000 +# define HIP_HOST_ALLOC_FUNC hipExtHostAlloc +# define HIP_HOST_FREE_FUNC hipFreeHost +#else +# define HIP_HOST_ALLOC_FUNC hipHostMalloc +# define HIP_HOST_FREE_FUNC hipHostFree +#endif diff --git a/samples/external_correlation_id_request/CMakeLists.txt b/samples/external_correlation_id_request/CMakeLists.txt index 02769168a8..983813c240 100644 --- a/samples/external_correlation_id_request/CMakeLists.txt +++ b/samples/external_correlation_id_request/CMakeLists.txt @@ -42,7 +42,7 @@ target_sources(external-correlation-id-request PRIVATE main.cpp) target_link_libraries( external-correlation-id-request PRIVATE external-correlation-id-request-client Threads::Threads - rocprofiler-sdk::samples-build-flags) + rocprofiler-sdk::samples-build-flags rocprofiler-sdk::samples-common-library) rocprofiler_samples_get_preload_env(PRELOAD_ENV external-correlation-id-request-client) rocprofiler_samples_get_ld_library_path_env(LIBRARY_PATH_ENV) diff --git a/samples/external_correlation_id_request/main.cpp b/samples/external_correlation_id_request/main.cpp index d78efed384..b8524f3ed0 100644 --- a/samples/external_correlation_id_request/main.cpp +++ b/samples/external_correlation_id_request/main.cpp @@ -20,6 +20,7 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. +#include "common/defines.hpp" #include "hip/hip_runtime.h" #include @@ -304,7 +305,7 @@ run_scratch(int rank, int tid, hipStream_t stream, int, char** argv) const auto* exe_name = ::basename(argv[0]); uint64_t* data_ptr = nullptr; - HIP_API_CALL(hipHostMalloc(&data_ptr, sizeof(uint64_t), 0)); + HIP_API_CALL(HIP_HOST_ALLOC_FUNC(&data_ptr, sizeof(uint64_t), 0)); *data_ptr = 0; test_kern_small<<<1000, 1, 0, stream>>>(data_ptr); diff --git a/samples/pc_sampling/CMakeLists.txt b/samples/pc_sampling/CMakeLists.txt index 313b78ff28..f8ae9f0147 100644 --- a/samples/pc_sampling/CMakeLists.txt +++ b/samples/pc_sampling/CMakeLists.txt @@ -39,8 +39,10 @@ find_package(Threads REQUIRED) add_executable(pc-sampling) target_sources(pc-sampling PRIVATE main.cpp) -target_link_libraries(pc-sampling PRIVATE pc-sampling-client Threads::Threads - rocprofiler-sdk::samples-build-flags) +target_link_libraries( + pc-sampling + PRIVATE pc-sampling-client Threads::Threads rocprofiler-sdk::samples-build-flags + rocprofiler-sdk::samples-common-library) rocprofiler_samples_get_preload_env(PRELOAD_ENV pc-sampling-client) rocprofiler_samples_get_ld_library_path_env(LIBRARY_PATH_ENV) diff --git a/samples/pc_sampling/main.cpp b/samples/pc_sampling/main.cpp index d78efed384..b8524f3ed0 100644 --- a/samples/pc_sampling/main.cpp +++ b/samples/pc_sampling/main.cpp @@ -20,6 +20,7 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. +#include "common/defines.hpp" #include "hip/hip_runtime.h" #include @@ -304,7 +305,7 @@ run_scratch(int rank, int tid, hipStream_t stream, int, char** argv) const auto* exe_name = ::basename(argv[0]); uint64_t* data_ptr = nullptr; - HIP_API_CALL(hipHostMalloc(&data_ptr, sizeof(uint64_t), 0)); + HIP_API_CALL(HIP_HOST_ALLOC_FUNC(&data_ptr, sizeof(uint64_t), 0)); *data_ptr = 0; test_kern_small<<<1000, 1, 0, stream>>>(data_ptr); diff --git a/tests/bin/scratch-memory/CMakeLists.txt b/tests/bin/scratch-memory/CMakeLists.txt index 0997ead8e6..06ba7ddadb 100644 --- a/tests/bin/scratch-memory/CMakeLists.txt +++ b/tests/bin/scratch-memory/CMakeLists.txt @@ -39,4 +39,5 @@ target_compile_options(scratch-memory PRIVATE -W -Wall -Wextra -Wpedantic -Wshad -Werror) find_package(Threads REQUIRED) -target_link_libraries(scratch-memory PRIVATE Threads::Threads hsa-runtime64) +target_link_libraries(scratch-memory PRIVATE Threads::Threads hsa-runtime64 + rocprofiler-sdk::tests-common-library) diff --git a/tests/bin/scratch-memory/scratch-memory.cpp b/tests/bin/scratch-memory/scratch-memory.cpp index 17efd59537..3533efa4db 100644 --- a/tests/bin/scratch-memory/scratch-memory.cpp +++ b/tests/bin/scratch-memory/scratch-memory.cpp @@ -27,6 +27,8 @@ #include #include +#include "common/defines.hpp" + #define hipCheckErr(errval) \ do \ { \ @@ -166,7 +168,7 @@ int test_scratch() { uint64_t* data_ptr; - hipCheckErr(hipHostMalloc(&data_ptr, sizeof(uint64_t), 0)); + hipCheckErr(HIP_HOST_ALLOC_FUNC(&data_ptr, sizeof(uint64_t), 0)); std::vector host_floats(1024); float* dev; diff --git a/tests/bin/vector-operations/CMakeLists.txt b/tests/bin/vector-operations/CMakeLists.txt index dc508eae99..c05b55e794 100644 --- a/tests/bin/vector-operations/CMakeLists.txt +++ b/tests/bin/vector-operations/CMakeLists.txt @@ -38,4 +38,5 @@ target_sources(vector-ops PRIVATE vector-ops.cpp) target_compile_options(vector-ops PRIVATE -W -Wall -Wextra -Wpedantic -Wshadow -Werror) find_package(Threads REQUIRED) -target_link_libraries(vector-ops PRIVATE Threads::Threads) +target_link_libraries(vector-ops PRIVATE Threads::Threads + rocprofiler-sdk::tests-common-library) diff --git a/tests/bin/vector-operations/vector-ops.cpp b/tests/bin/vector-operations/vector-ops.cpp index 33ca71457c..9acf1987c7 100644 --- a/tests/bin/vector-operations/vector-ops.cpp +++ b/tests/bin/vector-operations/vector-ops.cpp @@ -31,6 +31,8 @@ #include #include +#include "common/defines.hpp" + #define HIP_API_CALL(CALL) \ { \ hipError_t error_ = (CALL); \ @@ -167,9 +169,9 @@ run(int NUM_QUEUE, int DEVICE_ID) { HIP_API_CALL(hipStreamCreateWithFlags(&streams[q], hipStreamNonBlocking)); - HIP_API_CALL(hipHostMalloc(&hostA[q], NUM * sizeof(float), 0)); - HIP_API_CALL(hipHostMalloc(&hostB[q], NUM * sizeof(float), 0)); - HIP_API_CALL(hipHostMalloc(&hostC[q], NUM * sizeof(float), 0)); + HIP_API_CALL(HIP_HOST_ALLOC_FUNC(&hostA[q], NUM * sizeof(float), 0)); + HIP_API_CALL(HIP_HOST_ALLOC_FUNC(&hostB[q], NUM * sizeof(float), 0)); + HIP_API_CALL(HIP_HOST_ALLOC_FUNC(&hostC[q], NUM * sizeof(float), 0)); // initialize the input data for(int i = 0; i < NUM; i++) @@ -264,9 +266,9 @@ run(int NUM_QUEUE, int DEVICE_ID) HIP_API_CALL(hipFree(deviceB[q])); HIP_API_CALL(hipFree(deviceC[q])); - HIP_API_CALL(hipHostFree(hostA[q])); - HIP_API_CALL(hipHostFree(hostB[q])); - HIP_API_CALL(hipHostFree(hostC[q])); + HIP_API_CALL(HIP_HOST_FREE_FUNC(hostA[q])); + HIP_API_CALL(HIP_HOST_FREE_FUNC(hostB[q])); + HIP_API_CALL(HIP_HOST_FREE_FUNC(hostC[q])); HIP_API_CALL(hipStreamDestroy(streams[q])); } diff --git a/tests/common/defines.hpp b/tests/common/defines.hpp index 26c2e55fe4..1b4622a740 100644 --- a/tests/common/defines.hpp +++ b/tests/common/defines.hpp @@ -38,3 +38,11 @@ throw std::runtime_error(errmsg.str()); \ } \ } + +#if HIP_VERSION >= 60300000 +# define HIP_HOST_ALLOC_FUNC hipExtHostAlloc +# define HIP_HOST_FREE_FUNC hipFreeHost +#else +# define HIP_HOST_ALLOC_FUNC hipHostMalloc +# define HIP_HOST_FREE_FUNC hipHostFree +#endif diff --git a/tests/lib/vector-operations/CMakeLists.txt b/tests/lib/vector-operations/CMakeLists.txt index f9ebb9724c..ed2ec80c0b 100644 --- a/tests/lib/vector-operations/CMakeLists.txt +++ b/tests/lib/vector-operations/CMakeLists.txt @@ -41,4 +41,5 @@ target_include_directories(vector-ops-shared-library PUBLIC ${CMAKE_CURRENT_SOUR set_target_properties(vector-ops-shared-library PROPERTIES OUTPUT_NAME vector-ops) find_package(Threads REQUIRED) -target_link_libraries(vector-ops-shared-library PRIVATE Threads::Threads) +target_link_libraries(vector-ops-shared-library + PRIVATE Threads::Threads rocprofiler-sdk::tests-common-library) diff --git a/tests/lib/vector-operations/vector-ops.cpp b/tests/lib/vector-operations/vector-ops.cpp index 00914c4fd9..0e38910ce8 100644 --- a/tests/lib/vector-operations/vector-ops.cpp +++ b/tests/lib/vector-operations/vector-ops.cpp @@ -30,6 +30,8 @@ #include #include +#include "common/defines.hpp" + #define HIP_API_CALL(CALL) \ { \ hipError_t error_ = (CALL); \ @@ -170,9 +172,9 @@ run_vector_ops_impl(int num_queue, int device_id) { HIP_API_CALL(hipStreamCreateWithFlags(&streams[q], hipStreamNonBlocking)); - HIP_API_CALL(hipHostMalloc(&hostA[q], NUM * sizeof(float), 0)); - HIP_API_CALL(hipHostMalloc(&hostB[q], NUM * sizeof(float), 0)); - HIP_API_CALL(hipHostMalloc(&hostC[q], NUM * sizeof(float), 0)); + HIP_API_CALL(HIP_HOST_ALLOC_FUNC(&hostA[q], NUM * sizeof(float), 0)); + HIP_API_CALL(HIP_HOST_ALLOC_FUNC(&hostB[q], NUM * sizeof(float), 0)); + HIP_API_CALL(HIP_HOST_ALLOC_FUNC(&hostC[q], NUM * sizeof(float), 0)); // initialize the input data for(int i = 0; i < NUM; i++) @@ -253,9 +255,9 @@ run_vector_ops_impl(int num_queue, int device_id) HIP_API_CALL(hipFree(deviceB[q])); HIP_API_CALL(hipFree(deviceC[q])); - HIP_API_CALL(hipHostFree(hostA[q])); - HIP_API_CALL(hipHostFree(hostB[q])); - HIP_API_CALL(hipHostFree(hostC[q])); + HIP_API_CALL(HIP_HOST_FREE_FUNC(hostA[q])); + HIP_API_CALL(HIP_HOST_FREE_FUNC(hostB[q])); + HIP_API_CALL(HIP_HOST_FREE_FUNC(hostC[q])); HIP_API_CALL(hipStreamDestroy(streams[q])); } diff --git a/tests/rocprofv3/aborted-app/validate.py b/tests/rocprofv3/aborted-app/validate.py index a4cfa2a421..1bcad43632 100644 --- a/tests/rocprofv3/aborted-app/validate.py +++ b/tests/rocprofv3/aborted-app/validate.py @@ -99,8 +99,13 @@ def test_hip_api_trace_json(json_data): "hipGetLastError", ] ) - - assert functions == expected_functions + # TODO: When tracing support is added for hipExtHostAlloc, replace + # hipHostMalloc with hipExtHostAlloc instead of removing hipHostMalloc + # as is happening currently + updated_expected_functions = [ + func for func in expected_functions if func != "hipHostMalloc" + ] + assert functions == expected_functions or functions == updated_expected_functions if __name__ == "__main__":