From d46d399976c173521c9af0247fc80c71221ebf74 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A1bio?= Date: Tue, 28 Jun 2022 04:30:37 +0100 Subject: [PATCH 1/7] EXSWCPHIPT-42: Changes to HIP RTC Framework implementation (#2732) - Removed ifdef from hipTestContext class - Fix potential race condition in hipTest::launchRTCKernel() - Improve documentation - Move moduleUnloading to main() instead of explicitly calling it on every test - Fix code formating - Fix segmentation fault caused by using catch2 macro after catch2 is destroyed --- tests/README.md | 22 +++++++++----- .../external/Catch2/cmake/Catch2/Catch.cmake | 4 +-- tests/catch/hipTestMain/hip_test_context.cc | 6 +++- tests/catch/hipTestMain/main.cc | 5 +++- tests/catch/include/hip_test_rtc.hh | 30 +++++++++++-------- tests/catch/unit/event/Unit_hipEventRecord.cc | 1 - tests/catch/unit/memory/hipHostMalloc.cc | 2 -- 7 files changed, 42 insertions(+), 28 deletions(-) diff --git a/tests/README.md b/tests/README.md index 1b1e54a2e3..e03e399104 100644 --- a/tests/README.md +++ b/tests/README.md @@ -149,19 +149,25 @@ Here "-C performance" indicate the "performance" configuration of ctest. ### RTC Testing -To enable RTC testing, cmake needs to be passed the DRTC_TESTING=1 options. +To enable RTC testing, cmake needs to be passed the `-DRTC_TESTING=1` option. When this option is passed, all tests that support this functionality will be run using HIP RTC to compile and run. To enable HIP RTC support for a specific test: - 1 - Move all its kernels to tests/catch/kernels (one file per kernel) - 2 - Update tests/catch/kernels/CMakeLists.txt - 3 - Update tests/catch/include/kernels.hh - 4 - Update tests/catch/include/kernel_mapping.hh - 5 - Include kernels.hh - 6 - Call hipTest::launchKernel() function instead of hipLaunchKernelGGL() -Note: HIP RTC does not do implicit casting of kernel parameters. This requires the test writer to explicitly do all the casting before running the kernel. The code will not compile otherwise. +1. Move all its kernels to `tests/catch/kernels` (one file per kernel): + 1. Kernel **functions** should use the file extension `.cpp` and include `kernels.hh` + 2. Kernel **templates** should use the file extension `.inl` +2. Update `tests/catch/kernels/CMakeLists.txt` (i.e. add the new kernel **functions** to `TEST_SRC`) +3. Update `tests/catch/include/kernels.hh`: + 1. Declare the new kernel **functions** + 2. Include the new .inl files that contain kernel **templates** + 3. Call the `FUNCTION_WRAPPER` and `TEMPLATE_WRAPPER` macros for each new function and template respectively. +4. Update `tests/catch/include/kernel_mapping.hh` with the mapping between the new files and respective function / template names. +5. Include `kernels.hh` +6. Call the `hipTest::launchKernel()` function instead of `hipLaunchKernelGGL()` + +**Note:** HIP RTC does not do implicit casting of kernel parameters. This **requires** the test writer to explicitly do all the casting before running the kernel. There is a `static_assert` inside `hipTest::launchKernel()` that checks that this was done correctly. However, due to limitations, the assertion is only performed when `-DRTC_TESTING` option is **disabled**. This means that runtime errors can occur if the casts are not performed correctly and `-DRTC_TESTING` is enabled. ### If a test fails - how to debug a test diff --git a/tests/catch/external/Catch2/cmake/Catch2/Catch.cmake b/tests/catch/external/Catch2/cmake/Catch2/Catch.cmake index 603dc1b994..868ccfa739 100644 --- a/tests/catch/external/Catch2/cmake/Catch2/Catch.cmake +++ b/tests/catch/external/Catch2/cmake/Catch2/Catch.cmake @@ -204,9 +204,9 @@ function(hip_add_exe_to_target) ) # Create shared lib of all tests if(NOT RTC_TESTING) - add_executable(${_NAME} EXCLUDE_FROM_ALL ${_TEST_SRC} $ $) + add_executable(${_NAME} EXCLUDE_FROM_ALL ${_TEST_SRC} $ $) else () - add_executable(${_NAME} EXCLUDE_FROM_ALL ${_TEST_SRC} $) + add_executable(${_NAME} EXCLUDE_FROM_ALL ${_TEST_SRC} $) if(HIP_PLATFORM STREQUAL "amd") target_link_libraries(${_NAME} hiprtc) else() diff --git a/tests/catch/hipTestMain/hip_test_context.cc b/tests/catch/hipTestMain/hip_test_context.cc index 597813b4c8..ae496d372b 100644 --- a/tests/catch/hipTestMain/hip_test_context.cc +++ b/tests/catch/hipTestMain/hip_test_context.cc @@ -1,3 +1,4 @@ +#include #include #include #include @@ -211,7 +212,10 @@ bool TestContext::parseJsonFile() { void TestContext::cleanContext() { for (auto& pair : compiledKernels) { - REQUIRE(hipSuccess == hipModuleUnload(pair.second.module)); + hipError_t error = hipModuleUnload(pair.second.module); + if (error != hipSuccess) { + throw std::runtime_error("Unable to unload rtc module"); + } } } diff --git a/tests/catch/hipTestMain/main.cc b/tests/catch/hipTestMain/main.cc index 886aa7a8dc..ea3bb9bd23 100644 --- a/tests/catch/hipTestMain/main.cc +++ b/tests/catch/hipTestMain/main.cc @@ -9,5 +9,8 @@ int main(int argc, char** argv) { std::cout << "HIP_SKIP_THIS_TEST" << std::endl; return 0; } - return Catch::Session().run(argc, argv); + int out = Catch::Session().run(argc, argv); + TestContext::get().cleanContext(); + return out; + } diff --git a/tests/catch/include/hip_test_rtc.hh b/tests/catch/include/hip_test_rtc.hh index 0860ae51db..0f862840bb 100644 --- a/tests/catch/include/hip_test_rtc.hh +++ b/tests/catch/include/hip_test_rtc.hh @@ -31,6 +31,7 @@ THE SOFTWARE. #include #include #include +#include #include "hip/hip_runtime_api.h" #include "hip_test_context.hh" @@ -218,7 +219,6 @@ static inline void printInfo() { template void launchRTCKernel(std::string (*getKernelName)(), dim3 numBlocks, dim3 numThreads, std::uint32_t memPerBlock, hipStream_t stream, Args&&... packedArgs) { - printInfo(); TestContext& testContext = TestContext::get(); std::string kernelName = (*getKernelName)(); @@ -226,25 +226,29 @@ void launchRTCKernel(std::string (*getKernelName)(), dim3 numBlocks, dim3 numThr std::vector kernelTypenames{std::string(HipTest::getTypeName())...}; std::string kernelExpression = reconstructExpression(kernelName, kernelTypenames); - if (testContext.getFunction(kernelExpression) == nullptr) { - hiprtcProgram rtcProgram{compileRTC(kernelName, kernelExpression)}; - std::vector compiledCode{getKernelCode(rtcProgram)}; + static std::mutex mutex{}; + { + std::lock_guard lockGuard(mutex); + if (testContext.getFunction(kernelExpression) == nullptr) { + hiprtcProgram rtcProgram{compileRTC(kernelName, kernelExpression)}; + std::vector compiledCode{getKernelCode(rtcProgram)}; - hipModule_t module; + hipModule_t module; - REQUIRE(hipSuccess == hipModuleLoadData(&module, compiledCode.data())); + REQUIRE(hipSuccess == hipModuleLoadData(&module, compiledCode.data())); hipFunction_t kernelFunction; - const char* loweredName; - REQUIRE(HIPRTC_SUCCESS == - hiprtcGetLoweredName(rtcProgram, kernelExpression.c_str(), &loweredName)); - REQUIRE(hipSuccess == hipModuleGetFunction(&kernelFunction, module, loweredName)); + const char* loweredName; + REQUIRE(HIPRTC_SUCCESS == + hiprtcGetLoweredName(rtcProgram, kernelExpression.c_str(), &loweredName)); + REQUIRE(hipSuccess == hipModuleGetFunction(&kernelFunction, module, loweredName)); - /* After obtaining the kernelFunction, the program is no longer needed. So it can be destroyed */ - REQUIRE(HIPRTC_SUCCESS == hiprtcDestroyProgram(&rtcProgram)); + /* After obtaining the kernelFunction, the program is no longer needed. So it can be destroyed */ + REQUIRE(HIPRTC_SUCCESS == hiprtcDestroyProgram(&rtcProgram)); - testContext.trackRtcState(kernelExpression, module, kernelFunction); + testContext.trackRtcState(kernelExpression, module, kernelFunction); + } } hipFunction_t kernelFunction = testContext.getFunction(kernelExpression); diff --git a/tests/catch/unit/event/Unit_hipEventRecord.cc b/tests/catch/unit/event/Unit_hipEventRecord.cc index d2f13d6e12..408f802d41 100644 --- a/tests/catch/unit/event/Unit_hipEventRecord.cc +++ b/tests/catch/unit/event/Unit_hipEventRecord.cc @@ -87,5 +87,4 @@ static_cast(A_d), static_cast(B_d), C_d, N); HIP_CHECK(hipEventDestroy(stop)); HipTest::checkVectorADD(A_h, B_h, C_h, N, true); - TestContext::get().cleanContext(); } diff --git a/tests/catch/unit/memory/hipHostMalloc.cc b/tests/catch/unit/memory/hipHostMalloc.cc index 39a2bb6719..f0b1fafe8d 100644 --- a/tests/catch/unit/memory/hipHostMalloc.cc +++ b/tests/catch/unit/memory/hipHostMalloc.cc @@ -144,7 +144,6 @@ TEST_CASE("Unit_hipHostMalloc_Basic") { HIP_CHECK(hipHostFree(A_h)); HIP_CHECK(hipHostFree(B_h)); HIP_CHECK(hipHostFree(C_h)); - TestContext::get().cleanContext(); } } /* @@ -182,7 +181,6 @@ TEST_CASE("Unit_hipHostMalloc_NonCoherent") { SYNC_STREAM, ptrType); CheckHostPointer(numElements, A, hipEventReleaseToSystem, SYNC_EVENT, ptrType); - TestContext::get().cleanContext(); } /* From 166173e12d565d78f9e4d4acc0f85a3d83c761d1 Mon Sep 17 00:00:00 2001 From: Finlay Date: Tue, 28 Jun 2022 04:31:55 +0100 Subject: [PATCH 2/7] EXSWCPHIPT-121 - hipGetSetDeviceFlags tests (#2747) --- tests/catch/unit/device/CMakeLists.txt | 5 +- .../catch/unit/device/hipGetSetDeviceFlags.cc | 147 ++++++++++++++++++ tests/catch/unit/device/hipSetDeviceFlags.cc | 73 --------- 3 files changed, 150 insertions(+), 75 deletions(-) create mode 100644 tests/catch/unit/device/hipGetSetDeviceFlags.cc delete mode 100644 tests/catch/unit/device/hipSetDeviceFlags.cc diff --git a/tests/catch/unit/device/CMakeLists.txt b/tests/catch/unit/device/CMakeLists.txt index e6d45594ea..bebee8af71 100644 --- a/tests/catch/unit/device/CMakeLists.txt +++ b/tests/catch/unit/device/CMakeLists.txt @@ -13,11 +13,12 @@ set(TEST_SRC hipGetDeviceCount.cc hipGetDeviceProperties.cc hipRuntimeGetVersion.cc - hipSetDeviceFlags.cc + hipGetSetDeviceFlags.cc hipSetGetDevice.cc hipDeviceGetUuid.cc ) hip_add_exe_to_target(NAME DeviceTest TEST_SRC ${TEST_SRC} - TEST_TARGET_NAME build_tests) + TEST_TARGET_NAME build_tests + COMPILE_OPTIONS -std=c++14) diff --git a/tests/catch/unit/device/hipGetSetDeviceFlags.cc b/tests/catch/unit/device/hipGetSetDeviceFlags.cc new file mode 100644 index 0000000000..c134a21ad0 --- /dev/null +++ b/tests/catch/unit/device/hipGetSetDeviceFlags.cc @@ -0,0 +1,147 @@ +/* +Copyright (c) 2022 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 +#include +#include +/** + * Conformance test for checking functionality of + * hipError_t hipGetDeviceFlags(unsigned int* flags); + * hipError_t hipSetDeviceFlags(unsigned flags); + * + * + * hipGetDeviceFlags and hipSetDeviceFlags tests. + * Scenario1: Validates if hipGetDeviceFlags returns hipErrorInvalidValue for flags = nullptr. + * Scenario2: Validates if hipSetDeviceFlags returns hipErrorInvalidValue for invalid flags. + * Scenario3: Validates if flags returned by hipGetDeviceFlags are valid. + * Scenario4: Validates that flags set with hipSetDeviceFlags can be retrieved with + * hipGetDeviceFlags. + * Scenario5: Validates that flags set with hipSetDeviceFlags can be retrieved on a seperate thread + * with hipGetDeviceFlags. + */ +TEST_CASE("Unit_hipGetSetDeviceFlags_NullptrFlag") { + // Scenario1 + HIP_CHECK_ERROR(hipGetDeviceFlags(nullptr), hipErrorInvalidValue); +} + +TEST_CASE("Unit_hipGetSetDeviceFlags_InvalidFlag") { +#if HT_AMD + HipTest::HIP_SKIP_TEST("EXSWCPHIPT-115"); + return; +#endif + // Scenario2 + const unsigned int invalidFlag = GENERATE(0b011, // schedule flags should not overlap + 0b101, // schedule flags should not overlap + 0b110, // schedule flags should not overlap + 0b111, // schedule flags should not overlap + 0b100000, // out of bounds + 0xFFFF); + CAPTURE(invalidFlag); + HIP_CHECK_ERROR(hipSetDeviceFlags(invalidFlag), hipErrorInvalidValue); +} + +std::array getValidFlags() { + constexpr std::array scheduleFlags{hipDeviceScheduleAuto, hipDeviceScheduleSpin, + hipDeviceScheduleYield, + hipDeviceScheduleBlockingSync}; + constexpr std::array hostMapFlags{0, hipDeviceMapHost}; + constexpr std::array localMemResizeFlags{0, 0x10}; // FIXME EXSWCPHIPT-110 + constexpr size_t size = scheduleFlags.size() * hostMapFlags.size() * localMemResizeFlags.size(); + std::array validFlags; + int i = 0; + for (auto sf : scheduleFlags) { + for (auto hf : hostMapFlags) { + for (auto lf : localMemResizeFlags) { + validFlags[i] = sf | hf | lf; + i += 1; + } + } + } + return validFlags; +} + + +TEST_CASE("Unit_hipGetSetDeviceFlags_ValidFlag") { + // Scenario3 + auto validFlags = getValidFlags(); + + unsigned int flag = 0; + HIP_CHECK(hipGetDeviceFlags(&flag)); + REQUIRE(std::find(std::begin(validFlags), std::end(validFlags), flag) != std::end(validFlags)); +} + +TEST_CASE("Unit_hipGetSetDeviceFlags_SetThenGet") { + // Scenario4 + auto validFlags = getValidFlags(); + + auto devNo = GENERATE(range(0, HipTest::getDeviceCount())); + HIP_CHECK(hipSetDevice(devNo)); + + const unsigned int flag = GENERATE_COPY(from_range(std::begin(validFlags), std::end(validFlags))); + HIP_CHECK(hipSetDeviceFlags(flag)); + + unsigned int getFlag; + HIP_CHECK(hipGetDeviceFlags(&getFlag)); +// flags other than hipDeviceSchedule* are ignore on the ROCm backend +#if HT_NVIDIA + // CUDA backend will sometimes set other flags + getFlag = getFlag & hipDeviceScheduleMask; +#endif + REQUIRE((flag & hipDeviceScheduleMask) == getFlag); +} + +TEST_CASE("Unit_hipGetSetDeviceFlags_Threaded") { + // Scenario5 + auto validFlags = getValidFlags(); + + auto devNo = GENERATE(range(0, HipTest::getDeviceCount())); + HIP_CHECK(hipSetDevice(devNo)); + + std::mutex mut; + std::condition_variable cv; + bool ready = false; // required to avoid spurious wakeups + + const unsigned int flag = GENERATE_COPY(from_range(std::begin(validFlags), std::end(validFlags))); + std::thread test_thread([&mut, &ready, &cv, devNo, flag]() { + std::unique_lock lock(mut); + cv.wait(lock, [&ready] { return ready; }); + unsigned int getFlag; + HIP_CHECK_THREAD(hipSetDevice(devNo)); + HIP_CHECK_THREAD(hipGetDeviceFlags(&getFlag)); +// flags other than hipDeviceSchedule* are ignore on the ROCm backend +#if HT_NVIDIA + // CUDA backend will set other flags we aren't concerned about + getFlag = getFlag & hipDeviceScheduleMask; +#endif + REQUIRE_THREAD((flag & hipDeviceScheduleMask) == getFlag); + }); + + { + std::lock_guard lock(mut); + HIP_CHECK(hipSetDeviceFlags(flag)); + ready = true; + } + + cv.notify_one(); + + test_thread.join(); + HIP_CHECK_THREAD_FINALIZE(); +} diff --git a/tests/catch/unit/device/hipSetDeviceFlags.cc b/tests/catch/unit/device/hipSetDeviceFlags.cc deleted file mode 100644 index 9d6c1b6bc2..0000000000 --- a/tests/catch/unit/device/hipSetDeviceFlags.cc +++ /dev/null @@ -1,73 +0,0 @@ -/* -Copyright (c) 2021 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 -/* - * Conformance test for checking functionality of - * hipError_t hipGetDeviceFlags(unsigned int* flags); - * hipError_t hipSetDeviceFlags(unsigned flags); - */ -/** - * hipGetDeviceFlags and hipSetDeviceFlags tests. - * Scenario1: Validates if hipGetDeviceFlags returns hip error code for - * flags = nullptr. - * Scenario2: Validates if hipSetDeviceFlags returns hip error code for - * invalid flag. - * Scenario3: Validates if flags = hipDeviceScheduleSpin|hipDeviceScheduleYield - * |hipDeviceScheduleBlockingSync|hipDeviceScheduleAuto|hipDeviceMapHost - * |hipDeviceLmemResizeToMax returned by hipGetDeviceFlags. - */ -TEST_CASE("Unit_hipGetDeviceFlags_NegTst") { - // Scenario1 - SECTION("flags is nullptr") { - REQUIRE_FALSE(hipSuccess == hipGetDeviceFlags(nullptr)); - } - - // Scenario2 - SECTION("flags value is invalid") { - REQUIRE_FALSE(hipSuccess == hipSetDeviceFlags(0xffff)); - } -} - - -TEST_CASE("Unit_hipGetDeviceFlags_FuncTst") { - unsigned flag = 0; - - // Scenario3 - SECTION("Check flag value") { - HIP_CHECK(hipGetDeviceFlags(&flag)); - bool checkFlg = false; - checkFlg = ((flag != hipDeviceScheduleSpin) && - (flag != hipDeviceScheduleYield) && - (flag != hipDeviceScheduleBlockingSync) && - (flag != hipDeviceScheduleAuto) && - (flag != hipDeviceMapHost) && - (flag != hipDeviceLmemResizeToMax)); - REQUIRE_FALSE(checkFlg); - } - - SECTION("Set flag value") { - auto devNo = GENERATE(range(0, HipTest::getDeviceCount())); - flag = 0; - HIP_CHECK(hipSetDevice(devNo)); - auto bitmap = GENERATE(range(0, 4)); - flag = 1 << bitmap; - HIP_CHECK(hipSetDeviceFlags(flag)); - } -} From e09f0792c3cb443719b1cbb541dc8b33033246b8 Mon Sep 17 00:00:00 2001 From: Jatin Chaudhary Date: Tue, 28 Jun 2022 04:33:03 +0100 Subject: [PATCH 3/7] EXSWCPHIPT-124 - Add tests for hipDeviceTotalMem (#2749) --- tests/catch/unit/device/hipDeviceTotalMem.cc | 35 +++++++++++++++++--- 1 file changed, 30 insertions(+), 5 deletions(-) diff --git a/tests/catch/unit/device/hipDeviceTotalMem.cc b/tests/catch/unit/device/hipDeviceTotalMem.cc index d5b153ae28..6812b37873 100644 --- a/tests/catch/unit/device/hipDeviceTotalMem.cc +++ b/tests/catch/unit/device/hipDeviceTotalMem.cc @@ -37,13 +37,13 @@ TEST_CASE("Unit_hipDeviceTotalMem_NegTst") { #endif // Scenario 1 SECTION("bytes is nullptr") { - REQUIRE_FALSE(hipDeviceTotalMem(nullptr, 0) == hipSuccess); + HIP_CHECK_ERROR(hipDeviceTotalMem(nullptr, 0), hipErrorInvalidValue); } size_t totMem; // Scenario 2 SECTION("device is -1") { - REQUIRE_FALSE(hipDeviceTotalMem(&totMem, -1) == hipSuccess); + HIP_CHECK_ERROR(hipDeviceTotalMem(&totMem, -1), hipErrorInvalidDevice); } // Scenario 3 @@ -51,14 +51,14 @@ TEST_CASE("Unit_hipDeviceTotalMem_NegTst") { int numDevices; HIP_CHECK(hipGetDeviceCount(&numDevices)); size_t totMem; - REQUIRE_FALSE(hipDeviceTotalMem(&totMem, numDevices) == hipSuccess); + HIP_CHECK_ERROR(hipDeviceTotalMem(&totMem, numDevices), hipErrorInvalidDevice); } } // Scenario 4 TEST_CASE("Unit_hipDeviceTotalMem_ValidateTotalMem") { size_t totMem; - int numDevices; + int numDevices = 0; HIP_CHECK(hipGetDeviceCount(&numDevices)); REQUIRE(numDevices != 0); @@ -70,5 +70,30 @@ TEST_CASE("Unit_hipDeviceTotalMem_ValidateTotalMem") { HIP_CHECK(hipDeviceGet(&device, devNo)); HIP_CHECK(hipGetDeviceProperties(&prop, device)); HIP_CHECK(hipDeviceTotalMem(&totMem, device)); - REQUIRE_FALSE(totMem != prop.totalGlobalMem); + + size_t free = 0, total = 0; + HIP_CHECK(hipMemGetInfo(&free, &total)); + + REQUIRE(totMem == prop.totalGlobalMem); + REQUIRE(total == totMem); +} + +TEST_CASE("Unit_hipDeviceTotalMem_NonSelectedDevice") { + auto deviceCount = HipTest::getDeviceCount(); + if (deviceCount < 2) { + HipTest::HIP_SKIP_TEST("Multi Device Test, will not run on single gpu systems. Skipping."); + return; + } + + for (int i = 1; i < deviceCount; i++) { + HIP_CHECK(hipSetDevice(i - 1)); + hipDevice_t device; + HIP_CHECK(hipDeviceGet(&device, i)); + + size_t totMem = 0; + hipDeviceProp_t prop; + HIP_CHECK(hipDeviceTotalMem(&totMem, device)); + HIP_CHECK(hipGetDeviceProperties(&prop, device)); + REQUIRE(totMem == prop.totalGlobalMem); + } } From 329616bfd4cc818b50e573b0e9e739f2eca9b278 Mon Sep 17 00:00:00 2001 From: ROCm CI Service Account <66695075+rocm-ci@users.noreply.github.com> Date: Tue, 28 Jun 2022 22:36:30 +0530 Subject: [PATCH 4/7] SWDEV-327563 - Windows: Enable skipped tests (#2773) Change-Id: I091ca7e98dc6339853f955725c9cf3b485b2e44d --- .../config/config_amd_windows.json | 33 ------------------- 1 file changed, 33 deletions(-) diff --git a/tests/catch/hipTestMain/config/config_amd_windows.json b/tests/catch/hipTestMain/config/config_amd_windows.json index da44fdae25..2d92fd5752 100644 --- a/tests/catch/hipTestMain/config/config_amd_windows.json +++ b/tests/catch/hipTestMain/config/config_amd_windows.json @@ -1,45 +1,14 @@ { "DisabledTests": [ - "Unit_hipMemcpy3D_Basic - int", - "Unit_hipMemcpy3D_Basic - unsigned int", - "Unit_hipMemcpy3D_Basic - float", - "Unit_hipMemcpy3DAsync_Basic - int", - "Unit_hipMemcpy3DAsync_Basic - unsigned int", - "Unit_hipMemcpy3DAsync_Basic - float", - "Unit_hipMemcpy3DAsync_multiDevice-Negative", - "Unit_hipMemcpy3DAsync_multiDevice-DiffStream", - "Unit_hipPointerGetAttributes_ClusterAlloc", - "Unit_hipMallocManaged_MultiChunkMultiDevice", - "Unit_hipMallocManaged_TwoPointers - int", - "Unit_hipMallocManaged_TwoPointers - float", - "Unit_hipMallocManaged_TwoPointers - double", - "Unit_hipMallocManaged_DeviceContextChange - unsigned char", - "Unit_hipMallocManaged_DeviceContextChange - int", - "Unit_hipMallocManaged_DeviceContextChange - float", - "Unit_hipMallocManaged_DeviceContextChange - double", - "Unit_hipHostMalloc_CoherentTst", - "Unit_hipMallocManaged_CoherentTst", - "Unit_hipMallocManaged_CoherentTstWthAdvise", "Unit_hipMalloc_CoherentTst", - "Unit_hipExtMallocWithFlags_CoherentTst", "Unit_printf_flags", "Unit_printf_specifier", - "Unit_hipTextureObj2D_Check", "Unit_hipTextureMipmapObj2D_Check", - "Unit_hipStreamPerThread_DeviceReset_1", - "Unit_hipStreamPerThread_DeviceReset_2", "Unit_hipManagedKeyword_MultiGpu", "Unit_hipGraphAddHostNode_ClonedGraphwithHostNode", "Unit_hipGraphAddChildGraphNode_OrgGraphAsChildGraph", "Unit_hipGraphAddChildGraphNode_SingleChildNode", - "Unit_hipPtrGetAttribute_Simple", - "Unit_hipStreamCreateWithPriority_ValidateWithEvents", - "Unit_hipEvent", - "Unit_hipHostMalloc_NonCoherent", - "Unit_hipHostMalloc_Coherent", - "Unit_hipHostMalloc_Default", - "Unit_hipStreamCreate_MultistreamBasicFunctionalities", "Unit_hipEventIpc", "Unit_hipMalloc3D_Negative", "Unit_hipPointerGetAttribute_MappedMem", @@ -51,8 +20,6 @@ "Unit_hipStreamGetCaptureInfo_hipStreamPerThread", "Unit_hipStreamGetCaptureInfo_UniqueID", "Unit_hipStreamGetCaptureInfo_ArgValidation", - "# Following test is related to ticket EXSWCPHIPT-41", - "Unit_hipStreamGetPriority_happy", "Unit_hipMemPoolApi_Basic", "Unit_hipMemPoolApi_BasicAlloc", "Unit_hipMemPoolApi_BasicTrim", From 7c306091bfcdbb97e695e9abcbae077ae24fb36d Mon Sep 17 00:00:00 2001 From: ROCm CI Service Account <66695075+rocm-ci@users.noreply.github.com> Date: Tue, 28 Jun 2022 23:16:47 +0530 Subject: [PATCH 5/7] SWDEV-342025 - Update API documentation for hipEventCreateWithFlags (#2774) - Add information that hipEventDisableTiming flag also must be set when hipEventInterprocess flag is set Change-Id: Ic65bcc2258c1bacf870251383e5cf3c1e0e0c0c8 --- include/hip/hip_runtime_api.h | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/include/hip/hip_runtime_api.h b/include/hip/hip_runtime_api.h index 2ac304df2f..c6706024bc 100644 --- a/include/hip/hip_runtime_api.h +++ b/include/hip/hip_runtime_api.h @@ -574,7 +574,7 @@ enum hipLimit_t { /** Disable event's capability to record timing information. May improve performance.*/ #define hipEventDisableTiming 0x2 -/** Event can support IPC. Warnig: It is not supported in HIP.*/ +/** Event can support IPC. hipEventDisableTiming also must be set.*/ #define hipEventInterprocess 0x4 /** Use a device-scope release when recording this event. This flag is useful to obtain more @@ -1713,13 +1713,13 @@ hipError_t hipIpcCloseMemHandle(void* devPtr); /** * @brief Gets an opaque interprocess handle for an event. * - * This opaque handle may be copied into other processes and opened with cudaIpcOpenEventHandle. - * Then cudaEventRecord, cudaEventSynchronize, cudaStreamWaitEvent and cudaEventQuery may be used in + * This opaque handle may be copied into other processes and opened with hipIpcOpenEventHandle. + * Then hipEventRecord, hipEventSynchronize, hipStreamWaitEvent and hipEventQuery may be used in * either process. Operations on the imported event after the exported event has been freed with hipEventDestroy * will result in undefined behavior. * - * @param[out] handle Pointer to cudaIpcEventHandle to return the opaque event handle - * @param[in] event Event allocated with cudaEventInterprocess and cudaEventDisableTiming flags + * @param[out] handle Pointer to hipIpcEventHandle to return the opaque event handle + * @param[in] event Event allocated with hipEventInterprocess and hipEventDisableTiming flags * * @returns #hipSuccess, #hipErrorInvalidConfiguration, #hipErrorInvalidValue * @@ -2227,8 +2227,8 @@ hipError_t hipStreamWriteValue64(hipStream_t stream, void* ptr, uint64_t value, for the synchroniation but can result in lower power and more resources for other CPU threads. * #hipEventDisableTiming : Disable recording of timing information. Events created with this flag would not record profiling data and provide best performance if used for synchronization. - * @warning On AMD platform, hipEventInterprocess support is under development. Use of this flag - will return an error. + * #hipEventInterprocess : The event can be used as an interprocess event. hipEventDisableTiming + flag also must be set when hipEventInterprocess flag is set. * * @returns #hipSuccess, #hipErrorNotInitialized, #hipErrorInvalidValue, #hipErrorLaunchFailure, #hipErrorOutOfMemory From 88d9a0e7aeb251fe0ed069bf200a1cd8203875b9 Mon Sep 17 00:00:00 2001 From: ROCm CI Service Account <66695075+rocm-ci@users.noreply.github.com> Date: Tue, 28 Jun 2022 23:42:45 +0530 Subject: [PATCH 6/7] SWDEV-336547 - SWDEV-336548 - SWDEV-336549 - Add test cases for hipArray (#2759) Change-Id: I125b6c50cb6fa3ec5b2e06c4f491d759334a867d --- tests/catch/unit/memory/CMakeLists.txt | 1 + tests/catch/unit/memory/hipArray.cc | 76 ++++++++++++++++++++++++++ 2 files changed, 77 insertions(+) create mode 100644 tests/catch/unit/memory/hipArray.cc diff --git a/tests/catch/unit/memory/CMakeLists.txt b/tests/catch/unit/memory/CMakeLists.txt index fb5c5677e6..af72155549 100644 --- a/tests/catch/unit/memory/CMakeLists.txt +++ b/tests/catch/unit/memory/CMakeLists.txt @@ -84,6 +84,7 @@ set(TEST_SRC hipDrvPtrGetAttributes.cc hipMallocMngdMultiThread.cc hipMemPrefetchAsync.cc + hipArray.cc ) else() set(TEST_SRC diff --git a/tests/catch/unit/memory/hipArray.cc b/tests/catch/unit/memory/hipArray.cc new file mode 100644 index 0000000000..3afab53cfc --- /dev/null +++ b/tests/catch/unit/memory/hipArray.cc @@ -0,0 +1,76 @@ +/* +Copyright (c) 2022 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 +TEST_CASE("Unit_hipArray_Valid") { + hipArray* array = nullptr; + HIP_ARRAY_DESCRIPTOR desc; + desc.Format = HIP_AD_FORMAT_FLOAT; + desc.NumChannels = 1; + desc.Width = 1024; + desc.Height = 1024; + HIP_CHECK(hipArrayCreate(&array, &desc)); + HIP_CHECK(hipFreeArray(array)); +} +TEST_CASE("Unit_hipArray_Invalid") { + void* data = malloc(sizeof(char)); + hipArray_t arrayPtr = static_cast(data); + REQUIRE(hipFreeArray(arrayPtr) == hipErrorContextIsDestroyed); + free(data); +} +TEST_CASE("Unit_hipArray_Nullptr") { + hipArray* array = nullptr; + REQUIRE(hipFreeArray(array) == hipErrorInvalidValue); +} +TEST_CASE("Unit_hipArray_DoubleFree") { + hipArray* array = nullptr; + HIP_ARRAY_DESCRIPTOR desc; + desc.Format = HIP_AD_FORMAT_FLOAT; + desc.NumChannels = 1; + desc.Width = 1024; + desc.Height = 1024; + HIP_CHECK(hipArrayCreate(&array, &desc)); + HIP_CHECK(hipFreeArray(array)); + REQUIRE(hipFreeArray(array) == hipErrorContextIsDestroyed); +} +TEST_CASE("Unit_hipArray_TrippleDestroy") { + hipArray* array = nullptr; + HIP_ARRAY_DESCRIPTOR desc; + desc.Format = HIP_AD_FORMAT_FLOAT; + desc.NumChannels = 1; + desc.Width = 1024; + desc.Height = 1024; + HIP_CHECK(hipArrayCreate(&array, &desc)); + HIP_CHECK(hipArrayDestroy(array)); + REQUIRE(hipArrayDestroy(array) == hipErrorContextIsDestroyed); + REQUIRE(hipArrayDestroy(array) == hipErrorContextIsDestroyed); +} +TEST_CASE("Unit_hipArray_DoubleNullptr") { + hipArray* array = nullptr; + REQUIRE(hipFreeArray(array) == hipErrorInvalidValue); + REQUIRE(hipFreeArray(array) == hipErrorInvalidValue); +} +TEST_CASE("Unit_hipArray_DoubleInvalid") { + void* data = malloc(sizeof(char)); + hipArray_t arrayPtr = static_cast(data); + REQUIRE(hipFreeArray(arrayPtr) == hipErrorContextIsDestroyed); + REQUIRE(hipFreeArray(arrayPtr) == hipErrorContextIsDestroyed); + free(data); +} + + From 60b60f78e6b8ed3fb2e64388b5f27771a16673e8 Mon Sep 17 00:00:00 2001 From: ROCm CI Service Account <66695075+rocm-ci@users.noreply.github.com> Date: Wed, 29 Jun 2022 02:06:26 +0530 Subject: [PATCH 7/7] SWDEV-339742 - Check can access before set device to 1. (#2758) Change-Id: I5b06f98b0061ee162488e288c3bfac09ff4f94cf --- tests/catch/unit/memory/hipPtrGetAttribute.cc | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/tests/catch/unit/memory/hipPtrGetAttribute.cc b/tests/catch/unit/memory/hipPtrGetAttribute.cc index 99dbc5ab8d..eaf4c8b153 100644 --- a/tests/catch/unit/memory/hipPtrGetAttribute.cc +++ b/tests/catch/unit/memory/hipPtrGetAttribute.cc @@ -122,10 +122,14 @@ TEST_CASE("Unit_hipPtrGetAttribute_Simple") { // HIP_POINTER_ATTRIBUTE_DEVICE_ORDINAL if (numDevices > 1) { - HIP_CHECK(hipSetDevice(1)); - HIP_CHECK(hipPointerGetAttribute(&datatype, HIP_POINTER_ATTRIBUTE_DEVICE_ORDINAL, - reinterpret_cast(A_d))); - REQUIRE(datatype == 0); + int canAccess = -1; + HIP_CHECK(hipDeviceCanAccessPeer(&canAccess, 1, 0)); + if (canAccess == 1) { + HIP_CHECK(hipSetDevice(1)); + HIP_CHECK(hipPointerGetAttribute(&datatype, HIP_POINTER_ATTRIBUTE_DEVICE_ORDINAL, + reinterpret_cast(A_d))); + REQUIRE(datatype == 0); + } } // HIP_POINTER_ATTRIBUTE_MAPPED