1 module dcompute.driver.ocl.device; 2 3 import derelict.opencl.cl; 4 import dcompute.driver.ocl; 5 6 struct Device 7 { 8 enum Type : int 9 { 10 default_ = 0x1, 11 CPU = 0x2, 12 GPU = 0x4, 13 accelerator = 0x8, 14 custom = 0x10, 15 all = 0xFFFFFFFF 16 } 17 18 enum AffinityDomain 19 { 20 numa = 0x1, 21 l4_Cache = 0x2, 22 l3_Cache = 0x4, 23 l2_Cache = 0x8, 24 l1_Cache = 0x10, 25 nextPartitionable = 0x20 26 } 27 28 enum PartitionProperty 29 { 30 Equally = 0x1086, 31 ByCounts = 0x1087, 32 ByCountsListEnd = 0, 33 ByAffinityDomain = 0x1088, 34 } 35 36 enum FPConfig 37 { 38 denorm = 1 << 0, 39 infNan = 1 << 1, 40 roundNearest = 1 << 2, 41 roundZero = 1 << 3, 42 rounfInf = 1 << 4, 43 fma = 1 << 5, 44 softFloat = 1 << 6, 45 correctlyRoundedDivSqrt = 1 << 7, 46 } 47 48 enum MemoryCacheType 49 { 50 none = 0, 51 readOnly = 1, 52 readWrite = 2, 53 } 54 55 enum LocalMemoryType 56 { 57 local, 58 global, 59 } 60 61 enum ExecutionCapabilities 62 { 63 kernel, 64 nativeKernel, 65 } 66 67 static struct Info 68 { 69 @(0x1000) Type type; 70 @(0x1001) uint vendorID; 71 @(0x1002) uint maxComputeUnits; 72 @(0x1003) uint _maxWorkItemDimensions; 73 @(0x1004) size_t maxWorkGroupSize; 74 @(0x1005) size_t* _maxWorkItemSizes; 75 ArrayAccesssor!(_maxWorkItemSizes,_maxWorkItemDimensions) maxWorkItems; 76 @(0x1006) uint preferredVectorWidthByte; 77 @(0x1007) uint preferredVectorWidthShort; 78 @(0x1008) uint preferredVectorWidthInt; 79 @(0x1009) uint preferredVectorWidthLong; 80 @(0x100A) uint preferredVectorWidthFloat; 81 @(0x100B) uint preferredVectorWidthDouble; 82 @(0x100C) uint maxClockFrequency; 83 @(0x1000) uint addressBits; 84 @(0x100E) uint maxReadImageArgs; 85 @(0x100F) uint maxWriteImageArgs; 86 @(0x1010) ulong maxMemoryAllocSize; 87 @(0x1011) size_t image2DMaxWidth; 88 @(0x1012) size_t image2DMaxHeight; 89 @(0x1013) size_t image3DMaxWidth; 90 @(0x1014) size_t image3DMaxHeight; 91 @(0x1015) size_t image3DMaxDepth; 92 @(0x1016) bool imageSupport; 93 @(0x1017) size_t maxParameterSize; 94 @(0x1018) uint maxSamplers; 95 @(0x1019) uint memeoryBaseAddressAlign; 96 @(0x101A) uint minDataTypeAlignSize; // Deprecated in OpenCl 1.2 97 @(0x101B) FPConfig floatFPConfig; 98 @(0x101C) MemoryCacheType GLobalMemoryCacheType; 99 @(0x101D) uint globalMemoryCachelineSize; 100 @(0x101E) ulong globalMemoryCacheSize; 101 @(0x101F) ulong globalMemorySize; 102 @(0x1020) ulong maxConstantBufferSize; 103 @(0x1021) uint maxConstantArgs; 104 @(0x1022) LocalMemoryType localMemoryType; 105 @(0x1023) ulong localMemorySize; 106 @(0x1024) bool errorCorrectionSupport; 107 @(0x1025) size_t profilingTimerResolution; 108 @(0x1026) bool endianLittle; 109 @(0x1027) bool available; 110 @(0x1028) bool compilerAvailable; 111 @(0x1029) ExecutionCapabilities executionCapabilities; 112 @(0x102A) Queue.Properties queueProperties; 113 @(0x102B) char* _name; 114 @(0x102C) char* _vendor; 115 @(0x102D) char* _driverVersion; 116 @(0x102E) char* _profile; 117 @(0x102F) char* _deviceVersion; 118 @(0x1030) char* _extensions; 119 120 StringzAccessor!(_name) name; 121 StringzAccessor!(_vendor) vendor; 122 StringzAccessor!(_driverVersion) driverVersion; 123 StringzAccessor!(_profile) profile; 124 StringzAccessor!(_deviceVersion) deviceVersion; 125 StringzAccessor!(_extensions) extensions; 126 127 @(0x1031) Platform platform; 128 @(0x1032) FPConfig doubleFPConfig; 129 @(0x1033) FPConfig halfFPConfig; 130 @(0x1034) uint pefferedVectorWidthHalf; 131 @(0x1035) bool hostUnifiedMemory; 132 @(0x1036) uint nativeVectorWidthByte; 133 @(0x1037) uint nativeVectorWidthShort; 134 @(0x1038) uint nativeVectorWidthInt; 135 @(0x1039) uint nativeVectorWidthLong; 136 @(0x103A) uint nativeVectorWidthFloat; 137 @(0x103B) uint nativeVectorWidthDouble; 138 @(0x103C) uint nativeVectorWidthHalf; 139 @(0x103D) char* _OpenCLCVersion; 140 StringzAccessor!(_OpenCLCVersion) OpenCLCVersion; 141 @(0x103E) bool linkerAvailable; 142 @(0x103F) char* _builtinKernels; 143 StringzAccessor!(_builtinKernels) builtinKernels; 144 @(0x1040) size_t imageMaxBufferSize; 145 @(0x1041) size_t imageMaxArraySize; 146 @(0x1042) Device parentDevice; 147 @(0x1043) uint partitionMaxSubDevices; 148 //@(0x1044) PartitionProperty* _partitionProperties; 149 //ZeroTerminatedArrayAccessor!(_partitionProperties) partitionProperties; 150 @(0x1045) AffinityDomain partitionAffinityDomain; 151 //@(0x1046) PartitionProperty* _partitionType; 152 //ZeroTerminatedArrayAccessor!(_partitionType) partitionType; 153 @(0x1047) uint peferenceCount; 154 @(0x1048) bool prefferedInteropUserSync; 155 @(0x1049) size_t printfBufferSize; 156 157 // Extensions 158 //@(0x200F) khrTeminateCapability; 159 //@(0x4000) nvComputeCapabilityMajor; 160 //@(0x4001) nvComputeCapabilityMinor; 161 //@(0x4002) nvRegistersPerBlock; 162 //@(0x4003) nvWarpSize; 163 //@(0x4004) nvGPUOverlap; 164 //@(0x4005) nvKerenlExecTimeout; 165 //@(0x4006) nvIntegratedMemory; 166 167 //@(0x4036) amdProfilingTimerOffset 168 } 169 170 cl_device_id raw; 171 172 mixin(generateGetInfo!(Info,clGetDeviceInfo)); 173 174 //Is this a double call function? Also what to do about properties 175 //its zero terminated an can contain numbers 176 //see http://www.khronos.org/registry/cl/sdk/1.2/docs/man/xhtml/clCreateSubDevices.html under the examples 177 /*Device[] createSubDevices(cl.device_partition_property[] properites 178 cl.uint_ numSubDevices) 179 { 180 181 } 182 */ 183 184 void retain() 185 { 186 status = cast(Status)clRetainDevice(raw); 187 checkErrors(); 188 } 189 190 void release() 191 { 192 status = cast(Status)clReleaseDevice(raw); 193 checkErrors(); 194 } 195 196 }