SWDEV-388833 - [catch2][dtest] p2p tests migrated from dtests to catch2
Recreation of github PR https://github.com/ROCm-Developer-Tools/hip-tests/pull/319, Change-Id: I6024fd5172a9765756938601a30ed0469b5f1d5b
このコミットが含まれているのは:
@@ -16,7 +16,6 @@ set(TEST_SRC
|
||||
hipGetSetDeviceFlags.cc
|
||||
hipSetGetDevice.cc
|
||||
hipDeviceGetUuid.cc
|
||||
hipDeviceGetP2PAttribute.cc
|
||||
hipDeviceGetDefaultMemPool.cc
|
||||
hipDeviceCanAccessPeer.cc
|
||||
hipDeviceEnableDisablePeerAccess.cc
|
||||
@@ -38,10 +37,8 @@ if(UNIX)
|
||||
endif()
|
||||
|
||||
set_source_files_properties(hipGetDeviceCount.cc PROPERTIES COMPILE_FLAGS -std=c++17)
|
||||
set_source_files_properties(hipDeviceGetP2PAttribute.cc PROPERTIES COMPILE_FLAGS -std=c++17)
|
||||
|
||||
add_executable(getDeviceCount EXCLUDE_FROM_ALL getDeviceCount_exe.cc)
|
||||
add_executable(hipDeviceGetP2PAttribute_exe EXCLUDE_FROM_ALL hipDeviceGetP2PAttribute_exe.cc)
|
||||
|
||||
hip_add_exe_to_target(NAME DeviceTest
|
||||
TEST_SRC ${TEST_SRC}
|
||||
@@ -49,4 +46,3 @@ hip_add_exe_to_target(NAME DeviceTest
|
||||
COMPILE_OPTIONS -std=c++17)
|
||||
|
||||
add_dependencies(build_tests getDeviceCount)
|
||||
add_dependencies(build_tests hipDeviceGetP2PAttribute_exe)
|
||||
|
||||
@@ -1,177 +0,0 @@
|
||||
/*
|
||||
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 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 <cstdlib>
|
||||
#include <hip_test_common.hh>
|
||||
#include <hip_test_helper.hh>
|
||||
#include "hip/hip_runtime_api.h"
|
||||
#include <hip_test_process.hh>
|
||||
#include <string>
|
||||
|
||||
/**
|
||||
* @addtogroup hipDeviceGetP2PAttribute hipDeviceGetP2PAttribute
|
||||
* @{
|
||||
* @ingroup DriverTest
|
||||
* `hipDeviceGetP2PAttribute(int* value, hipDeviceP2PAttr attr,
|
||||
* int srcDevice, int dstDevice)` -
|
||||
* Returns a value for attr of link between two devices.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Test Description
|
||||
* ------------------------
|
||||
* - Get all possible combinations of attributes between all pairs of devices.
|
||||
* Test source
|
||||
* ------------------------
|
||||
* - unit/device/hipDeviceGetP2PAttribute.cc
|
||||
* Test requirements
|
||||
* ------------------------
|
||||
* - HIP_VERSION >= 5.2
|
||||
*/
|
||||
TEST_CASE("Unit_hipDeviceGetP2PAttribute_Basic") {
|
||||
#if HT_AMD
|
||||
HipTest::HIP_SKIP_TEST("EXSWCPHIPT-119");
|
||||
return;
|
||||
#else
|
||||
|
||||
int deviceCount = HipTest::getGeviceCount();
|
||||
if (deviceCount < 2) {
|
||||
HipTest::HIP_SKIP_TEST("Skipping because devices < 2");
|
||||
return;
|
||||
}
|
||||
|
||||
hipDeviceP2PAttr attribute =
|
||||
GENERATE(hipDevP2PAttrPerformanceRank, hipDevP2PAttrAccessSupported,
|
||||
hipDevP2PAttrNativeAtomicSupported, hipDevP2PAttrHipArrayAccessSupported);
|
||||
|
||||
/* Test all combinations of devices in the system */
|
||||
for (int srcDevice = 0; srcDevice < deviceCount; ++srcDevice) {
|
||||
for (int dstDevice = 0; dstDevice < deviceCount; ++dstDevice) {
|
||||
if (srcDevice != dstDevice) {
|
||||
int value{-1};
|
||||
HIP_CHECK(hipDeviceGetP2PAttribute(&value, attribute, srcDevice, dstDevice));
|
||||
INFO("hipDeviceP2PAttr: " << attribute << "\nsrcDevice: " << srcDevice
|
||||
<< "\ndstDevice: " << dstDevice << "\nValue: " << value);
|
||||
if (attribute == hipDevP2PAttrPerformanceRank) {
|
||||
REQUIRE(value >= 0);
|
||||
} else {
|
||||
REQUIRE((value == 0 || value == 1));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* Test Description
|
||||
* ------------------------
|
||||
* - Verifies handling of invalid arguments:
|
||||
* -# When output pointer to the value is `nullptr`
|
||||
* - Expected output: return `hipErrorInvalidValue`
|
||||
* -# When attribute is invalid, out of bounds
|
||||
* - Expected output: return `hipErrorInvalidValue`
|
||||
* -# When device ordinal is negative (-1)
|
||||
* - Expected output: return `hipErrorInvalidDevice`
|
||||
* -# When device ordinal is out of bounds
|
||||
* - Expected output: return `hipErrorInvalidDevice`
|
||||
* -# When the src and dst devices are the same one
|
||||
* - Expected output: return `hipErrorInvalidDevice`
|
||||
* -# When some devices are hidden using environment variables
|
||||
* - Expected output: different scenarios produce different return value
|
||||
* Test source
|
||||
* ------------------------
|
||||
* - unit/device/hipDeviceGetP2PAttribute.cc
|
||||
* Test requirements
|
||||
* ------------------------
|
||||
* - Platform specific (NVIDIA)
|
||||
* - HIP_VERSION >= 5.2
|
||||
*/
|
||||
TEST_CASE("Unit_hipDeviceGetP2PAttribute_Negative") {
|
||||
#if HT_AMD
|
||||
HipTest::HIP_SKIP_TEST("EXSWCPHIPT-122");
|
||||
return;
|
||||
#else
|
||||
|
||||
int deviceCount = HipTest::getGeviceCount();
|
||||
if (deviceCount < 2) {
|
||||
HipTest::HIP_SKIP_TEST("Skipping because devices < 2");
|
||||
return;
|
||||
}
|
||||
|
||||
int value;
|
||||
int validSrcDevice = 0;
|
||||
int validDstDevice = 1;
|
||||
hipDeviceP2PAttr validAttr = hipDevP2PAttrAccessSupported;
|
||||
|
||||
SECTION("Nullptr value") {
|
||||
HIP_CHECK_ERROR(hipDeviceGetP2PAttribute(nullptr, validAttr, validSrcDevice, validDstDevice),
|
||||
hipErrorInvalidValue);
|
||||
}
|
||||
|
||||
SECTION("Invalid attribute") {
|
||||
hipDeviceP2PAttr invalidAttr = static_cast<hipDeviceP2PAttr>(10);
|
||||
HIP_CHECK_ERROR(hipDeviceGetP2PAttribute(&value, invalidAttr, validSrcDevice, validDstDevice),
|
||||
hipErrorInvalidValue);
|
||||
}
|
||||
|
||||
SECTION("Device is -1") {
|
||||
int invalidDevice = -1;
|
||||
HIP_CHECK_ERROR(hipDeviceGetP2PAttribute(&value, validAttr, invalidDevice, validDstDevice),
|
||||
hipErrorInvalidDevice);
|
||||
HIP_CHECK_ERROR(hipDeviceGetP2PAttribute(&value, validAttr, validSrcDevice, invalidDevice),
|
||||
hipErrorInvalidDevice);
|
||||
}
|
||||
|
||||
SECTION("Device is out of bounds") {
|
||||
int deviceCount = 0;
|
||||
HIP_CHECK(hipGetDeviceCount(&deviceCount));
|
||||
REQUIRE_FALSE(deviceCount == 0);
|
||||
|
||||
HIP_CHECK_ERROR(hipDeviceGetP2PAttribute(&value, validAttr, deviceCount, validDstDevice),
|
||||
hipErrorInvalidDevice);
|
||||
HIP_CHECK_ERROR(hipDeviceGetP2PAttribute(&value, validAttr, validSrcDevice, deviceCount),
|
||||
hipErrorInvalidDevice);
|
||||
}
|
||||
|
||||
SECTION("Source and destination devices are the same") {
|
||||
HIP_CHECK_ERROR(hipDeviceGetP2PAttribute(&value, validAttr, validSrcDevice, validSrcDevice),
|
||||
hipErrorInvalidDevice);
|
||||
}
|
||||
|
||||
/* https://docs.nvidia.com/cuda/cuda-c-programming-guide/index.html#env-vars */
|
||||
SECTION("Hidden devices using environment variables") {
|
||||
REQUIRE(hip::SpawnProc("hipDeviceGetP2PAttribute_exe").run("") == hipSuccess);
|
||||
REQUIRE(hip::SpawnProc("hipDeviceGetP2PAttribute_exe").run("0") == hipErrorInvalidDevice);
|
||||
REQUIRE(hip::SpawnProc("hipDeviceGetP2PAttribute_exe").run("1") == hipErrorInvalidDevice);
|
||||
REQUIRE(hip::SpawnProc("hipDeviceGetP2PAttribute_exe").run("0,1") == hipSuccess);
|
||||
REQUIRE(hip::SpawnProc("hipDeviceGetP2PAttribute_exe").run("-1,0") == hipErrorNoDevice);
|
||||
REQUIRE(hip::SpawnProc("hipDeviceGetP2PAttribute_exe").run("0,-1") == hipErrorInvalidDevice);
|
||||
REQUIRE(hip::SpawnProc("hipDeviceGetP2PAttribute_exe").run("0,1,-1") == hipSuccess);
|
||||
REQUIRE(hip::SpawnProc("hipDeviceGetP2PAttribute_exe").run("0,-1,1") == hipErrorInvalidDevice);
|
||||
|
||||
if (deviceCount > 2) {
|
||||
REQUIRE(hip::SpawnProc("hipDeviceGetP2PAttribute_exe").run("2,1") == hipSuccess);
|
||||
REQUIRE(hip::SpawnProc("hipDeviceGetP2PAttribute_exe").run("2") == hipErrorInvalidDevice);
|
||||
} else {
|
||||
REQUIRE(hip::SpawnProc("hipDeviceGetP2PAttribute_exe").run("2,1") == hipErrorNoDevice);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -1,86 +0,0 @@
|
||||
/*
|
||||
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 <hip/hip_runtime.h>
|
||||
#include "hip/hip_runtime_api.h"
|
||||
#include <hip_test_context.hh>
|
||||
#include <stdlib.h>
|
||||
|
||||
bool UNSETENV(std::string var) {
|
||||
int result = -1;
|
||||
#ifdef __unix__
|
||||
result = unsetenv(var.c_str());
|
||||
#else
|
||||
result = _putenv((var + '=').c_str());
|
||||
#endif
|
||||
return (result == 0) ? true: false;
|
||||
}
|
||||
|
||||
bool SETENV(std::string var, std::string value) {
|
||||
int result = -1;
|
||||
#ifdef __unix__
|
||||
result = setenv(var.c_str(), value.c_str(), 1);
|
||||
#else
|
||||
result = _putenv((var + '=' + value).c_str());
|
||||
#endif
|
||||
return (result == 0) ? true: false;
|
||||
}
|
||||
|
||||
void inline hideDevices(const char* devices) {
|
||||
#if HT_NVIDIA
|
||||
SETENV("CUDA_VISIBLE_DEVICES", devices);
|
||||
#else
|
||||
SETENV("HIP_VISIBLE_DEVICES", devices);
|
||||
SETENV("ROCR_VISIBLE_DEVICES", devices);
|
||||
#endif
|
||||
}
|
||||
|
||||
void inline unhideAllDevices() {
|
||||
#if HT_NVIDIA
|
||||
UNSETENV("CUDA_VISIBLE_DEVICES");
|
||||
#else
|
||||
UNSETENV("HIP_VISIBLE_DEVICES");
|
||||
UNSETENV("ROCR_VISIBLE_DEVICES");
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Runs hipDeviceGetP2PAttribute with srcDevice = 0 and dstDevice = 1
|
||||
* Expects 1 command line arg, which is the Device Visible String
|
||||
*
|
||||
* @return the error code returned by hipDeviceGetP2PAttribute
|
||||
*/
|
||||
int main(int argc, char** argv) {
|
||||
int value;
|
||||
const int srcDevice = 0;
|
||||
const int dstDevice = 1;
|
||||
const hipDeviceP2PAttr validAttr = hipDevP2PAttrAccessSupported;
|
||||
|
||||
if (argc == 2) {
|
||||
hideDevices(argv[1]);
|
||||
}
|
||||
|
||||
hipError_t error = hipDeviceGetP2PAttribute(&value, validAttr, srcDevice, dstDevice);
|
||||
|
||||
if (argc == 2) {
|
||||
unhideAllDevices();
|
||||
}
|
||||
|
||||
return error;
|
||||
}
|
||||
新しいイシューから参照
ユーザーをブロックする