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
156 lines
4.5 KiB
C++
156 lines
4.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>
|
|
#include <vector>
|
|
#include <iostream>
|
|
|
|
#pragma clang diagnostic ignored "-Wunused-variable"
|
|
#pragma clang diagnostic ignored "-Wunused-parameter"
|
|
|
|
template <typename T> __global__ void tex1dKernelFetch(T* val, hipTextureObject_t obj, int N) {
|
|
#if !__HIP_NO_IMAGE_SUPPORT
|
|
int k = blockIdx.x * blockDim.x + threadIdx.x;
|
|
if (k < N) {
|
|
val[k] = tex1Dfetch<T>(obj, k);
|
|
}
|
|
#endif
|
|
}
|
|
|
|
template <typename T, typename std::enable_if<rank<T>() == 1>::type* = nullptr>
|
|
static inline void printVector(T& val) {
|
|
using B = decltype(T::x);
|
|
constexpr bool isChar = std::is_same<B, char>::value || std::is_same<B, unsigned char>::value;
|
|
std::cout << "(";
|
|
std::cout << (isChar ? static_cast<int>(val.x) : val.x);
|
|
std::cout << ")";
|
|
}
|
|
|
|
template <typename T, typename std::enable_if<rank<T>() == 2>::type* = nullptr>
|
|
static inline void printVector(T& val) {
|
|
using B = decltype(T::x);
|
|
constexpr bool isChar = std::is_same<B, char>::value || std::is_same<B, unsigned char>::value;
|
|
std::cout << "(";
|
|
std::cout << (isChar ? static_cast<int>(val.x) : val.x);
|
|
std::cout << ", " << (isChar ? static_cast<int>(val.y) : val.y);
|
|
std::cout << ")";
|
|
}
|
|
|
|
template <typename T, typename std::enable_if<rank<T>() == 4>::type* = nullptr>
|
|
static inline void printVector(T& val) {
|
|
using B = decltype(T::x);
|
|
constexpr bool isChar = std::is_same<B, char>::value || std::is_same<B, unsigned char>::value;
|
|
std::cout << "(";
|
|
std::cout << (isChar ? static_cast<int>(val.x) : val.x);
|
|
std::cout << ", " << (isChar ? static_cast<int>(val.y) : val.y);
|
|
std::cout << ", " << (isChar ? static_cast<int>(val.z) : val.z);
|
|
std::cout << ", " << (isChar ? static_cast<int>(val.w) : val.w);
|
|
std::cout << ")";
|
|
}
|
|
|
|
template <typename T> bool runTest() {
|
|
const int N = 1024;
|
|
bool testResult = true;
|
|
// Allocating the required buffer on gpu device
|
|
T *texBuf, *texBufOut;
|
|
T val[N], output[N];
|
|
auto err = hipGetLastError(); // Clear err due to negative tests
|
|
memset(output, 0, sizeof(output));
|
|
std::srand(std::time(nullptr)); // use current time as seed for random generator
|
|
|
|
for (int i = 0; i < N; i++) {
|
|
initVal<T>(val[i]);
|
|
}
|
|
|
|
HIP_CHECK(hipMalloc(&texBuf, N * sizeof(T)));
|
|
HIP_CHECK(hipMalloc(&texBufOut, N * sizeof(T)));
|
|
HIP_CHECK(hipMemcpy(texBuf, val, N * sizeof(T), hipMemcpyHostToDevice));
|
|
HIP_CHECK(hipMemset(texBufOut, 0, N * sizeof(T)));
|
|
hipResourceDesc resDescLinear;
|
|
|
|
memset(&resDescLinear, 0, sizeof(resDescLinear));
|
|
resDescLinear.resType = hipResourceTypeLinear;
|
|
resDescLinear.res.linear.devPtr = texBuf;
|
|
resDescLinear.res.linear.desc = hipCreateChannelDesc<T>();
|
|
resDescLinear.res.linear.sizeInBytes = N * sizeof(T);
|
|
|
|
hipTextureDesc texDesc;
|
|
memset(&texDesc, 0, sizeof(texDesc));
|
|
texDesc.readMode = hipReadModeElementType;
|
|
texDesc.addressMode[0] = hipAddressModeClamp;
|
|
|
|
// Creating texture object
|
|
hipTextureObject_t texObj = 0;
|
|
HIP_CHECK(hipCreateTextureObject(&texObj, &resDescLinear, &texDesc, NULL));
|
|
|
|
dim3 dimBlock(64, 1, 1);
|
|
dim3 dimGrid((N + dimBlock.x - 1) / dimBlock.x, 1, 1);
|
|
|
|
hipLaunchKernelGGL(tex1dKernelFetch<T>, dimGrid, dimBlock, 0, 0, texBufOut, texObj, N);
|
|
HIP_CHECK(hipGetLastError());
|
|
HIP_CHECK(hipDeviceSynchronize());
|
|
|
|
HIP_CHECK(hipMemcpy(output, texBufOut, N * sizeof(T), hipMemcpyDeviceToHost));
|
|
|
|
for (int i = 0; i < N; i++) {
|
|
if (!isEqual(output[i], val[i])) {
|
|
std::cout << "output[" << i << "]= ";
|
|
printVector<T>(output[i]);
|
|
std::cout << ", expected val[" << i << "]= ";
|
|
printVector<T>(val[i]);
|
|
std::cout << "\n";
|
|
testResult = false;
|
|
break;
|
|
}
|
|
}
|
|
HIP_CHECK(hipDestroyTextureObject(texObj));
|
|
HIP_CHECK(hipFree(texBuf));
|
|
HIP_CHECK(hipFree(texBufOut));
|
|
|
|
REQUIRE(testResult == true);
|
|
return testResult;
|
|
}
|
|
|
|
HIP_TEST_CASE(Unit_hipTextureFetch_vector) {
|
|
CHECK_IMAGE_SUPPORT
|
|
|
|
// test for char
|
|
runTest<char1>();
|
|
runTest<char2>();
|
|
runTest<char4>();
|
|
|
|
// test for uchar
|
|
runTest<uchar1>();
|
|
runTest<uchar2>();
|
|
runTest<uchar4>();
|
|
|
|
// test for short
|
|
runTest<short1>();
|
|
runTest<short2>();
|
|
runTest<short4>();
|
|
|
|
// test for ushort
|
|
runTest<ushort1>();
|
|
runTest<ushort2>();
|
|
runTest<ushort4>();
|
|
|
|
// test for int
|
|
runTest<int1>();
|
|
runTest<int2>();
|
|
runTest<int4>();
|
|
|
|
// test for unsigned int
|
|
runTest<uint1>();
|
|
runTest<uint2>();
|
|
runTest<uint4>();
|
|
|
|
// test for float
|
|
runTest<float1>();
|
|
runTest<float2>();
|
|
runTest<float4>();
|
|
}
|