-
Notifications
You must be signed in to change notification settings - Fork 97
Expand file tree
/
Copy pathjellycuda.c
More file actions
87 lines (68 loc) · 2.42 KB
/
jellycuda.c
File metadata and controls
87 lines (68 loc) · 2.42 KB
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
///////////////////////////////////////////////////////////////////////////////
//
// Gone but not forgotten,
// dead or alive,
// in the name of the unresolved,
// here it is...
//
// The Cuda JellyFish
#include <windows.h>
#define CUDACALL __stdcall
//typedef int size_t ;
typedef struct CUctx_st *CUcontext;
/**< Host -> Host */
#define MemcpyKindHostToHost 0
/**< Host -> Device */
#define MemcpyKindHostToDevice 1
/**< Device -> Host */
#define MemcpyKindDeviceToHost 2
/**< Device -> Device */
#define MemcpyKindDeviceToDevice 3
/**< Default based unified virtual address space */
#define MemcpyKindDefault 4
typedef int (CUDACALL * LPFNcuMemAlloc) ( void** devPtr, size_t size );
typedef int (CUDACALL * LPFNcuInit)(int);
typedef int (CUDACALL * LPFNcuDeviceGetCount)(int *count);
typedef int (CUDACALL * LPFNcuDeviceGet)(int *device, int ordinal);
typedef int (CUDACALL * LPFNcuCtxCreate)(CUcontext *pctx, unsigned int flags, int dev);
typedef int (CUDACALL * LPFNcuMemcpy)(void *dst, const void *src, size_t count, int kind);
typedef struct _JellyCuda
{
LPFNcuMemAlloc fncuMemAlloc;
LPFNcuInit fncuInit;
LPFNcuDeviceGetCount fncuDeviceGetCount;
LPFNcuDeviceGet fncuDeviceGet;
LPFNcuCtxCreate fncuCtxCreate;
LPFNcuMemcpy fncuMemcpy;
} JellyCuda, *PJellyCuda;
int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
HMODULE hCuda;
int nDevices;
int device;
int result;
CUcontext context;
void * memory;
JellyCuda jc;
hCuda = LoadLibraryA("nvcuda.dll");
if(hCuda == NULL) return -1;
jc.fncuInit = (LPFNcuInit)GetProcAddress(hCuda, "cuInit");
jc.fncuMemAlloc = (LPFNcuMemAlloc)GetProcAddress(hCuda, "cuMemAlloc");
jc.fncuDeviceGetCount = (LPFNcuDeviceGetCount)GetProcAddress(hCuda, "cuDeviceGetCount");
jc.fncuDeviceGet = (LPFNcuDeviceGet)GetProcAddress(hCuda, "cuDeviceGet");
jc.fncuCtxCreate = (LPFNcuCtxCreate)GetProcAddress(hCuda, "cuCtxCreate");
jc.fncuMemcpy = (LPFNcuMemcpy)GetProcAddress(hCuda, "cuMemcpy");
result = jc.fncuInit(0);
if(result != 0) goto hell;
result = jc.fncuDeviceGetCount(&nDevices);
if(result != 0 || nDevices == 0) goto hell;
result = jc.fncuDeviceGet(&device, 0);
if(result != 0) goto hell;
result = jc.fncuCtxCreate(&context, 0, device);
if(result != 0) goto hell;
result = jc.fncuMemAlloc(&memory, 1024 * 1024);
if(result != 0) goto hell;
hell:
FreeLibrary(hCuda);
return 0;
}