Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Executing CPU/GPU instructions from managed code

Tags:

.net

gpu

Taking into account the execute disable bit what is the recommended way of executing instructions against a native processor from a high level managed environment such as VB.NET 2008 or C#. In addition has anyone achieved similar in executing GPU instructions against a graphics processor?

like image 538
acheo Avatar asked Jan 20 '10 17:01

acheo


2 Answers

There are a few GPU options for C#, for direct access without reverting to P/Invoke or writing your own C++ wrappers:

  • Brahma is quite interesting. It provides access to the GPU directly via a customized LINQ provider. The code includes some samples of highly computational methods run on the GPU, all written in C# via LINQ.
  • SlimDX provides a nice .NET wrapper to all of the major DirectX functionality. With custom shaders, you can do computation on the GPU via DirectX. It also includes DX11 support, so you can use the compute shaders directly (if you have the hardware for it).
  • You can access CUDA via CUDA.NET.
  • You can use OpenCL via OpenCL.NET.

As for CPU instructions, this typically would require dropping to lower level native code with assembler instruction. Probably the most interesting completely managed (at least partially related) option would be to use Mono.Simd, which provides direct access to the SIMD instructions in the CPU from managed code when running on the Mono stack.

like image 133
Reed Copsey Avatar answered Nov 23 '22 21:11

Reed Copsey


It is not an option. You'll have to P/Invoke a function in DLL that was generated by MASM or written in unmanaged C/C++, using inline assembly or intrinsics. Or use the C++/CLI compiler and generate mixed mode code with #pragma managed.

Beware that you now can no longer depend on the JIT compiler generating whatever platform code is suitable for the operating system. Use Project + Properties, Build tab, Platform Target to force the architecture to match your unmanaged code.

Look at CUDA for managed GPU code.

like image 24
Hans Passant Avatar answered Nov 23 '22 20:11

Hans Passant