Giter Club home page Giter Club logo

alexandersemenyak / amplifier.net Goto Github PK

View Code? Open in Web Editor NEW

This project forked from deepakkumar1984/amplifier.net

0.0 0.0 0.0 3.74 MB

Amplifier allows .NET developers to easily run complex applications with intensive mathematical computation on Intel CPU/GPU, NVIDIA, AMD without writing any additional C kernel code. Write your function in .NET and Amplifier will take care of running it on your favorite hardware.

License: MIT License

C 0.90% C# 98.84% CSS 0.07% Cuda 0.19%

amplifier.net's Introduction

origin: https://github.com/deepakkumar1984/Amplifier.NET

Amplifier.NET

Amplifier allows .NET developers to easily run complex applications with intensive mathematical computation on Intel CPU/GPU, NVIDIA, AMD without writing any additional C kernel code. Write your function in .NET and Amplifier will take care of running it on your favorite hardware.

Below is the sample Kernel you can write in CSharp

[OpenCLKernel]
void add_float([Global]float[] a, [Global] float[] b, [Global]float[] r)
{
    int i = get_global_id(0);
    b[i] = 0.5f * b[i];
    r[i] = a[i] + b[i];
}

[OpenCLKernel]
void Fill([Global] float[] x, float value)
{
    int i = get_global_id(0);

    x[i] = value;
}

Now this kernel will be converted to C99 format which is specific instruction for OpenCL. Let's do some magic to execute the kernel using OpenCL

  1. Create an instance of OpenCL compiler. You can list all the available devices.
var compiler = new OpenCLCompiler();
Console.WriteLine("\nList Devices----");
foreach (var item in compiler.Devices)
{
    Console.WriteLine(item);
}
  1. Select a device by id and load the Sample kernel created.
compiler.UseDevice(0);
compiler.CompileKernel(typeof(SimpleKernels));

Console.WriteLine("\nList Kernels----");
foreach (var item in compiler.Kernels)
{
    Console.WriteLine(item);
}
  1. Declare variable and do some operation which will run on any hardware selected like Intel CPU/GPU, NVIDIA, AMD etc.
Array a = new float[] { 1, 2, 3, 4 };
Array b = new float[4];
Array r = new float[4];

var exec = compiler.GetExec<float>();
exec.Fill(b, 0.5f);
exec.add_float(a, b, r);

Console.WriteLine("\nResult----");
for(int i = 0;i<r.Length;i++)
{
    Console.Write(r.GetValue(i) + " ");
}

Result:

Documentation

Any contribution is welcome

Please fork the code and suggest improvements by raising PR. Raise issues so that I can make this library robust.

amplifier.net's People

Contributors

deepakkumar1984 avatar thedozman avatar kgamecarter avatar alexandersemenyak avatar csrakowski avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.