Skip to content

Commit af1ac60

Browse files
2 parents 4a52074 + f75b0d9 commit af1ac60

File tree

1 file changed

+66
-0
lines changed

1 file changed

+66
-0
lines changed

README.md

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,68 @@
11
# Amplifier.NET
22
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.
3+
4+
Below is the sample Kernel you can write in CSharp
5+
6+
```csharp
7+
[OpenCLKernel]
8+
void add_float([Global]float[] a, [Global] float[] b, [Global]float[] r)
9+
{
10+
int i = get_global_id(0);
11+
b[i] = 0.5f * b[i];
12+
r[i] = a[i] + b[i];
13+
}
14+
15+
[OpenCLKernel]
16+
void Fill([Global] float[] x, float value)
17+
{
18+
int i = get_global_id(0);
19+
20+
x[i] = value;
21+
}
22+
```
23+
24+
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
25+
26+
1. Create an instance of OpenCL compiler. You can list all the available devices.
27+
```csharp
28+
var compiler = new OpenCLCompiler();
29+
Console.WriteLine("\nList Devices----");
30+
foreach (var item in compiler.Devices)
31+
{
32+
Console.WriteLine(item);
33+
}
34+
```
35+
36+
2. Select a device by id and load the Sample kernel created.
37+
```csharp
38+
compiler.UseDevice(0);
39+
compiler.CompileKernel(typeof(SimpleKernels));
40+
41+
Console.WriteLine("\nList Kernels----");
42+
foreach (var item in compiler.Kernels)
43+
{
44+
Console.WriteLine(item);
45+
}
46+
```
47+
48+
3. Declare variable and do some operation which will run on any hardware selected like Intel CPU/GPU, NVIDIA, AMD etc.
49+
```csharp
50+
Array a = new float[] { 1, 2, 3, 4 };
51+
Array b = new float[4];
52+
Array r = new float[4];
53+
54+
var exec = compiler.GetExec<float>();
55+
exec.Fill(b, 0.5f);
56+
exec.add_float(a, b, r);
57+
58+
Console.WriteLine("\nResult----");
59+
for(int i = 0;i<r.Length;i++)
60+
{
61+
Console.Write(r.GetValue(i) + " ");
62+
}
63+
```
64+
65+
## Documentation
66+
Coming soon....
67+
68+
## Any contribution is welcome

0 commit comments

Comments
 (0)