forked from tinygrad/tinygrad
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor GPU and Metal langauges in their own separate renderers (tin…
…ygrad#2033) * Refactor GPU and Metal langauges in their own separate renderers * remove CStyleLanguage imports * move renderers too
- Loading branch information
Showing
4 changed files
with
41 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import functools | ||
from tinygrad.renderer.cstyle import uops_to_cstyle, CStyleLanguage | ||
|
||
class MetalLanguage(CStyleLanguage): | ||
kernel_prefix = "#include <metal_stdlib>\nusing namespace metal;\nkernel " | ||
buffer_prefix = "device " | ||
smem_prefix = "threadgroup " | ||
arg_int_prefix = "constant int&" | ||
barrier = "threadgroup_barrier(mem_flags::mem_threadgroup);" | ||
float4 = "float4" | ||
uses_ptr_arithmetic=True | ||
gid = [f"gid.{chr(120+i)}" for i in range(3)] | ||
lid = [f"lid.{chr(120+i)}" for i in range(3)] | ||
extra_args = ['uint3 gid [[threadgroup_position_in_grid]]', 'uint3 lid [[thread_position_in_threadgroup]]'] | ||
|
||
MetalRenderer = functools.partial(uops_to_cstyle, MetalLanguage()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import functools | ||
from tinygrad.helpers import dtypes | ||
from tinygrad.renderer.cstyle import uops_to_cstyle, CStyleLanguage | ||
|
||
type_map = { dtypes.uint8: "uchar", dtypes.uint32: "uint", dtypes.uint64: "ulong" } | ||
class OpenCLLanguage(CStyleLanguage): | ||
kernel_prefix = "__kernel " | ||
buffer_prefix = "__global " | ||
smem_align = "__attribute__ ((aligned (16))) " | ||
smem_prefix = "__local " | ||
arg_int_prefix = "const int" | ||
half_prekernel = "#pragma OPENCL EXTENSION cl_khr_fp16 : enable" | ||
barrier = "barrier(CLK_LOCAL_MEM_FENCE);" | ||
float4 = "(float4)" | ||
gid = [f'get_group_id({i})' for i in range(3)] | ||
lid = [f'get_local_id({i})' for i in range(3)] | ||
uses_vload=True | ||
|
||
OpenCLRenderer = functools.partial(uops_to_cstyle, OpenCLLanguage()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters