Date: Tuesday, December 20, 2022 @ 10:48:37
  Author: tpkessler
Revision: 1363705

Migrate rocm-opencl-runtime from AUR to community

Added:
  rocm-opencl-runtime/
  rocm-opencl-runtime/repos/
  rocm-opencl-runtime/trunk/
  rocm-opencl-runtime/trunk/PKGBUILD
  rocm-opencl-runtime/trunk/test.c
  rocm-opencl-runtime/trunk/test.sh

----------+
 PKGBUILD |   54 ++++++++++++++++++++++++
 test.c   |  136 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 test.sh  |    7 +++
 3 files changed, 197 insertions(+)

Added: rocm-opencl-runtime/trunk/PKGBUILD
===================================================================
--- rocm-opencl-runtime/trunk/PKGBUILD                          (rev 0)
+++ rocm-opencl-runtime/trunk/PKGBUILD  2022-12-20 10:48:37 UTC (rev 1363705)
@@ -0,0 +1,54 @@
+# Maintainer: Torsten Keßler <tpkessler at archlinux dot org>
+# Contributor: Ranieri Althoff <ranisalt+aur at gmail dot com>
+# Contributor: acxz <akashpatel2008 at yahoo dot com>
+
+pkgname=rocm-opencl-runtime
+pkgver=5.4.1
+pkgrel=2
+pkgdesc='OpenCL implementation for AMD'
+arch=('x86_64')
+url='https://github.com/RadeonOpenCompute/ROCm-OpenCL-Runtime'
+license=('MIT')
+depends=('hsakmt-roct' 'hsa-rocr' 'comgr' 'mesa' 'opencl-icd-loader')
+makedepends=('rocm-cmake')
+provides=('opencl-driver')
+_rocclr='https://github.com/ROCm-Developer-Tools/ROCclr'
+source=("$pkgname-$pkgver.tar.gz::$url/archive/rocm-$pkgver.tar.gz"
+        "$pkgname-rocclr-$pkgver.tar.gz::$_rocclr/archive/rocm-$pkgver.tar.gz")
+sha256sums=('2b3d7b365f569ce64d1408d6e745d005aa10eca3623891be50f6b1b2e802d875'
+            'c0926fa5dad71cd02f21504d82e218d482779df579a400604e13864e6b2a7d9c')
+_dirname="$(basename "$url")-$(basename "${source[0]}" .tar.gz)"
+_rocclr_dir="$(basename "$_rocclr")-$(basename "${source[1]}" .tar.gz)"
+
+build() {
+    cmake \
+        -Wno-dev \
+        -B build-rocclr \
+        -S "$_rocclr_dir" \
+        -DCMAKE_BUILD_TYPE=None \
+        -DAMD_OPENCL_PATH="$srcdir/$_dirname"
+    cmake --build build-rocclr
+
+    cmake \
+        -Wno-dev \
+        -B build \
+        -S "$_dirname" \
+        -DCMAKE_BUILD_TYPE=None \
+        -DCMAKE_INSTALL_PREFIX=/opt/rocm \
+        -DROCM_PATH=/opt/rocm \
+        -DCMAKE_PREFIX_PATH="$srcdir/$_rocclr_dir;/opt/rocm" \
+        -DAMD_OPENCL_PATH="$srcdir/$_dirname"
+    cmake --build build
+}
+
+package() {
+    DESTDIR="$pkgdir" cmake --install build
+
+    install -Dm644 "$_dirname/LICENSE.txt" 
"$pkgdir/usr/share/licenses/$pkgname/LICENSE"
+
+    echo '/opt/rocm/lib' > "$pkgname.conf"
+    install -Dm644 "$pkgname.conf" "$pkgdir/etc/ld.so.conf.d/$pkgname.conf"
+
+    echo '/opt/rocm/lib/libamdocl64.so' > 'amdocl64.icd'
+    install -Dm644 'amdocl64.icd' "$pkgdir/etc/OpenCL/vendors/amdocl64.icd"
+}

Added: rocm-opencl-runtime/trunk/test.c
===================================================================
--- rocm-opencl-runtime/trunk/test.c                            (rev 0)
+++ rocm-opencl-runtime/trunk/test.c    2022-12-20 10:48:37 UTC (rev 1363705)
@@ -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);
+}

Added: rocm-opencl-runtime/trunk/test.sh
===================================================================
--- rocm-opencl-runtime/trunk/test.sh                           (rev 0)
+++ rocm-opencl-runtime/trunk/test.sh   2022-12-20 10:48:37 UTC (rev 1363705)
@@ -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


Property changes on: rocm-opencl-runtime/trunk/test.sh
___________________________________________________________________
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property

Reply via email to