1 module dcompute.driver.cuda.context; 2 3 import dcompute.driver.cuda; 4 5 struct Context 6 { 7 void* raw; 8 this(Device dev, uint flags = 0) 9 { 10 status = cast(Status)cuCtxCreate(&raw, flags,dev.raw); 11 checkErrors(); 12 } 13 14 static void push(Context ctx) 15 { 16 status = cast(Status)cuCtxPushCurrent(ctx.raw); 17 checkErrors(); 18 } 19 20 static Context pop() 21 { 22 Context ret; 23 status = cast(Status)cuCtxPopCurrent(&ret.raw); 24 checkErrors(); 25 return ret; 26 } 27 static @property Context current() 28 { 29 Context ret; 30 status = cast(Status)cuCtxGetCurrent(&ret.raw); 31 checkErrors(); 32 return ret; 33 } 34 35 static @property void current(Context ctx) 36 { 37 status = cast(Status)cuCtxSetCurrent(ctx.raw); 38 checkErrors(); 39 } 40 41 static void sync() 42 { 43 status = cast(Status)cuCtxSynchronize(); 44 checkErrors(); 45 } 46 //CUlimit 47 enum Limit 48 { 49 stackSize, 50 printfFifoSize, 51 mallocHeapSize, 52 deviceRuntimeSyncDepth, 53 deviceRuntimePendingLaunchCount 54 } 55 56 static @property void limit(Limit what)(size_t lim) 57 { 58 status = cast(Status)cuCtxSetLimit(what,lim); 59 checkErrors(); 60 } 61 62 static @property size_t limit(Limit what)() 63 { 64 size_t ret; 65 status = cast(Status)cuCtxSetLimit(&ret,what); 66 checkErrors(); 67 return ret; 68 } 69 //CUfunc_cache 70 enum CacheConfig 71 { 72 preferNone, 73 preferShared, 74 preferL1, 75 preferEqual, 76 } 77 78 static @property void cacheConfig(CacheConfig cc) 79 { 80 status = cast(Status)cuCtxSetSharedMemConfig(cc); 81 checkErrors(); 82 } 83 84 85 static @property CacheConfig cacheConfig() 86 { 87 CacheConfig ret; 88 status = cast(Status)cuCtxGetSharedMemConfig(cast(int*)&ret); 89 checkErrors(); 90 return ret; 91 } 92 93 @property uint apiVersion() 94 { 95 uint ret; 96 status = cast(Status)cuCtxGetApiVersion(raw,&ret); 97 checkErrors(); 98 return ret; 99 } 100 101 static void getQueuePriorityRange(out int lo, out int hi) 102 { 103 status = cast(Status)cuCtxGetStreamPriorityRange(&lo,&hi); 104 checkErrors(); 105 } 106 107 void detach() 108 { 109 status = cast(Status)cuCtxDetach(raw); 110 checkErrors(); 111 } 112 }