diff options
author | Torsten Keßler | 2022-12-12 14:18:22 +0100 |
---|---|---|
committer | Torsten Keßler | 2022-12-12 14:18:22 +0100 |
commit | e2184849d6138a29f15df867d7f531db5f9a761a (patch) | |
tree | 1faa9d872771c8a32be2098265af10a899c45f32 | |
parent | 3a918bf5ee45ad5ca1b3641d7b05143a9c8a3125 (diff) | |
download | aur-e2184849d6138a29f15df867d7f531db5f9a761a.tar.gz |
upgpkg: rocm-opencl-runtime 5.4.0-2
* Remove check() as tests depend on installed hardware,
* instead add simple test case to be run after package installation to
check if it is correctly configured and installed;
* Overwrite default cmake build type to comply with arch's cmake policy.
-rw-r--r-- | .SRCINFO | 2 | ||||
-rw-r--r-- | PKGBUILD | 15 | ||||
-rw-r--r-- | test.c | 136 | ||||
-rwxr-xr-x | test.sh | 7 |
4 files changed, 148 insertions, 12 deletions
@@ -1,7 +1,7 @@ pkgbase = rocm-opencl-runtime pkgdesc = OpenCL implementation for AMD pkgver = 5.4.0 - pkgrel = 1 + pkgrel = 2 url = https://github.com/RadeonOpenCompute/ROCm-OpenCL-Runtime arch = x86_64 license = MIT @@ -4,7 +4,7 @@ pkgname=rocm-opencl-runtime pkgver=5.4.0 -pkgrel=1 +pkgrel=2 pkgdesc='OpenCL implementation for AMD' arch=('x86_64') url='https://github.com/RadeonOpenCompute/ROCm-OpenCL-Runtime' @@ -24,30 +24,23 @@ build() { cmake \ -Wno-dev \ -B build-rocclr \ - -S "$_rocclr_dir" \ + -S "$_rocclr_dir" \ + -DCMAKE_BUILD_TYPE=None \ -DAMD_OPENCL_PATH="$srcdir/$_dirname" cmake --build build-rocclr - # Tests do not compile with strict format security - CXXFLAGS=${CXXFLAGS//-Werror=format-security/} cmake \ -Wno-dev \ -B build \ -S "$_dirname" \ + -DCMAKE_BUILD_TYPE=None \ -DCMAKE_INSTALL_PREFIX=/opt/rocm \ -DROCM_PATH=/opt/rocm \ - -DBUILD_TESTS=ON \ -DCMAKE_PREFIX_PATH="$srcdir/$_rocclr_dir;/opt/rocm" \ -DAMD_OPENCL_PATH="$srcdir/$_dirname" cmake --build build } -check() { - # Two test targets are defined: runtime and performance. - # Performance tests freeze video output thus we're not calling them here. - cmake --build build --target test.ocltst.oclruntime -} - package() { DESTDIR="$pkgdir" cmake --install build diff --git a/test.c b/test.c new file mode 100644 index 000000000000..1ad3dd203df6 --- /dev/null +++ b/test.c @@ -0,0 +1,136 @@ +#include <stdio.h> +#include <stdlib.h> +#define CL_TARGET_OPENCL_VERSION 300 +#include <CL/cl.h> +#include <math.h> + +static const char *kernel_source="\n" +"__kernel\n" +"void square(__global float *input, __global float *output, uint n)\n" +"{\n" +" uint id = get_global_id(0);\n" +" if(id < n){\n" +" output[id] = input[id]*input[id];\n" +" }\n" +"}\n"; + +int main(int argc, char *argv[]) +{ + size_t n = 1024; + + float *xin = malloc(sizeof *xin * n); + for(size_t i = 0; i < n; i++){ + xin[i] = -1.0f + 2.0f * i / n; + } + + cl_platform_id platform_id; + cl_uint n_platforms; + cl_int err = clGetPlatformIDs(1,&platform_id, &n_platforms); + if(err != CL_SUCCESS){ + fprintf(stderr, "Unable to get platforms\n"); + return 1; + } + + cl_device_id device_id; + cl_uint n_devs; + err = clGetDeviceIDs(platform_id, CL_DEVICE_TYPE_GPU, 1, &device_id, &n_devs); + if(err != CL_SUCCESS){ + fprintf(stderr, "Unable to get device id\n"); + return 1; + } + + cl_context_properties properties[3]; + properties[0] = CL_CONTEXT_PLATFORM; + properties[1] = (cl_context_properties) platform_id; + properties[2] = 0; + + cl_context context = clCreateContext(properties, 1, &device_id, NULL, NULL, &err); + if(err != CL_SUCCESS){ + fprintf(stderr, "Creating context failed with error %d\n", err); + return 1; + } + + cl_command_queue command_queue = clCreateCommandQueueWithProperties(context, device_id, NULL, &err); + if(err != CL_SUCCESS){ + fprintf(stderr, "Creating command queue failed with error %d\n", err); + return 1; + } + + cl_program program = clCreateProgramWithSource(context, 1, &kernel_source, NULL, &err); + if(err != CL_SUCCESS){ + fprintf(stderr, "Creating program from source failed with error %d\n", err); + return 1; + } + + err = clBuildProgram(program, 0, NULL, NULL, NULL, NULL); + if(err != CL_SUCCESS){ + fprintf(stderr, "Compiling program failed with error %d\n", err); + return 1; + } + + cl_kernel kernel = clCreateKernel(program, "square", &err); + if(err != CL_SUCCESS){ + fprintf(stderr, "Creating kernel failed with error %d\n", err); + return 1; + } + + cl_mem x = clCreateBuffer(context, CL_MEM_READ_ONLY, sizeof *xin * n, NULL, &err); + if(err != CL_SUCCESS){ + fprintf(stderr, "Allocating read-only memory failed with error code %d\n", err); + return 1; + } + cl_mem y = clCreateBuffer(context, CL_MEM_WRITE_ONLY, sizeof *xin * n, NULL, &err); + if(err != CL_SUCCESS){ + fprintf(stderr, "Allocating write-only memory failed with error code %d\n", err); + return 1; + } + + err = clEnqueueWriteBuffer(command_queue, x, CL_TRUE, 0, sizeof *xin * n, xin, 0, NULL, NULL); + if(err != CL_SUCCESS){ + fprintf(stderr, "Command queue finished with error code: %d\n", err); + return 1; + } + + cl_uint dim = n; + clSetKernelArg(kernel, 0, sizeof x, &x); + clSetKernelArg(kernel, 1, sizeof y, &y); + clSetKernelArg(kernel, 2, sizeof dim, &dim); + + err = clEnqueueNDRangeKernel(command_queue, kernel, 1, NULL, &n, NULL, 0, NULL, NULL); + if(err != CL_SUCCESS){ + fprintf(stderr, "Cannot queue kernel for execution. Error code: %d\n", err); + return 1; + } + err = clFinish(command_queue); + if(err != CL_SUCCESS){ + fprintf(stderr, "Command queue finished with error code: %d\n", err); + return 1; + } + + float *yout = malloc(sizeof *yout * n); + err = clEnqueueReadBuffer(command_queue, y, CL_TRUE, 0, sizeof *yout * n, yout, 0, NULL, NULL); + if(err != CL_SUCCESS){ + fprintf(stderr, "Could not copy memory from device: %d\n", err); + return 1; + } + + float tol = 0.001f; + for(size_t i = 0; i < n; i++){ + if(fabsf(yout[i] - xin[i] * xin[i]) > tol){ + printf("Mismatch at index %zu:\n", i); + printf("Desired: %f\n", xin[i] * xin[i]); + printf("Actual : %f\n", yout[i]); + return 1; + } + } + printf("TESTS PASSED!\n"); + + free(xin); + free(yout); + clReleaseMemObject(x); + clReleaseMemObject(y); + clReleaseProgram(program); + clReleaseKernel(kernel); + clReleaseCommandQueue(command_queue); + clReleaseContext(context); +} diff --git a/test.sh b/test.sh new file mode 100755 index 000000000000..7a9e12c442f1 --- /dev/null +++ b/test.sh @@ -0,0 +1,7 @@ +#!/usr/bin/env sh + +OUT=$(mktemp -d) +CC=/usr/bin/gcc + +$CC -o "$OUT/test" test.c -L/opt/rocm/lib -lOpenCL -lm +"$OUT"/test |