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
61 lines
2.1 KiB
Plaintext
61 lines
2.1 KiB
Plaintext
// RUN: %run_test hipify "%s" "%t" %hipify_args 1 --hip-kernel-execution-syntax %clang_args
|
|
|
|
#pragma once
|
|
// CHECK: #include <hip/hip_runtime.h>
|
|
#include <cuda_runtime.h>
|
|
#include <math.h>
|
|
// CHECK: #include "hip/hip_fp16.h"
|
|
#include "cuda_fp16.h"
|
|
/**
|
|
* Allocate GPU memory for `count` elements of type `T`.
|
|
*/
|
|
template<typename T>
|
|
static T *gpuMalloc(size_t count) {
|
|
T *ret = nullptr;
|
|
// CHECK: hipMalloc(&ret, count * sizeof(T));
|
|
cudaMalloc(&ret, count * sizeof(T));
|
|
return ret;
|
|
}
|
|
|
|
template<typename T>
|
|
__global__ void add(int n, T *x, T *y) {
|
|
int index = blockIdx.x * blockDim.x + threadIdx.x;
|
|
int stride = blockDim.x * gridDim.x;
|
|
// CHECK: half2 tmp = __float2half2_rn(0.0f);
|
|
half2 tmp = __float2half2_rn(0.0f);
|
|
// CHECK: float max_val = fmax((float)reinterpret_cast<half&>(tmp.x), (float)reinterpret_cast<half&>(tmp.y));
|
|
float max_val = fmax((float)tmp.x, (float)tmp.y);
|
|
// CHECK: float min_val = fmin((float)reinterpret_cast<half&>(tmp.x), (float)reinterpret_cast<half&>(tmp.y));
|
|
float min_val = fmin((float)reinterpret_cast<half&>(tmp.x), (float)reinterpret_cast<half&>(tmp.y));
|
|
for (int i = index; i < n; i += stride)
|
|
y[i] = max_val - min_val + x[i] + y[i];
|
|
}
|
|
|
|
int main(int argc, char* argv[]) {
|
|
size_t numElements = 50;
|
|
float *A = gpuMalloc<float>(numElements);
|
|
float* B = gpuMalloc<float>(numElements);
|
|
for (int i = 0; i < numElements; ++i) {
|
|
A[i] = 1.0f;
|
|
B[i] = 2.0f;
|
|
}
|
|
int blockSize = 512;
|
|
int numBlocks = (numElements + blockSize - 1) / blockSize;
|
|
dim3 dimGrid(numBlocks, 1, 1);
|
|
dim3 dimBlock(blockSize, 1, 1);
|
|
// CHECK: hipLaunchKernelGGL(HIP_KERNEL_NAME(add<float>), dim3(dimGrid), dim3(dimBlock), 0, 0, numElements, A, B);
|
|
add<float><<<dimGrid, dimBlock>>>(numElements, A, B);
|
|
// CHECK: hipDeviceSynchronize();
|
|
cudaDeviceSynchronize();
|
|
float maxError = 0.0f;
|
|
for (int i = 0; i < numElements; ++i)
|
|
maxError = fmax(maxError, fabs(B[i] - 3.0f));
|
|
// CHECK: hipFree(A);
|
|
cudaFree(A);
|
|
// CHECK: hipFree(B);
|
|
cudaFree(B);
|
|
if (maxError == 0.0f)
|
|
return 0;
|
|
return -1;
|
|
}
|