1 module dcompute.driver.cuda.memory; 2 3 import dcompute.driver.error; 4 import dcompute.driver.cuda; 5 6 // void pointer like 7 struct MemoryPointer 8 { 9 size_t raw; 10 static MemoryPointer allocate(size_t nbytes) 11 { 12 MemoryPointer ret; 13 status = cast(Status)cuMemAlloc(&ret.raw,nbytes); 14 checkErrors(); 15 return ret; 16 } 17 //static MemoryPointer allocatePitch(T)(size_t nbytes) 18 19 Memory addressRange() 20 { 21 Memory ret; 22 status = cast(Status)cuMemGetAddressRange(&ret.ptr.raw,&ret.length,raw); 23 checkErrors(); 24 return ret; 25 } 26 27 } 28 29 // void[] like 30 struct Memory 31 { 32 MemoryPointer ptr; 33 size_t length; 34 35 enum CopySource 36 { 37 Host, 38 Device, 39 Array 40 } 41 42 // cuMemcpy and friends 43 // TODO: implement this properly 44 /* 45 template copy(T, CopySource from, CopySource to, int dimentions = 1, 46 Flag!"peer" _peer = No.peer) 47 { 48 auto copy(Memory to) 49 { 50 status = cast(Status)cuMemcpy(to.ptr.raw,ptr.raw,length); 51 checkErrors(); 52 } 53 }*/ 54 55 // TODO: cuMemset & frineds 56 57 }