MCPcopy Index your code
hub / github.com/tinygrad/tinygrad / __init__

Method __init__

tinygrad/runtime/ops_webgpu.py:196–221  ·  view source on GitHub ↗
(self, device:str)

Source from the content-addressed store, hash-verified

194
195class WebGpuDevice(Compiled):
196 def __init__(self, device:str):
197 # Requesting an adapter
198 adapter_res = _run(webgpu.wgpuInstanceRequestAdapterF, webgpu.WGPURequestAdapterCallbackInfo, webgpu.WGPURequestAdapterCallback,
199 webgpu.WGPURequestAdapterStatus, 1, 2, instance, webgpu.WGPURequestAdapterOptions(powerPreference=webgpu.WGPUPowerPreference_HighPerformance,
200 backendType=backend_types.get(os.getenv("WEBGPU_BACKEND", ""), 0)))
201
202 # Get supported features
203 supported_features = webgpu.WGPUSupportedFeatures()
204 webgpu.wgpuAdapterGetFeatures(adapter_res, supported_features)
205 supported = [supported_features.features[i] for i in range(supported_features.featureCount)]
206 features = [feat for feat in [webgpu.WGPUFeatureName_TimestampQuery, webgpu.WGPUFeatureName_ShaderF16] if feat in supported]
207 dev_desc = webgpu.WGPUDeviceDescriptor(requiredFeatureCount=len(features),
208 requiredFeatures=c.Array(webgpu.WGPUFeatureName, len(features))(*features)) # type: ignore
209
210 # Limits
211 supported_limits = webgpu.WGPUSupportedLimits()
212 webgpu.wgpuAdapterGetLimits(adapter_res, ctypes.cast(ctypes.pointer(supported_limits),ctypes.POINTER(webgpu.struct_WGPUSupportedLimits)))
213 limits = webgpu.WGPURequiredLimits(limits=supported_limits.limits)
214 dev_desc.requiredLimits = c.pointer(limits)
215
216 # Requesting a device
217 self.device_res = _run(webgpu.wgpuAdapterRequestDeviceF, webgpu.WGPURequestDeviceCallbackInfo, webgpu.WGPURequestDeviceCallback,
218 webgpu.WGPURequestDeviceStatus, 1, 2, adapter_res, dev_desc)
219
220 super().__init__(device, WebGpuAllocator(self), [WGSLRenderer],
221 functools.partial(WebGPUProgram, (self.device_res, webgpu.WGPUFeatureName_TimestampQuery in supported)))
222
223 def synchronize(self):
224 _run(webgpu.wgpuQueueOnSubmittedWorkDone2, webgpu.WGPUQueueWorkDoneCallbackInfo2, webgpu.WGPUQueueWorkDoneCallback2,

Callers

nothing calls this directly

Calls 4

WebGpuAllocatorClass · 0.85
_runFunction · 0.70
getMethod · 0.45
castMethod · 0.45

Tested by

no test coverage detected