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
78 lines
2.5 KiB
C++
78 lines
2.5 KiB
C++
/*
|
|
* Copyright (c) Advanced Micro Devices, Inc., or its affiliates.
|
|
*
|
|
* SPDX-License-Identifier: MIT
|
|
*/
|
|
|
|
#include <hip_test_common.hh>
|
|
#include <hip_array_common.hh>
|
|
|
|
__global__ void add_vectors(int* a, int* b, int* result, int size) {
|
|
int tid = blockIdx.x * blockDim.x + threadIdx.x;
|
|
if (tid < size) {
|
|
result[tid] = a[tid] + b[tid];
|
|
}
|
|
}
|
|
|
|
HIP_TEST_CASE(Unit_hipSetupArgument_Simple) {
|
|
dim3 grid_dim(1, 1, 1);
|
|
dim3 block_dim(1, 1, 1);
|
|
|
|
HIP_CHECK(hipConfigureCall(grid_dim, block_dim, 0, 0));
|
|
|
|
int arg = 42;
|
|
HIP_CHECK(hipSetupArgument(&arg, sizeof(int), 0));
|
|
}
|
|
|
|
/**
|
|
* Test Description
|
|
* ------------------------
|
|
* - Verifies that arguments sent to the kernel with hipSetupArgument are correct by executing
|
|
* kernel that calculates sum of two vectors, doing the same calculation on CPU and checking if
|
|
* the results are the same, which proves that the arguments used in kernel are the proper ones
|
|
*
|
|
* Test source
|
|
* ------------------------
|
|
* - unit/kernel/hipSetupArgument.cc
|
|
*/
|
|
HIP_TEST_CASE(Unit_hipSetupArgument_Execute_Kernel_And_Check_Result) {
|
|
constexpr auto block_size = 32;
|
|
auto vec_size = 256;
|
|
size_t block_num = static_cast<size_t>(std::ceil(static_cast<float>(vec_size) / block_size));
|
|
dim3 grid_dim(block_num, 1, 1);
|
|
dim3 block_dim(block_size, 1, 1);
|
|
|
|
HIP_CHECK(hipConfigureCall(grid_dim, block_dim, 0, 0));
|
|
|
|
std::vector<int> vec_a, vec_b, vec_c;
|
|
for (size_t i = 0; i < vec_size; i++) {
|
|
vec_a.push_back(getRandom<int>());
|
|
vec_b.push_back(getRandom<int>());
|
|
vec_c.push_back(vec_a[i] + vec_b[i]);
|
|
}
|
|
|
|
size_t vec_size_in_bytes = sizeof(int) * vec_size;
|
|
int *dev_a, *dev_b, *dev_c;
|
|
HIP_CHECK(hipMalloc(&dev_a, vec_size_in_bytes));
|
|
HIP_CHECK(hipMalloc(&dev_b, vec_size_in_bytes));
|
|
HIP_CHECK(hipMalloc(&dev_c, vec_size_in_bytes));
|
|
|
|
HIP_CHECK(hipMemcpy(dev_a, vec_a.data(), vec_size_in_bytes, hipMemcpyHostToDevice));
|
|
HIP_CHECK(hipMemcpy(dev_b, vec_b.data(), vec_size_in_bytes, hipMemcpyHostToDevice));
|
|
|
|
HIP_CHECK(hipSetupArgument(&dev_a, sizeof(int*), 0));
|
|
HIP_CHECK(hipSetupArgument(&dev_b, sizeof(int*), sizeof(int*)));
|
|
HIP_CHECK(hipSetupArgument(&dev_c, sizeof(int*), 2 * sizeof(int*)));
|
|
HIP_CHECK(hipSetupArgument(&vec_size, sizeof(int), 3 * sizeof(int*)));
|
|
|
|
HIP_CHECK(hipLaunchByPtr((const void*)add_vectors));
|
|
|
|
std::vector<int> vec_res(vec_size);
|
|
HIP_CHECK(hipMemcpy(vec_res.data(), dev_c, vec_size_in_bytes, hipMemcpyDeviceToHost));
|
|
REQUIRE(vec_res == vec_c);
|
|
|
|
HIP_CHECK(hipFree(dev_c));
|
|
HIP_CHECK(hipFree(dev_b));
|
|
HIP_CHECK(hipFree(dev_a));
|
|
}
|