Skip to content

This is an OpenCL wrapper for .NET Core, which implements the .NET Standard Profile and therefore should run cross-platform on Linux, macOS, and Windows, as well as on many different .NET implementations, such as .NET Core, Mono, .NET Framework, and Xamarin.

License

lecode-official/opencl-dotnet

Repository files navigation

OpenCL.NET

This is an OpenCL wrapper for .NET Core, which implements the .NET Standard Profile and therefore should run cross-platform on Linux, macOS, and Windows, as well as on many different .NET implementations, such as .NET Core, Mono, .NET Framework, and Xamarin. The project aims at implementing the full OpenCL 2.1 standard on a low-level PInvoke level and create a wrapper, which exposes most of the functionality in a more CLR-style fashion. More abstract wrappers are planned for the future. This wrapper should help with implementing image manipulation software as well as with machine learning (especially deep learning). Once the components have reached a certain maturity, they will be released to NuGet.

Installation

In order to use OpenCL you have to install OpenCL. Under macOS you are in luck, because macOS has been shipping with OpenCL ever since Snow Leopard and you have to do nothing more, to get everything set up. Many standard Windows installations also alread ship with OpenCL installed. If you have a custom setup, then installing the correct drivers should suffice. Under Linux things are a little more complicated. First of all you have to install the ICD loader. For example under Ubuntu and Debian based systems you can do it like so:

sudo apt update
sudo apt install ocl-icd-opencl-dev

Then you have to install the correct drivers for your platform, e.g. the graphics adapter, and the OpenCL platform of choice. For example for Nvidia you have to install the CUDA framework.

More information on installation and setup will follow soon.

Running the Sample

You can try the test application, that comes with this repository. It just performs a simple multiplication of a matrix with a vector. To build and run the sample application, you can do the following:

git clone https://github.com/lecode-official/opencl-dotnet.git
cd opencl-dotnet
cd OpenCl.DotNetCore.Tests
dotnet run

Troubleshooting

When you are experiencing a DllNotFoundException on macOS, then please make sure that you have the OpenCL framework in your library load path:

export DYLD_LIBRARY_PATH=$DYLD_LIBRARY_PATH:/System/Library/Frameworks/OpenCL.framework/OpenCL
dotnet run

Roadmap

In the following sections the roadmap to a stable 0.1.0-beta release is mapped out.

General Todos

  • Separate into three projects: Native Core, CLR Wrapper, Test Program

OpenCl.DotNetCore.Interop Project Todos

  • Rename the arguments of the native methods
  • Rename Info to Information
  • Put the different APIs of the native wrapper into different classes
  • Port the whole API surface area
    • Command Queues API
    • Contexts API
    • Devices API
    • Enqueued Commands API
    • Events API
    • Extensions API
    • Kernels API
    • Memory API
    • Platforms API
    • Profiling API
    • Programs API
    • Samplers API
    • SVM Allocations API
  • Finish API documentation
    • Command Queues API
    • Contexts API
    • Devices API
    • Enqueued Commands API
    • Events API
    • Extensions API
    • Kernels API
    • Memory API
    • Platforms API
    • Profiling API
    • Programs API
    • Samplers API
    • SVM Allocations API
  • Mark everything with the Obsolete attribute that have been deprecated in OpenCL
  • Mark everything with an attribute that contains the minimum version of OpenCL required

OpenCl.DotNetCore Project Todos

  • HandleBase class, which is the base class for all OpenCL classes that need a handle
  • Add compiler log to exception, when program cannot be build
  • Add method to compile multiple sources at once
  • Add method to compile from file/files
  • Add method to compile from Stream/Streams
  • Create a class that converts byte arrays into CLR types
  • Implement the equals and the == operator, which compares the Handle
  • Split the different APIs in sub-namespaces
  • Make MemoryObject abstract and derive Image, Pipe, and Buffer from it
  • Add async methods for all native methods that have an event
  • Create an base class for event and then derive a user event from it, which is returned when calling CreateUserEvent (this should be done to ensure, that SetUserEventStatus can only be called on valid user events)
  • Fix compilation and linking problems for Intel platform (maybe only on Windows)
  • Make WaitEvent awaitable (maybe even rename it to AwaitableEvent)

OpenCl.DotNetCore.Tests Project Todos

Nothing to do here

About

This is an OpenCL wrapper for .NET Core, which implements the .NET Standard Profile and therefore should run cross-platform on Linux, macOS, and Windows, as well as on many different .NET implementations, such as .NET Core, Mono, .NET Framework, and Xamarin.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages