(Updated January 30, 2015.)
Prerequisites:
(1) You must have Visual Studio 2013 C++ installed.
(2) Download Campy.NET: Go to the Source tab and select download.
(3) Unpack the ZIP file and set up an environmental variable CAMPYNETROOT (either through the Control Panel, or specific for a command-line shell, like bash) to the path of the Campy.NET directory (using Windows backslash style, not forward slash Unix style).
(4) Download the source from ILSpy (ilspy.net). Unpack the ZIP file in the Campy.NET directory.
(5) Download the download and unpack the binaries for Uncrustify, and place it on your PATH. See http://uncrustify.sourceforge.net/
The Example:
Start Visual Studio 2013, and create a C# CLR Console Application. Open the C# source file, and paste the following code into the file. The example provided is the following code:
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Diagnostics; using Campy; using Campy.Types; namespace Test { class Program { static void Main(string[] args) { int size = 100000; int[] data = new int[size]; Extent e = new Extent(size); Array_View<int> d = new Array_View<int>(ref data); AMP.Parallel_For_Each(d.Extent, (Index idx) => { int j = idx[0]; d[j] = size - j - 1; // Capture size and d. }); d.Synchronize(); for (int i = 0; i < size; ++i) { System.Console.WriteLine(data[i]); } } } }
Add Campy.Types.dll and Campy.NET.dll to the references. Compile and run the project. The output should be “99999 … 99998 … 99997 …”. NOTE: IF YOU MAKE CHANGES TO THE CODE AND REBUILD, THE PROGRAM MAY FAIL TO PERFORM A DYNAMIC LINK! YOU MUST STOP THE PROGRAM AND RERUN IT. THIS IS A PROBLEM WITH WINDOWS, AND NO WAY AT THE MOMENT TO BYPASS IT (YOU CANNOT UNLOAD A DLL THAT HAS ALREADY BEEN LOADED). CAMPY WILL RELINK THE DYNAMIC CODE THAT IT BUILDS AND PLACES IN THE DLL UPON PROGRAM START UP!
To debug the kernel, create a C++ CLR application. Open the Property Pages for the project, select Debugging in the left pane. In the right pane, set the Debugger Type to GPU Only. Select Command in the right pane, and enter the path of the C# executable, “…\ConsoleApplication1.exe”. Select Working Directory and set the path for the C# executable. In Visual Studio, open the generated file System_Void_Test_Program___c__DisplayClass1__Main_b__0_Campy_Types_Index__unmanaged.cpp. Set a breakpoint on a line in the kernel, then start a debug session. The program will stop in the kernel.
(Note: updated Feb 7, 2015 for API changes.)