Add and restructure tests for hipStreamCreate (#2560)

* Add and restructure tests for hipStreamCreate
* Add streamCreate to CMakeLists file
This commit is contained in:
Jatin Chaudhary
2022-04-01 04:32:45 +01:00
committed by GitHub
parent 7d45f699fc
commit 600157719d
6 changed files with 268 additions and 106 deletions
@@ -1,5 +1,5 @@
/*
Copyright (c) 2021 Advanced Micro Devices, Inc. All rights reserved.
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
@@ -43,7 +43,7 @@ kernel tasks on these streams from multiple threads. Validate all the results.
8) Validate stream priorities with event after classifying them as low, medium, high.
*/
#include <hip_test_common.hh>
#include "streamCommon.hh"
#include <hip_test_kernels.hh>
#include <atomic>
#include <vector>
@@ -500,8 +500,6 @@ bool validateStreamPrioritiesWithEvents() {
} // namespace hipStreamCreateWithPriorityTest
/**
Tests following scenarios.
1)Create streams with default flag for all available priority levels and
@@ -565,14 +563,12 @@ TEST_CASE("Unit_hipStreamCreateWithPriority_MulthreadNonblockingflag") {
flag = 0xffffffff.
*/
TEST_CASE("Unit_hipStreamCreateWithPriority_NegTst") {
hipStream_t stream;
int priority_low;
int priority_high;
hipError_t ret;
hipStream_t stream{nullptr};
int priority_low{0};
int priority_high{0};
// Test is to get the Stream Priority Range
HIP_CHECK(
hipDeviceGetStreamPriorityRange(&priority_low, &priority_high));
HIP_CHECK(hipDeviceGetStreamPriorityRange(&priority_low, &priority_high));
// Check if priorities are indeed supported
if (priority_low == priority_high) {
WARN("Stream priority range not supported. Skipping test.");
@@ -580,26 +576,64 @@ TEST_CASE("Unit_hipStreamCreateWithPriority_NegTst") {
}
SECTION("stream = nullptr test") {
ret = hipStreamCreateWithPriority(nullptr, hipStreamDefault,
priority_low);
REQUIRE(ret != hipSuccess);
REQUIRE(hipErrorInvalidValue ==
hipStreamCreateWithPriority(nullptr, hipStreamDefault, priority_low));
}
SECTION("flag value invalid test") {
ret = hipStreamCreateWithPriority(&stream, 0xffffffff,
priority_low);
REQUIRE(ret != hipSuccess);
REQUIRE(hipErrorInvalidValue == hipStreamCreateWithPriority(&stream, 0xffffffff, priority_low));
}
}
TEST_CASE("Unit_hipStreamCreateWithPriority") {
int id = GENERATE(range(0, HipTest::getDeviceCount()));
HIP_CHECK(hipSetDevice(id));
int priority_low = 0, priority_high = 0;
HIP_CHECK(hipDeviceGetStreamPriorityRange(&priority_low, &priority_high));
hipStream_t stream{nullptr};
SECTION("Setting high priority") {
HIP_CHECK(hipStreamCreateWithPriority(&stream, hipStreamDefault, priority_high));
REQUIRE(stream != nullptr);
REQUIRE(hip::checkStreamPriorityAndFlags(stream, priority_high));
}
SECTION("Setting low priority") {
HIP_CHECK(hipStreamCreateWithPriority(&stream, hipStreamDefault, priority_low));
REQUIRE(stream != nullptr);
REQUIRE(hip::checkStreamPriorityAndFlags(stream, priority_low));
}
SECTION("Setting lowest possible priority") {
HIP_CHECK(
hipStreamCreateWithPriority(&stream, hipStreamDefault, std::numeric_limits<int>::max()));
REQUIRE(stream != nullptr);
REQUIRE(hip::checkStreamPriorityAndFlags(stream, priority_low));
}
SECTION("Setting highest possible priority") {
HIP_CHECK(
hipStreamCreateWithPriority(&stream, hipStreamDefault, std::numeric_limits<int>::min()));
REQUIRE(stream != nullptr);
REQUIRE(hip::checkStreamPriorityAndFlags(stream, priority_high));
}
SECTION("Setting flags to hipStreamNonBlocking") {
HIP_CHECK(hipStreamCreateWithPriority(&stream, hipStreamNonBlocking, priority_high));
REQUIRE(stream != nullptr);
REQUIRE(hip::checkStreamPriorityAndFlags(stream, priority_high, hipStreamNonBlocking));
}
HIP_CHECK(hipStreamDestroy(stream));
}
/**
* Validate stream priorities with event after classifying them as low, medium and high.
*/
TEST_CASE("Unit_hipStreamCreateWithPriority_ValidateWithEvents") {
bool TestPassed = true;
TestPassed = hipStreamCreateWithPriorityTest::
validateStreamPrioritiesWithEvents<int>();
TestPassed = hipStreamCreateWithPriorityTest::validateStreamPrioritiesWithEvents<int>();
REQUIRE(TestPassed);
}