EXSWCPHIPT-112 - Unit test for hipMalloc3DArray for default and surface arrays (#2713)

Этот коммит содержится в:
Finlay
2022-07-11 07:49:05 +01:00
коммит произвёл GitHub
родитель 25f2b260be
Коммит c0deb17bbc
4 изменённых файлов: 302 добавлений и 184 удалений
+48 -47
Просмотреть файл
@@ -30,11 +30,11 @@ hipMallocArray API test scenarios
#include <numeric>
#include "hipArrayCommon.hh"
static constexpr auto NUM_W{4};
static constexpr auto BIGNUM_W{100};
static constexpr auto BIGNUM_H{100};
static constexpr auto NUM_H{4};
static constexpr auto ARRAY_LOOP{100};
static constexpr size_t NUM_W{4};
static constexpr size_t NUM_H{4};
static constexpr size_t BIGNUM_W{100};
static constexpr size_t BIGNUM_H{100};
static constexpr int ARRAY_LOOP{100};
/*
* This API verifies memory allocations for small and
@@ -50,28 +50,30 @@ static constexpr auto ARRAY_LOOP{100};
*
*/
static void MallocArray_DiffSizes(int gpu) {
HIP_CHECK(hipSetDevice(gpu));
std::vector<std::pair<size_t, size_t>> array_size{{NUM_W, NUM_H}, {BIGNUM_W, BIGNUM_H}};
for (auto& size : array_size) {
std::array<hipArray_t, ARRAY_LOOP> A_d;
size_t tot, avail, ptot, pavail;
hipChannelFormatDesc desc = hipCreateChannelDesc<float>();
HIP_CHECK(hipMemGetInfo(&pavail, &ptot));
for (int i = 0; i < ARRAY_LOOP; i++) {
HIP_CHECK(
hipMallocArray(&A_d[i], &desc, std::get<0>(size), std::get<1>(size), hipArrayDefault));
}
for (int i = 0; i < ARRAY_LOOP; i++) {
HIP_CHECK(hipFreeArray(A_d[i]));
}
HIP_CHECK(hipMemGetInfo(&avail, &tot));
if ((pavail != avail)) {
HIPASSERT(false);
}
HIP_CHECK_THREAD(hipSetDevice(gpu));
std::pair<size_t, size_t> size =
GENERATE(std::make_pair(NUM_W, NUM_H), std::make_pair(BIGNUM_W, BIGNUM_H));
hipChannelFormatDesc desc = hipCreateChannelDesc<float>();
std::array<hipArray_t, ARRAY_LOOP> A_d;
size_t pavail, avail;
HIP_CHECK_THREAD(hipMemGetInfo(&pavail, nullptr));
for (int i = 0; i < ARRAY_LOOP; i++) {
HIP_CHECK_THREAD(
hipMallocArray(&A_d[i], &desc, std::get<0>(size), std::get<1>(size), hipArrayDefault));
}
for (int i = 0; i < ARRAY_LOOP; i++) {
HIP_CHECK_THREAD(hipFreeArray(A_d[i]));
}
HIP_CHECK_THREAD(hipMemGetInfo(&avail, nullptr));
REQUIRE_THREAD(pavail == avail);
}
TEST_CASE("Unit_hipMallocArray_DiffSizes") { MallocArray_DiffSizes(0); }
TEST_CASE("Unit_hipMallocArray_DiffSizes") {
MallocArray_DiffSizes(0);
HIP_CHECK_THREAD_FINALIZE();
}
/*
This testcase verifies the hipMallocArray API in multithreaded
@@ -82,18 +84,17 @@ TEST_CASE("Unit_hipMallocArray_MultiThread") {
std::vector<std::thread> threadlist;
int devCnt = 0;
devCnt = HipTest::getDeviceCount();
size_t tot, avail, ptot, pavail;
HIP_CHECK(hipMemGetInfo(&pavail, &ptot));
const auto pavail = getFreeMem();
for (int i = 0; i < devCnt; i++) {
// FIXME: the HIP_CHECK and HIPASSERT are not threadsafe so this test is broken.
threadlist.push_back(std::thread(MallocArray_DiffSizes, i));
}
for (auto& t : threadlist) {
t.join();
}
HIP_CHECK(hipMemGetInfo(&avail, &tot));
HIP_CHECK_THREAD_FINALIZE();
const auto avail = getFreeMem();
if (pavail != avail) {
WARN("Memory leak of hipMalloc3D API in multithreaded scenario");
REQUIRE(false);
@@ -450,32 +451,32 @@ TEMPLATE_TEST_CASE("Unit_hipMallocArray_happy", "", uint, int, int4, ushort, sho
// EXSWCPHIPT-71 - no equivalent value for maxSurface and maxTexture2DGather.
TEMPLATE_TEST_CASE("Unit_hipMallocArray_MaxTexture_Default", "", uint, int4, ushort, short2, char,
char4, float2, float4) {
int device;
HIP_CHECK(hipGetDevice(&device));
hipDeviceProp_t prop;
HIP_CHECK(hipGetDeviceProperties(&prop, device));
size_t width, height;
hipArray_t array{};
hipChannelFormatDesc desc = hipCreateChannelDesc<TestType>();
const unsigned int flag = hipArrayDefault;
const Sizes sizes(flag);
CAPTURE(sizes.max1D, sizes.max2D, sizes.max3D);
const size_t s = 64;
SECTION("Happy") {
SECTION("1D - Max") {
width = prop.maxTexture1D;
width = sizes.max1D;
height = 0;
}
SECTION("2D - Max Width") {
width = prop.maxTexture2D[0];
height = 64;
width = sizes.max2D[0];
height = s;
}
SECTION("2D - Max Height") {
width = 64;
height = prop.maxTexture2D[1];
width = s;
height = sizes.max2D[1];
}
SECTION("2D - Max Width and Height") {
width = prop.maxTexture2D[0];
height = prop.maxTexture2D[1];
width = sizes.max2D[0];
height = sizes.max2D[1];
}
auto maxArrayCreateError = hipMallocArray(&array, &desc, width, height, flag);
// this can try to alloc many GB of memory, so out of memory is acceptable
@@ -485,20 +486,20 @@ TEMPLATE_TEST_CASE("Unit_hipMallocArray_MaxTexture_Default", "", uint, int4, ush
}
SECTION("Negative") {
SECTION("1D - More Than Max") {
width = prop.maxTexture1D + 1;
width = sizes.max1D + 1;
height = 0;
}
SECTION("2D - More Than Max Width") {
width = prop.maxTexture2D[0] + 1;
height = 64;
width = sizes.max2D[0] + 1;
height = s;
}
SECTION("2D - More Than Max Height") {
width = 64;
height = prop.maxTexture2D[1] + 1;
width = s;
height = sizes.max2D[1] + 1;
}
SECTION("2D - More Than Max Width and Height") {
width = prop.maxTexture2D[0] + 1;
height = prop.maxTexture2D[1] + 1;
width = sizes.max2D[0] + 1;
height = sizes.max2D[1] + 1;
}
HIP_CHECK_ERROR(hipMallocArray(&array, &desc, width, height, flag), hipErrorInvalidValue);
}