Files
TheRock/rocm-systems/projects/hip-tests/catch/unit/device/hipGetProcAddressHelpers.hh
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

217 lines
4.7 KiB
C++

/*
* Copyright (c) Advanced Micro Devices, Inc., or its affiliates.
*
* SPDX-License-Identifier: MIT
*/
#ifndef CATCH_UNIT_DEVICE_HIPGETPROCADDRESSHELPERS_HH_
#define CATCH_UNIT_DEVICE_HIPGETPROCADDRESSHELPERS_HH_
#include <hip_test_common.hh>
/**
* Local Function to fill the array with given value
*/
void fillHostArray(int *arr, int size, int value) {
for ( int i = 0; i < size; i++ ) {
arr[i] = value;
}
}
/**
* Local Function to validate the array with given reference value
*/
bool validateHostArray(int *arr, int size, int refValue) {
for ( int i = 0; i < size; i++ ) {
if ( arr[i] != refValue ) {
return false;
}
}
return true;
}
/**
* Local Function to fill the character array with given value
*/
void fillCharHostArray(char *arr, int size, int value) {
for ( int i = 0; i < size; i++ ) {
arr[i] = value;
}
}
/**
* Local Function to validate the array with given reference value
*/
bool validateCharHostArray(char *arr, int size, int refValue) {
for ( int i = 0; i < size; i++ ) {
if ( arr[i] != refValue ) {
return false;
}
}
return true;
}
/**
* Kernel to validate the array with given reference value
*/
__global__ void verifyArray(int *arr, int size, int refValue, int* status) {
for ( int i = 0; i < size; i++ ) {
if ( arr[i] != refValue ) {
*status = 0;
return;
}
}
*status = 1;
return;
}
/**
* Local Function to validate the device array with given reference value
*/
bool validateDeviceArray(int *arr, int size, int refValue) {
int *devStatus = nullptr;
HIP_CHECK(hipMalloc(&devStatus, sizeof(int)));
REQUIRE(devStatus != nullptr);
verifyArray<<<1, 1>>>(arr, size, refValue, devStatus);
int status;
HIP_CHECK(hipMemcpy(&status, devStatus, sizeof(int), hipMemcpyDeviceToHost));
HIP_CHECK(hipFree(devStatus));
if ( status == 1 ) {
return true;
} else {
return false;
}
}
/**
* Kernel to validate the character array with given reference value
*/
__global__ void verifyCharArray(char *arr, int size,
int refValue, int* status) {
for ( int i = 0; i < size; i++ ) {
if ( arr[i] != refValue ) {
*status = 0;
return;
}
}
*status = 1;
return;
}
/**
* Local Function to validate the character device array with
* given reference value
*/
bool validateCharDeviceArray(char *arr, int size, int refValue) {
int *devStatus = nullptr;
HIP_CHECK(hipMalloc(&devStatus, sizeof(int)));
REQUIRE(devStatus != nullptr);
verifyCharArray<<< 1, 1 >>>(arr, size, refValue, devStatus);
int status;
HIP_CHECK(hipMemcpy(&status, devStatus, sizeof(int), hipMemcpyDeviceToHost));
HIP_CHECK(hipFree(devStatus));
if ( status == 1 ) {
return true;
} else {
return false;
}
}
/**
* Kernel to fill the array with given value
*/
__global__ void fillArray(int *arr, int size, int value) {
for ( int i = 0; i < size; i++ ) {
arr[i] = value;
}
}
/**
* Local Function to fill the device array with given value
*/
void fillDeviceArray(int *arr, int size, int value) {
fillArray<<<1, 1>>>(arr, size, value);
}
/**
* Local Function to validate the array of different types
*/
template<class T>
bool validateArrayT(T *arr, int size, T value) {
for ( int i = 0; i < size; i++ ) {
if ( arr[i] != value ) {
return false;
}
}
return true;
}
/**
* Kernel to increment 1 value to all the elements in array
*/
__global__ void addOneKernel(int *a, int size) {
int offset = blockDim.x * blockIdx.x + threadIdx.x;
int stride = blockDim.x * gridDim.x;
for (int i = offset; i < size; i+= stride) {
a[i] += 1;
}
}
/**
* Kernel to increment 2 value to all the elements in array
*/
__global__ void addTwoKernel(int *a, int size) {
int offset = blockDim.x * blockIdx.x + threadIdx.x;
int stride = blockDim.x * gridDim.x;
for (int i = offset; i < size; i+= stride) {
a[i] += 2;
}
}
/**
* A Simple Kernel useful for validating some kernel related scenarios
*/
__global__ void simpleKernel() {
}
/**
* In addTenKernel, integer a value increased by 10
*/
__global__ void addTenKernel(int *a) {
*a = *a + 10;
}
/**
* Host function adds 10 to the integer a
*/
void addTen(void* data) {
int *a = reinterpret_cast<int *>(data);
*a = *a + 10;
}
/**
* Host function adds 20 to the integer a
*/
void addTwenty(void* data) {
int *a = reinterpret_cast<int *>(data);
*a = *a + 20;
}
/**
* Local function used in call back scenarios
*/
void callBackFunction(hipStream_t stream, hipError_t status, void* userData) {
REQUIRE(stream != nullptr);
REQUIRE(status == hipSuccess);
int *a = reinterpret_cast<int *>(userData);
*a += 100;
}
#endif // CATCH_UNIT_DEVICE_HIPGETPROCADDRESSHELPERS_HH_