Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

simpler webgpu copyin [pr] #600

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions tinygrad/runtime/ops_webgpu.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import functools
import functools, struct
from tinygrad.device import Compiled, Allocator, Compiler
from tinygrad.renderer.wgsl import WGSLRenderer
from tinygrad.helpers import round_up
import wgpu
import struct

def create_uniform(wgpu_device, val) -> wgpu.GPUBuffer:
buf = wgpu_device.create_buffer(size=4, usage=wgpu.BufferUsage.UNIFORM | wgpu.BufferUsage.COPY_DST)
Expand Down Expand Up @@ -47,10 +46,8 @@ def __init__(self, dev): self.dev = dev
def _alloc(self, size: int, options):
return self.dev.create_buffer(size=round_up(size, 4), usage=wgpu.BufferUsage.STORAGE | wgpu.BufferUsage.COPY_DST | wgpu.BufferUsage.COPY_SRC)
def _copyin(self, dest, src: memoryview):
if src.nbytes % 4:
padded_src = bytearray(round_up(src.nbytes, 4))
padded_src[:src.nbytes] = src
self.dev.queue.write_buffer(dest, 0, padded_src if src.nbytes % 4 else src)
if (pad := src.nbytes % 4): src = memoryview(bytearray(src) + bytearray(pad))
self.dev.queue.write_buffer(dest, 0, src)
def _copyout(self, dest: memoryview, src):
buffer_data = self.dev.queue.read_buffer(src, 0)
dest[:] = buffer_data[:dest.nbytes] if src._nbytes > dest.nbytes else buffer_data
Expand Down
Loading