Files
TheRock/rocm-systems/projects/hip-tests/catch/unit/memory/hipMemsetD2D8Async.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

162 lines
5.8 KiB
C++

/*
* Copyright (c) Advanced Micro Devices, Inc., or its affiliates.
*
* SPDX-License-Identifier: MIT
*/
#include <hip_test_common.hh>
#include <hip_test_checkers.hh>
#include <hip_test_defgroups.hh>
/**
* @addtogroup hipMemsetD2D8Async hipMemsetD2D8Async
* @{
* @ingroup MemoryTest
* `hipError_t hipMemsetD2D8Async(hipDeviceptr_t dst, size_t dstPitch,
unsigned char value, size_t width,
size_t height, hipStream_t stream __dparm(0))` -
* Fills 2D memory range of 'width' 8-bit values asynchronously to the specified char
* value. Height specifies numbers of rows to set and dstPitch speicifies the number
* of bytes between each row.
*/
/**
* Test Description
* ------------------------
* - Checks that allocated buffers have the expected value
* after setting it to a known constant.
* Test source
* ------------------------
* - catch/unit/memory/hipMemsetD2D8Async.cc
* Test requirements
* ------------------------
* - HIP_VERSION >= 7.1
*/
HIP_TEST_CASE(Unit_hipMemsetD2D8Async_BasicFunctional) {
constexpr char memsetval = 'c';
constexpr size_t numH = 256;
constexpr size_t numW = 256;
size_t pitch_A;
size_t width = numW * sizeof(char);
size_t sizeElements = numW * numH;
hipDeviceptr_t A_d;
hipStream_t stream = nullptr;
HIP_CHECK(hipStreamCreate(&stream));
HIP_CHECK(
hipMemAllocPitch(&A_d, &pitch_A, width, numH, 4 * sizeof(char)));
std::vector<char>A_h(sizeElements, 'a');
HIP_CHECK(hipMemsetD2D8Async(A_d, pitch_A, memsetval, width, numH, stream));
HIP_CHECK(hipMemcpy2DAsync(A_h.data(), width, reinterpret_cast<void *>( A_d ), pitch_A, width, numH, hipMemcpyDeviceToHost, stream));
HIP_CHECK(hipStreamSynchronize(stream));
for (size_t i = 0; i < sizeElements; i++) {
INFO("Memset2D mismatch at index:" << i << " computed:" << A_h[i]
<< " memsetval:" << memsetval);
REQUIRE(A_h[i] == memsetval);
}
HIP_CHECK(hipStreamDestroy(stream));
HIP_CHECK(hipFree(reinterpret_cast<void*>(A_d)));
}
/**
* Test Description
* ------------------------
* - Uneven width and Hight 2D Memory.
* - Checks that allocated buffers have the expected value
* after setting it to a known constant.
* Test source
* ------------------------
* - catch/unit/memory/hipMemsetD2D8Async.cc
* Test requirements
* ------------------------
* - HIP_VERSION >= 7.1
*/
HIP_TEST_CASE(Unit_hipMemsetD2D8Async_UnEvenRowsCols) {
hipDeviceptr_t A_d;
int rows, cols;
rows = GENERATE(3, 4, 100);
cols = GENERATE(3, 4, 100);
size_t devPitch;
constexpr char memsetval = 'c';
hipStream_t stream = nullptr;
HIP_CHECK(hipStreamCreate(&stream));
size_t size = rows * cols;
std::vector<char>A_h(size, 'a');
std::vector<char>B_h(size, 'a');
HIP_CHECK(hipMemAllocPitch(&A_d, &devPitch, sizeof(char) * cols, rows,
4 * sizeof(char)));
HIP_CHECK(hipMemcpy2DAsync(reinterpret_cast<void*>( A_d ), devPitch, A_h.data(), sizeof(char) * cols, sizeof(char) * cols, rows,
hipMemcpyHostToDevice, stream));
HIP_CHECK(hipMemsetD2D8Async(A_d, devPitch, memsetval, sizeof(char) * cols, rows, stream));
HIP_CHECK(hipMemcpy2DAsync(B_h.data(), sizeof(char) * cols, reinterpret_cast<void*>(A_d), devPitch, sizeof(char) * cols, rows,
hipMemcpyDeviceToHost, stream));
HIP_CHECK(hipStreamSynchronize(stream));
for (int i = 0; i < rows; i++) {
for (int j = 0; j < cols; j++) {
INFO("Memset2D mismatch at index:" << i << " computed:" << B_h[i * cols + j]
<< " memsetval:" << memsetval);
REQUIRE(B_h[i * cols + j] == memsetval);
}
}
HIP_CHECK(hipStreamDestroy(stream));
HIP_CHECK(hipFree(reinterpret_cast<void *>(A_d)));
}
/**
* Test Description
* ------------------------
* - Checks function behaviour when provided invalid arguments.
* Test source
* ------------------------
* - catch/unit/memory/hipMemsetD2D8Async.cc
* Test requirements
* ------------------------
* - HIP_VERSION >= 7.1
*/
HIP_TEST_CASE(Unit_hipMemsetD2D8Async_NegTsts) {
hipDeviceptr_t A_d;
constexpr size_t numH = 256;
constexpr size_t numW = 256;
size_t width = numW * sizeof(char);
size_t devPitch;
constexpr char memsetval = 'c';
hipStream_t stream = nullptr;
HIP_CHECK(hipStreamCreate(&stream));
HIP_CHECK(
hipMemAllocPitch(&A_d, &devPitch, width, numH, 4 * sizeof(char)));
SECTION("nullptr destination") {
HIP_CHECK_ERROR(hipMemsetD2D8Async(NULL, devPitch, memsetval, numW, numH, stream),
hipErrorInvalidValue);
}
SECTION("OutOfBound destination") {
void* outOfBoundsDst{reinterpret_cast<char*>(A_d) + devPitch * numH + 1};
HIP_CHECK_ERROR(hipMemsetD2D8Async(reinterpret_cast<hipDeviceptr_t>(outOfBoundsDst), devPitch, memsetval, numW, numH, stream),
hipErrorInvalidValue);
}
SECTION("Dst pointer points to Source Memory") {
hipDeviceptr_t B_d;
std::unique_ptr<char[]> hostPtr;
hostPtr.reset(new char[numH * width]);
B_d = reinterpret_cast<hipDeviceptr_t>(hostPtr.get());
HIP_CHECK_ERROR(hipMemsetD2D8Async(B_d, devPitch, memsetval, numW, numH, stream),
hipErrorInvalidValue);
}
SECTION("Invalid Pitch") {
size_t inValidPitch = 1;
HIP_CHECK_ERROR(hipMemsetD2D8Async(A_d, inValidPitch, memsetval, numW, numH, stream),
hipErrorInvalidValue);
}
SECTION("Negative Values of Hight, Width") {
HIP_CHECK_ERROR(hipMemsetD2D8Async(A_d, devPitch, memsetval, numW, -10, stream),
hipErrorInvalidValue);
HIP_CHECK_ERROR(hipMemsetD2D8Async(A_d, devPitch, memsetval, -10, numH, stream),
hipErrorInvalidValue);
}
HIP_CHECK(hipFree(reinterpret_cast<void*>(A_d)));
HIP_CHECK(hipStreamDestroy(stream));
}
/**
* End doxygen group MemoryTest.
* @}
*/