Files
TheRock/rocm-systems/projects/hip-tests/catch/unit/memory/hipDrvPtrGetAttributes.cc
T
derek.holloway 7502bf64a4
CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
Flatten subprojects into a single base monorepo
2026-09-02 16:34:47 -07:00

167 lines
5.4 KiB
C++

/*
* Copyright (c) Advanced Micro Devices, Inc., or its affiliates.
*
* SPDX-License-Identifier: MIT
*/
/*
* Tests for hipDrvPointerGetAttributes API
Functional Tests:
1. Pass multiple device related attributes in the attributes of hipDrvPointerGetAttributes API
for the device pointer and check the behaviour
2. Pass device and host attributes in the attributes of hipDrvPointerGetAttributes API and
validate the behaviour
3. Pass invalid pointer to hipDrvPointerGetAttributes API and validate the behaviour.
Negative Tests:
1. Pass invalid numAttributes
2. Pass nullptr to attributes
3. Pass nullptr to data
4. Pass nullptr to device pointer
*/
#include <hip_test_common.hh>
static size_t Nbytes = 0;
constexpr size_t N{1000000};
/* This testcase verifies Negative Scenarios of
* hipDrvPointerGetAttributes API */
HIP_TEST_CASE(Unit_hipDrvPtrGetAttributes_Negative) {
HIP_CHECK(hipSetDevice(0));
Nbytes = N * sizeof(int);
int deviceId;
int numDevices = 0;
HIP_CHECK(hipGetDeviceCount(&numDevices));
int* A_d;
HIP_CHECK(hipMalloc(&A_d, Nbytes));
HIP_CHECK(hipGetDevice(&deviceId));
unsigned int device_ordinal;
int* dev_ptr{nullptr};
void* data[2];
data[0] = &dev_ptr;
data[1] = &device_ordinal;
hipPointer_attribute attributes[] = {HIP_POINTER_ATTRIBUTE_DEVICE_POINTER,
HIP_POINTER_ATTRIBUTE_DEVICE_ORDINAL};
SECTION("Passing invalid number to numAttributes") {
REQUIRE(
hipDrvPointerGetAttributes(0, attributes, data, reinterpret_cast<hipDeviceptr_t>(A_d)) ==
hipErrorInvalidValue);
}
SECTION("Passing nullptr to attributes") {
REQUIRE(hipDrvPointerGetAttributes(2, nullptr, data, reinterpret_cast<hipDeviceptr_t>(A_d)) ==
hipErrorInvalidValue);
}
SECTION("Passing nullptr to data") {
REQUIRE(
hipDrvPointerGetAttributes(2, attributes, nullptr, reinterpret_cast<hipDeviceptr_t>(A_d)) ==
hipErrorInvalidValue);
}
#if HT_AMD
SECTION("Passing nullptr to device Pointer") {
hipDeviceptr_t ptr = 0;
REQUIRE(hipDrvPointerGetAttributes(2, attributes, data, ptr) == hipErrorInvalidValue);
}
#endif
#if HT_NVIDIA
SECTION("Passing invalid dependencies") {
hipPointer_attribute attributes1[] = {HIP_POINTER_ATTRIBUTE_DEVICE_POINTER};
REQUIRE(
hipDrvPointerGetAttributes(2, attributes1, data, reinterpret_cast<hipDeviceptr_t>(A_d)) ==
hipErrorInvalidValue);
}
#endif
HIP_CHECK(hipFree(A_d));
}
// Testcase verifies functional scenarios of hipDrvPointerGetAttributes API
HIP_TEST_CASE(Unit_hipDrvPtrGetAttributes_Functional) {
HIP_CHECK(hipSetDevice(0));
Nbytes = N * sizeof(int);
int deviceId;
int numDevices = 0;
HIP_CHECK(hipGetDeviceCount(&numDevices));
int* A_d;
HIP_CHECK(hipMalloc(&A_d, Nbytes));
HIP_CHECK(hipGetDevice(&deviceId));
SECTION("Passing device attributes to device pointer") {
unsigned int memory_type;
int device_ordinal;
int* dev{nullptr};
int* dev_ptr{nullptr};
int* dev_ptr1{nullptr};
unsigned int range_size;
int* start_addr{nullptr};
void* data[5];
data[0] = (&memory_type);
data[1] = (&device_ordinal);
data[2] = (&dev_ptr);
data[3] = (&range_size);
data[4] = (&start_addr);
// Device memory
hipPointer_attribute attributes[] = {
HIP_POINTER_ATTRIBUTE_MEMORY_TYPE, HIP_POINTER_ATTRIBUTE_DEVICE_ORDINAL,
HIP_POINTER_ATTRIBUTE_DEVICE_POINTER, HIP_POINTER_ATTRIBUTE_RANGE_SIZE,
HIP_POINTER_ATTRIBUTE_RANGE_START_ADDR};
HIP_CHECK(hipPointerGetAttribute(&dev_ptr1, HIP_POINTER_ATTRIBUTE_DEVICE_POINTER,
reinterpret_cast<hipDeviceptr_t>(A_d + 100)));
HIP_CHECK(hipPointerGetAttribute(&dev, HIP_POINTER_ATTRIBUTE_DEVICE_POINTER,
reinterpret_cast<hipDeviceptr_t>(A_d)));
HIP_CHECK(hipDrvPointerGetAttributes(5, attributes, data,
reinterpret_cast<hipDeviceptr_t>(A_d + 100)));
REQUIRE(dev_ptr == dev_ptr1);
REQUIRE(memory_type == hipMemoryTypeDevice);
REQUIRE(device_ordinal == deviceId);
REQUIRE(range_size == Nbytes);
REQUIRE(start_addr == dev);
}
SECTION("Passing device and host attributes to device pointer") {
int device_ordinal;
int* host_ptr;
void* data[2];
data[0] = (&host_ptr);
data[1] = (&device_ordinal);
hipPointer_attribute attributes[] = {HIP_POINTER_ATTRIBUTE_HOST_POINTER,
HIP_POINTER_ATTRIBUTE_DEVICE_ORDINAL};
HIP_CHECK(
hipDrvPointerGetAttributes(2, attributes, data, reinterpret_cast<hipDeviceptr_t>(A_d)));
REQUIRE(host_ptr == nullptr);
REQUIRE(device_ordinal == deviceId);
}
SECTION("Passing host related attributes to host pointer") {
int device_ordinal;
void* data[2];
int* host_ptr;
int* pinned_host_ptr;
data[0] = (&host_ptr);
data[1] = (&device_ordinal);
HIP_CHECK(hipHostMalloc(reinterpret_cast<void**>(&pinned_host_ptr), Nbytes, hipHostMallocDefault));
hipPointer_attribute attributes[] = {HIP_POINTER_ATTRIBUTE_HOST_POINTER,
HIP_POINTER_ATTRIBUTE_DEVICE_ORDINAL};
HIP_CHECK(hipDrvPointerGetAttributes(2, attributes, data,
reinterpret_cast<hipDeviceptr_t>(pinned_host_ptr)));
REQUIRE(host_ptr == pinned_host_ptr);
REQUIRE(device_ordinal == deviceId);
HIP_CHECK(hipFreeHost(pinned_host_ptr));
}
HIP_CHECK(hipFree(A_d));
}