blob: 666c23790932cb83b4bddcbb69df757121437e03 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
using System;
using System.IO;
using System.Reflection;
using System.Runtime.InteropServices;
namespace Zluda
{
class Program
{
[UnmanagedFunctionPointer(CallingConvention.Winapi)]
private delegate int CuInit(int flags);
static int Main(string[] args)
{
DirectoryInfo exeDirectory = Directory.GetParent(Assembly.GetEntryAssembly().Location);
string dllPath = Path.Combine(exeDirectory.ToString(), "do_cuinit.dll");
IntPtr nvcuda = NativeMethods.LoadLibrary(dllPath);
if (nvcuda == IntPtr.Zero)
return 1;
IntPtr doCuinitPtr = NativeMethods.GetProcAddress(nvcuda, "do_cuinit");
CuInit cuinit = (CuInit)Marshal.GetDelegateForFunctionPointer(doCuinitPtr, typeof(CuInit));
return cuinit(0);
}
}
static class NativeMethods
{
[DllImport("kernel32.dll")]
public static extern IntPtr LoadLibrary(string dllToLoad);
[DllImport("kernel32.dll")]
public static extern IntPtr GetProcAddress(IntPtr hModule, string procedureName);
}
}
|