1
- // See https://aka.ms/new-console-template for more information
1
+ using ILGPU ;
2
+ using ILGPU . Runtime ;
2
3
3
- Console . WriteLine ( "Hello, World!" ) ;
4
+ class Program
5
+ {
6
+ class MyRefType
7
+ {
8
+ public int Hello => 42 ;
9
+ }
10
+
11
+ struct MyUnmanagedType
12
+ {
13
+ public int Hello ;
14
+
15
+ public MyUnmanagedType ( )
16
+ {
17
+ Hello = 42 ;
18
+ }
19
+ }
20
+
21
+ void Kernel ( Index1D index , ArrayView < int > input , ArrayView < int > output )
22
+ {
23
+ // This is disallowed, since MyRefType is a reference type
24
+ var refType = new MyRefType ( ) ;
25
+ output [ index ] = input [ index ] + refType . Hello ;
26
+
27
+ // Allocating arrays of unmanaged types is fine
28
+ MyUnmanagedType [ ] array = [ new MyUnmanagedType ( ) ] ;
29
+ int [ ] ints = [ 0 , 1 , 2 ] ;
30
+
31
+ // But arrays of reference types are still disallowed
32
+ MyRefType [ ] refs = [ new MyRefType ( ) ] ;
33
+ }
34
+
35
+ void Main ( string [ ] args )
36
+ {
37
+ var context = Context . CreateDefault ( ) ;
38
+ var device = context . GetPreferredDevice ( false ) ;
39
+ var accelerator = device . CreateAccelerator ( context ) ;
40
+
41
+ var input = accelerator . Allocate1D < int > ( 1024 ) ;
42
+ var output = accelerator . Allocate1D < int > ( 1024 ) ;
43
+
44
+ var kernel = accelerator . LoadAutoGroupedStreamKernel < Index1D , ArrayView < int > , ArrayView < int > > ( Kernel ) ;
45
+
46
+ kernel ( input . IntExtent , input . View , output . View ) ;
47
+
48
+ accelerator . Synchronize ( ) ;
49
+ }
50
+ }
0 commit comments