# opencl-csharp **Repository Path**: alabohai/opencl-csharp ## Basic Information - **Project Name**: opencl-csharp - **Description**: No description available - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2020-12-10 - **Last Updated**: 2020-12-19 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # opencl-csharp Prime calculation example using extension method for array (ClooExtensions.cs). Published to native binary via [CoreRT](https://github.com/dotnet/corert) - see `tasks.json`. C#: ```cs // Prepare data - 2,3,4,5,6,7,8,9,10,11,12,13,14,... int[] Primes = Enumerable.Range(2, 1000000).ToArray(); Primes.OpenCLForEach(IsPrimeKernelFunctionCodeString); // Expected result - 2,3,0,5,0,7,0,0,0,11,0,13,0,... ``` Kernel code string contents: ```cpp kernel void GetIfPrime(global int* message) { int index = get_global_id(0); int upperl=(int)sqrt((float)message[index]); for(int i=2;i<=upperl;i++) { if(message[index]%i==0) { message[index]=0; return; } } } ``` Requirements: - newest `VSCode` with C#/Omnisharp extension **OR** newest `Visual Studio 2019` - .NET Core 3.1 SDK installed ( cmd: `dotnet --info` ) - Windows 10 SDK + Visual studio build tools for c++ - GPU driver [with OpenCL support](https://www.khronos.org/conformance/adopters/conformant-products#opencl) - for linux/macos create `Cloo.dll.config`: ```xml ``` The project targets .NET Core, but code files should work with .NET 4.8 as well (after installing `Cloo` nuget package).