mirror of
https://github.com/vosen/ZLUDA.git
synced 2025-04-20 00:19:20 +03:00
34 lines
1.1 KiB
C#
34 lines
1.1 KiB
C#
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);
|
|
}
|
|
} |