* Minimal setup of webgpu backend with dawn. Just prints out the adapter and segfaults * Initialize webgpu device * Making progress on setting up the backend * Finish more boilerplate/utility functions * Organize file and work on alloc buffer * Add webgpu_context to prepare for actually running some shaders * Work on memset and add shader loading * Work on memset polyfill * Implement set_tensor as webgpu WriteBuffer, remove host_buffer stubs since webgpu doesn't support it * Implement get_tensor and buffer_clear * Finish rest of setup * Start work on compute graph * Basic mat mul working * Work on emscripten build * Basic WebGPU backend instructions * Use EMSCRIPTEN flag * Work on passing ci, implement 4d tensor multiplication * Pass thread safety test * Implement permuting for mul_mat and cpy * minor cleanups * Address feedback * Remove division by type size in cpy op * Fix formatting and add github action workflows for vulkan and metal (m-series) webgpu backends * Fix name * Fix macos dawn prefix path
36 lines
1.0 KiB
Python
Executable File
36 lines
1.0 KiB
Python
Executable File
import os
|
|
import argparse
|
|
|
|
|
|
def escape_triple_quotes(wgsl):
|
|
# Simple defense in case of embedded """
|
|
return wgsl.replace('"""', '\\"""')
|
|
|
|
|
|
def to_cpp_string_literal(varname, content):
|
|
return f'const char* wgsl_{varname} = R"({content})";\n'
|
|
|
|
|
|
def main():
|
|
parser = argparse.ArgumentParser()
|
|
parser.add_argument('--input', required=True)
|
|
parser.add_argument('--output', required=True)
|
|
args = parser.parse_args()
|
|
|
|
with open(args.output, 'w', encoding='utf-8') as out:
|
|
out.write("// Auto-generated shader embedding \n\n")
|
|
for fname in sorted(os.listdir(args.input)):
|
|
if not fname.endswith('.wgsl'):
|
|
continue
|
|
shader_path = os.path.join(args.input, fname)
|
|
varname = os.path.splitext(fname)[0]
|
|
with open(shader_path, 'r', encoding='utf-8') as f:
|
|
content = f.read()
|
|
content = escape_triple_quotes(content)
|
|
out.write(to_cpp_string_literal(varname, content))
|
|
out.write('\n')
|
|
|
|
|
|
if __name__ == '__main__':
|
|
main()
|