SWDEV-470698 - fix formatting, add format check workflow (#657)

This commit is contained in:
Danylo Lytovchenko
2025-08-20 16:28:06 +02:00
committed by GitHub
parent 5840940caa
commit f7338717ae
1574 changed files with 162972 additions and 199346 deletions
@@ -30,7 +30,7 @@ Following scenarios are verified for hipPointerGetAttributes API
*/
#include <inttypes.h>
#include <hip_test_common.hh>
#ifdef __linux__
#include <sys/mman.h>
#endif
@@ -51,17 +51,14 @@ constexpr size_t N{1000000};
// Utility Functions:
//=================================================================================================
bool operator==(const hipPointerAttribute_t& lhs,
const hipPointerAttribute_t& rhs) {
return ((lhs.hostPointer == rhs.hostPointer) &&
(lhs.devicePointer == rhs.devicePointer) &&
bool operator==(const hipPointerAttribute_t& lhs, const hipPointerAttribute_t& rhs) {
return ((lhs.hostPointer == rhs.hostPointer) && (lhs.devicePointer == rhs.devicePointer) &&
(lhs.type == rhs.type) && (lhs.device == rhs.device) &&
(lhs.allocationFlags == rhs.allocationFlags));
}
bool operator!=(const hipPointerAttribute_t& lhs,
const hipPointerAttribute_t& rhs) {
bool operator!=(const hipPointerAttribute_t& lhs, const hipPointerAttribute_t& rhs) {
return !(lhs == rhs);
}
@@ -92,8 +89,7 @@ void printAttribs(const hipPointerAttribute_t* attribs) {
printf(
"hostPointer:%p devicePointer:%p type:%s deviceId:%d isManaged:%d "
"allocationFlags:%u\n",
attribs->hostPointer, attribs->devicePointer,
memoryTypeToString(attribs->type),
attribs->hostPointer, attribs->devicePointer, memoryTypeToString(attribs->type),
attribs->device, attribs->isManaged, attribs->allocationFlags);
}
@@ -112,8 +108,7 @@ struct SuperPointerAttribute {
// Support function to check result against a reference:
void checkPointer(const SuperPointerAttribute& ref, int major,
int minor, void* pointer) {
void checkPointer(const SuperPointerAttribute& ref, int major, int minor, void* pointer) {
hipPointerAttribute_t attribs;
resetAttribs(&attribs);
@@ -137,9 +132,12 @@ void checkPointer(const SuperPointerAttribute& ref, int major,
// we do this in the testMultiThreaded_1 test.
void clusterAllocs(int numAllocs, size_t minSize, size_t maxSize) {
Nbytes = N * sizeof(char);
printf("clusterAllocs numAllocs=%d size=" "%" PRIu64 ".." "%" PRIu64 "\n",
numAllocs, static_cast<uint64_t>(minSize),
static_cast<uint64_t>(maxSize));
printf(
"clusterAllocs numAllocs=%d size="
"%" PRIu64
".."
"%" PRIu64 "\n",
numAllocs, static_cast<uint64_t>(minSize), static_cast<uint64_t>(maxSize));
const int Max_Devices = 256;
std::vector<SuperPointerAttribute> reference(numAllocs);
@@ -166,17 +164,14 @@ void clusterAllocs(int numAllocs, size_t minSize, size_t maxSize) {
void* ptr;
if (isDevice) {
totalDeviceAllocated[reference[i]._attrib.device] +=
reference[i]._sizeBytes;
HIP_CHECK(hipMalloc(reinterpret_cast<void**>(&ptr),
reference[i]._sizeBytes));
totalDeviceAllocated[reference[i]._attrib.device] += reference[i]._sizeBytes;
HIP_CHECK(hipMalloc(reinterpret_cast<void**>(&ptr), reference[i]._sizeBytes));
reference[i]._attrib.type = hipMemoryTypeDevice;
reference[i]._attrib.devicePointer = ptr;
reference[i]._attrib.hostPointer = NULL;
reference[i]._attrib.allocationFlags = 0;
} else {
HIP_CHECK(hipHostMalloc(reinterpret_cast<void**>(&ptr),
reference[i]._sizeBytes,
HIP_CHECK(hipHostMalloc(reinterpret_cast<void**>(&ptr), reference[i]._sizeBytes,
hipHostMallocDefault));
reference[i]._attrib.type = hipMemoryTypeHost;
reference[i]._attrib.devicePointer = ptr;
@@ -192,12 +187,12 @@ void clusterAllocs(int numAllocs, size_t minSize, size_t maxSize) {
HIP_CHECK(hipMemGetInfo(&free, &total));
printf(
" device#%d: hipMemGetInfo: "
"free=%zu (%4.2fMB) totalDevice=""%" PRIu64 "(%4.2fMB) total=%zu "
"free=%zu (%4.2fMB) totalDevice="
"%" PRIu64
"(%4.2fMB) total=%zu "
"(%4.2fMB)\n",
i, free, (free / 1024.0 / 1024.0),
static_cast<uint64_t>(totalDeviceAllocated[i]),
(totalDeviceAllocated[i]) / 1024.0 / 1024.0, total,
(total / 1024.0 / 1024.0));
i, free, (free / 1024.0 / 1024.0), static_cast<uint64_t>(totalDeviceAllocated[i]),
(totalDeviceAllocated[i]) / 1024.0 / 1024.0, total, (total / 1024.0 / 1024.0));
REQUIRE(free + totalDeviceAllocated[i] <= total);
}
@@ -243,15 +238,15 @@ TEST_CASE("Unit_hipPointerGetAttributes_Basic") {
hipError_t e;
HIP_CHECK(hipMalloc(&A_d, Nbytes));
HIP_CHECK(hipHostMalloc(reinterpret_cast<void**>(&A_Pinned_h),
Nbytes, hipHostMallocDefault));
HIP_CHECK(hipHostMalloc(reinterpret_cast<void**>(&A_Pinned_h), Nbytes, hipHostMallocDefault));
size_t free, total;
HIP_CHECK(hipMemGetInfo(&free, &total));
printf("hipMemGetInfo: free=%zu (%4.2f) Nbytes=""%" PRIu64
"total=%zu (%4.2f)\n", free,
(free / 1024.0 / 1024.0), static_cast<uint64_t>(Nbytes),
total, (total / 1024.0 / 1024.0));
printf(
"hipMemGetInfo: free=%zu (%4.2f) Nbytes="
"%" PRIu64 "total=%zu (%4.2f)\n",
free, (free / 1024.0 / 1024.0), static_cast<uint64_t>(Nbytes), total,
(total / 1024.0 / 1024.0));
REQUIRE(free + Nbytes <= total);
@@ -271,16 +266,14 @@ TEST_CASE("Unit_hipPointerGetAttributes_Basic") {
// Corner case at end of array:
resetAttribs(&attribs2);
HIP_CHECK(hipPointerGetAttributes(&attribs2, A_d + Nbytes - 1));
REQUIRE((ptr + Nbytes - 1) == reinterpret_cast<char*>
(attribs2.devicePointer));
REQUIRE((ptr + Nbytes - 1) == reinterpret_cast<char*>(attribs2.devicePointer));
// Pointer just beyond array must be invalid or at least a different pointer
resetAttribs(&attribs2);
e = hipPointerGetAttributes(&attribs2, A_d + Nbytes + 1);
if (e != hipErrorInvalidValue) {
// We might have strayed into another pointer area.
REQUIRE(reinterpret_cast<char*>(ptr) !=
reinterpret_cast<char*>(attribs2.devicePointer));
REQUIRE(reinterpret_cast<char*>(ptr) != reinterpret_cast<char*>(attribs2.devicePointer));
}
@@ -382,8 +375,7 @@ TEST_CASE("Unit_hipPointerGetAttributes_Negative") {
SECTION("Invalid Attributes Pointer") {
int* dPtr{nullptr};
HIP_CHECK(hipMalloc(&dPtr, sizeof(int)));
HIP_CHECK_ERROR(hipPointerGetAttributes(nullptr, dPtr),
hipErrorInvalidValue);
HIP_CHECK_ERROR(hipPointerGetAttributes(nullptr, dPtr), hipErrorInvalidValue);
HIP_CHECK(hipFree(dPtr));
}
#endif
@@ -407,10 +399,9 @@ TEST_CASE("Unit_hipPointerGetAttributes_GpuIter") {
REQUIRE(deviceCount != 0);
// Memory Types
enum MemoryTypes {DeviceMemory = 0, HostMemory, MappedMemory};
enum MemoryTypes { DeviceMemory = 0, HostMemory, MappedMemory };
auto MemoryType =
GENERATE(MemoryTypes::DeviceMemory, MemoryTypes::HostMemory,
MemoryTypes::MappedMemory);
GENERATE(MemoryTypes::DeviceMemory, MemoryTypes::HostMemory, MemoryTypes::MappedMemory);
INFO("Memory Type: " << MemoryType);
@@ -421,9 +412,9 @@ TEST_CASE("Unit_hipPointerGetAttributes_GpuIter") {
if (MemoryType == MemoryTypes::DeviceMemory) {
HIP_CHECK(hipMalloc(&ptr, sizeof(int)));
} else if (MemoryType == MemoryTypes::HostMemory) {
HIP_CHECK(hipHostMalloc(&ptr, sizeof(int)));
HIP_CHECK(hipHostMalloc(&ptr, sizeof(int)));
} else if (MemoryType == MemoryTypes::MappedMemory) {
HIP_CHECK(hipHostMalloc(&ptr, sizeof(int), hipHostMallocMapped));
HIP_CHECK(hipHostMalloc(&ptr, sizeof(int), hipHostMallocMapped));
}
REQUIRE(ptr != nullptr);
hipPointerAttribute_t attributes{};
@@ -439,16 +430,14 @@ TEST_CASE("Unit_hipPointerGetAttributes_GpuIter") {
REQUIRE(attributes.hostPointer == ptr);
} else if (MemoryType == MemoryTypes::MappedMemory) {
int* devicePtr{nullptr};
HIP_CHECK(hipHostGetDevicePointer(reinterpret_cast<void**>(&devicePtr),
ptr, 0));
HIP_CHECK(hipHostGetDevicePointer(reinterpret_cast<void**>(&devicePtr), ptr, 0));
REQUIRE(attributes.hostPointer == ptr);
REQUIRE(attributes.hostPointer == devicePtr);
}
if (MemoryType == MemoryTypes::DeviceMemory) {
HIP_CHECK(hipFree(ptr));
} else if (MemoryType == MemoryTypes::MappedMemory ||
MemoryType == MemoryTypes::HostMemory) {
} else if (MemoryType == MemoryTypes::MappedMemory || MemoryType == MemoryTypes::HostMemory) {
HIP_CHECK(hipHostFree(ptr));
}
}
@@ -472,8 +461,7 @@ TEST_CASE("Unit_hipPointerGetAttributes_GpuIter_Managed__Memory") {
for (int i = 0; i < deviceCount; i++) {
HIP_CHECK(hipSetDevice(i));
int managed_memory = 0;
HIP_CHECK(hipDeviceGetAttribute(&managed_memory,
hipDeviceAttributeManagedMemory, i));
HIP_CHECK(hipDeviceGetAttribute(&managed_memory, hipDeviceAttributeManagedMemory, i));
if (!managed_memory) {
INFO("Managed memory access not supported on the device" << i);
} else {
@@ -506,33 +494,34 @@ TEST_CASE("Unit_hipPointerGetAttributes_GpuIter_Unregistered_Memory") {
int deviceCount{0};
HIP_CHECK(hipGetDeviceCount(&deviceCount));
REQUIRE(deviceCount != 0);
int* ptr1{nullptr}; int* ptr2{nullptr}; int* ptr3{nullptr};
int* ptr1{nullptr};
int* ptr2{nullptr};
int* ptr3{nullptr};
for (int i = 0; i < deviceCount; i++) {
HIP_CHECK(hipSetDevice(i));
int N = 5;
ptr1 = new int;
ptr2 = reinterpret_cast<int*>(malloc(sizeof(int)));
ptr3 = reinterpret_cast<int *>(calloc(N, sizeof(int)));
ptr3 = reinterpret_cast<int*>(calloc(N, sizeof(int)));
int ptr4[1000];
#ifdef __linux__
void* ptr5{nullptr};
ptr5 = mmap ( NULL, N*sizeof(int),
PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, 0, 0);
#ifdef __linux__
void* ptr5{nullptr};
ptr5 = mmap(NULL, N * sizeof(int), PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, 0, 0);
if (ptr5 == MAP_FAILED) {
INFO("Mapping Failed\n");
REQUIRE(false);
}
REQUIRE(ptr5 != nullptr);
hipPointerAttribute_t attributes1{};
HIP_CHECK(hipPointerGetAttributes(&attributes1, ptr5));
REQUIRE(attributes1.type == hipMemoryTypeUnregistered);
int err = munmap(ptr5, N*sizeof(int));
if (err != 0) {
INFO("UnMapping Failed\n");
REQUIRE(false);
}
#endif
if (ptr5 == MAP_FAILED) {
INFO("Mapping Failed\n");
REQUIRE(false);
}
REQUIRE(ptr5 != nullptr);
hipPointerAttribute_t attributes1{};
HIP_CHECK(hipPointerGetAttributes(&attributes1, ptr5));
REQUIRE(attributes1.type == hipMemoryTypeUnregistered);
int err = munmap(ptr5, N * sizeof(int));
if (err != 0) {
INFO("UnMapping Failed\n");
REQUIRE(false);
}
#endif
REQUIRE(ptr1 != nullptr);
REQUIRE(ptr2 != nullptr);
REQUIRE(ptr3 != nullptr);
@@ -554,6 +543,6 @@ TEST_CASE("Unit_hipPointerGetAttributes_GpuIter_Unregistered_Memory") {
}
/**
* End doxygen group MemoryTest.
* @}
*/
* End doxygen group MemoryTest.
* @}
*/