SWDEV-378057 - [catch2][dtest] Test cases for hipStreamGetDevice API (#223)
Change-Id: I456e32bfaaa1b284c590015e3319c49e47236f71
[ROCm/hip-tests commit: eea59ab941]
Цей коміт міститься в:
зафіксовано
GitHub
джерело
ef76581b13
коміт
7ab638c564
@@ -17,25 +17,68 @@ OUT OF OR INN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <hip_test_kernels.hh>
|
||||
#include <hip_test_common.hh>
|
||||
#include <hip_test_checkers.hh>
|
||||
#include <hip_test_defgroups.hh>
|
||||
#define NUMBER_OF_THREADS 10
|
||||
static bool thread_results[NUMBER_OF_THREADS];
|
||||
|
||||
/**
|
||||
* @addtogroup hipStreamGetDevice hipStreamGetDevice
|
||||
* @{
|
||||
* @ingroup StreamTest
|
||||
* `hipError_t hipStreamGetDevice(hipStream_t stream, hipDevice_t* device)` -
|
||||
* Get the device assocaited with the stream.
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* Test Description
|
||||
* ------------------------
|
||||
* - NegativeTest case.
|
||||
* Pass device as nullptr and verify hipErrorInvalidValue
|
||||
* Pass stream as nullptr and verify hipErrorInvalidValue
|
||||
* Pass device as nullptr for hipStreamPerThread and verify hipErrorInvalidValue
|
||||
|
||||
* Test source
|
||||
* ------------------------
|
||||
* - catch/unit/stream/hipStreamGetDevice.cc
|
||||
* Test requirements
|
||||
* ------------------------
|
||||
* - HIP_VERSION >= 5.6
|
||||
*/
|
||||
|
||||
TEST_CASE("Unit_hipStreamGetDevice_Negative") {
|
||||
hipStream_t stream;
|
||||
|
||||
HIP_CHECK(hipStreamCreate(&stream));
|
||||
HIP_CHECK_ERROR(hipStreamGetDevice(nullptr, nullptr), hipErrorInvalidValue); // null stream
|
||||
HIP_CHECK_ERROR(hipStreamGetDevice(nullptr, nullptr), hipErrorInvalidValue);
|
||||
HIP_CHECK_ERROR(hipStreamGetDevice(hipStreamPerThread, nullptr),
|
||||
hipErrorInvalidValue); // stream per thread
|
||||
HIP_CHECK_ERROR(hipStreamGetDevice(stream, nullptr), hipErrorInvalidValue); // created stream
|
||||
hipErrorInvalidValue);
|
||||
HIP_CHECK_ERROR(hipStreamGetDevice(stream, nullptr), hipErrorInvalidValue);
|
||||
HIP_CHECK(hipStreamDestroy(stream));
|
||||
}
|
||||
|
||||
// Iterate over all devices, create stream on the device and match the device we get from stream
|
||||
/**
|
||||
* Test Description
|
||||
* ------------------------
|
||||
* - NegativeTest case.
|
||||
* Test case to validate hipStreamGetDevice on user created stream,
|
||||
* Null stream and hipStreamPerThread.
|
||||
|
||||
* Test source
|
||||
* ------------------------
|
||||
* - catch/unit/stream/hipStreamGetDevice.cc
|
||||
* Test requirements
|
||||
* ------------------------
|
||||
* - HIP_VERSION >= 5.6
|
||||
*/
|
||||
|
||||
TEST_CASE("Unit_hipStreamGetDevice_Usecase") {
|
||||
int device_count = 0;
|
||||
|
||||
HIP_CHECK(hipGetDeviceCount(&device_count));
|
||||
REQUIRE(device_count != 0); // atleast 1 device
|
||||
REQUIRE(device_count != 0);
|
||||
|
||||
SECTION("Null Stream") {
|
||||
CTX_CREATE();
|
||||
@@ -43,7 +86,7 @@ TEST_CASE("Unit_hipStreamGetDevice_Usecase") {
|
||||
hipDevice_t device_from_stream, device_from_ordinal;
|
||||
HIP_CHECK(hipStreamGetDevice(nullptr, &device_from_stream));
|
||||
|
||||
HIP_CHECK(hipDeviceGet(&device_from_ordinal, 0)); // default device
|
||||
HIP_CHECK(hipDeviceGet(&device_from_ordinal, 0));
|
||||
REQUIRE(device_from_stream == device_from_ordinal);
|
||||
|
||||
CTX_DESTROY();
|
||||
@@ -55,7 +98,7 @@ TEST_CASE("Unit_hipStreamGetDevice_Usecase") {
|
||||
hipDevice_t device_from_stream, device_from_ordinal;
|
||||
HIP_CHECK(hipStreamGetDevice(hipStreamPerThread, &device_from_stream));
|
||||
|
||||
HIP_CHECK(hipDeviceGet(&device_from_ordinal, 0)); // default device
|
||||
HIP_CHECK(hipDeviceGet(&device_from_ordinal, 0));
|
||||
REQUIRE(device_from_stream == device_from_ordinal);
|
||||
|
||||
CTX_DESTROY();
|
||||
@@ -72,7 +115,128 @@ TEST_CASE("Unit_hipStreamGetDevice_Usecase") {
|
||||
HIP_CHECK(hipStreamGetDevice(stream, &device_from_stream));
|
||||
|
||||
HIP_CHECK(hipDeviceGet(&device_from_ordinal, i));
|
||||
REQUIRE(device_from_stream == device_from_ordinal); // maybe match uuid??
|
||||
REQUIRE(device_from_stream == device_from_ordinal);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test Description
|
||||
* ------------------------
|
||||
* - NegativeTest case.
|
||||
* Test case to multi-threaded scenario for hipStreamGetDevice
|
||||
|
||||
* Test source
|
||||
* ------------------------
|
||||
* - catch/unit/stream/hipStreamGetDevice.cc
|
||||
* Test requirements
|
||||
* ------------------------
|
||||
* - HIP_VERSION >= 5.6
|
||||
*/
|
||||
|
||||
static bool validateStreamGetDevice() {
|
||||
int gpu = 0;
|
||||
hipDevice_t device_from_stream;
|
||||
hipStream_t stream;
|
||||
HIP_CHECK(hipStreamCreate(&stream));
|
||||
HIP_CHECK(hipStreamGetDevice(stream, &device_from_stream));
|
||||
|
||||
REQUIRE(device_from_stream == gpu);
|
||||
return true;
|
||||
}
|
||||
|
||||
static void thread_Test(int threadNum) {
|
||||
thread_results[threadNum] = validateStreamGetDevice();
|
||||
}
|
||||
|
||||
static bool test_hipStreamGetDevice_MThread() {
|
||||
std::vector<std::thread> tests;
|
||||
|
||||
// Spawn the test threads
|
||||
for (int idx = 0; idx < NUMBER_OF_THREADS; idx++) {
|
||||
thread_results[idx] = false;
|
||||
tests.push_back(std::thread(thread_Test, idx));
|
||||
}
|
||||
// Wait for all threads to complete
|
||||
for (std::thread &t : tests) {
|
||||
t.join();
|
||||
}
|
||||
// Wait for thread
|
||||
bool status = true;
|
||||
for (int idx = 0; idx < NUMBER_OF_THREADS; idx++) {
|
||||
status = status & thread_results[idx];
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
TEST_CASE("Unit_hipStreamGetDevice_MThread") {
|
||||
REQUIRE(true == test_hipStreamGetDevice_MThread());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test Description
|
||||
* ------------------------
|
||||
* - NegativeTest case.
|
||||
* Create a stream with gpu1, then set device to gpu0
|
||||
* call hipStreamGetDevice on the stream and verify the
|
||||
* returned device is same as initial set device.
|
||||
|
||||
* Test source
|
||||
* ------------------------
|
||||
* - catch/unit/stream/hipStreamGetDevice.cc
|
||||
* Test requirements
|
||||
* ------------------------
|
||||
* - HIP_VERSION >= 5.6
|
||||
*/
|
||||
|
||||
TEST_CASE("Unit_hipStreamGetDevice_SetDiffDevice") {
|
||||
hipDevice_t device_from_stream;
|
||||
int device_count = 0;
|
||||
HIP_CHECK(hipGetDeviceCount(&device_count));
|
||||
if (device_count < 2) {
|
||||
HipTest::HIP_SKIP_TEST("Skipping because devices < 2");
|
||||
return;
|
||||
}
|
||||
for (int i = 0; i < device_count; ++i) {
|
||||
HIP_CHECK(hipSetDevice(i));
|
||||
hipStream_t stream;
|
||||
HIP_CHECK(hipStreamCreate(&stream));
|
||||
for (int j = 0; j < device_count; ++j) {
|
||||
if (i != j) {
|
||||
HIP_CHECK(hipSetDevice(j));
|
||||
HIP_CHECK(hipStreamGetDevice(stream, &device_from_stream));
|
||||
REQUIRE(device_from_stream == i);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test Description
|
||||
* ------------------------
|
||||
* - NegativeTest case.
|
||||
* Set hip Devices to each available gpu and probe
|
||||
* hipStreamGetDevice with null stream.
|
||||
|
||||
* Test source
|
||||
* ------------------------
|
||||
* - catch/unit/stream/hipStreamGetDevice.cc
|
||||
* Test requirements
|
||||
* ------------------------
|
||||
* - HIP_VERSION >= 5.6
|
||||
* Test to be run only on AMD machine as it's failing in CUDA.
|
||||
*/
|
||||
#if HT_AMD
|
||||
TEST_CASE("Unit_hipStreamGetDevice_NullStream") {
|
||||
int device_count = 0;
|
||||
HIP_CHECK(hipGetDeviceCount(&device_count));
|
||||
REQUIRE(device_count != 0);
|
||||
|
||||
for (int i = 0; i < device_count; i++) {
|
||||
HIP_CHECK(hipSetDevice(i));
|
||||
hipDevice_t device_from_stream;
|
||||
HIP_CHECK(hipStreamGetDevice(0, &device_from_stream));
|
||||
REQUIRE(device_from_stream == i);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
Посилання в новій задачі
Заблокувати користувача