Skip to content

Commit

Permalink
feat: implement cudaLaunchKernel (#34)
Browse files Browse the repository at this point in the history
Co-authored-by: Kevin Wang <kevmo314@gmail.com>
  • Loading branch information
brodeynewman and kevmo314 authored Nov 7, 2024
1 parent 47438ce commit 99562ab
Show file tree
Hide file tree
Showing 17 changed files with 2,066 additions and 36,897 deletions.
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
"variant": "cpp",
"format": "cpp",
"__nullptr": "cpp",
"__config": "cpp"
"__config": "cpp",
"__mutex_base": "cpp"
}
}
1 change: 1 addition & 0 deletions PTXEmitter
Submodule PTXEmitter added at 9f3586
1 change: 1 addition & 0 deletions codegen/annotations.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <nvml.h>
#include <cuda.h>
#include <cuda_runtime.h>

/**
*/
nvmlReturn_t nvmlInit_v2();
Expand Down
41 changes: 37 additions & 4 deletions codegen/codegen.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,25 @@
("cuMemAllocFromPoolAsync_ptsz", "cuMemAllocFromPoolAsync"),
]

# These functions are not exposed in header files, but we need to make sure they are...
# properly added to our client/server definitions.
# These, ideally, should never be added or removed.
INTERNAL_FUNCTIONS = [
"__cudaRegisterVar",
"__cudaRegisterFunction",
"__cudaRegisterFatBinary",
"__cudaRegisterFatBinaryEnd",
"__cudaPushCallConfiguration",
"__cudaPopCallConfiguration"
]

# a list of manually implemented cuda/nvml functions.
# these are automatically appended to each file; operation order is maintained as well.
MANUAL_IMPLEMENTATIONS = ["cudaMemcpy", "cudaMemcpyAsync"]

MANUAL_IMPLEMENTATIONS = [
"cudaMemcpy",
"cudaMemcpyAsync",
"cudaLaunchKernel"
]

@dataclass
class Operation:
Expand Down Expand Up @@ -215,6 +230,7 @@ def main():
)

functions_with_annotations: list[tuple[Function, Function, list[Operation]]] = []

for function in functions:
try:
annotation = next(
Expand All @@ -232,15 +248,24 @@ def main():

with open("gen_api.h", "w") as f:
lastIndex = 0
for i, (function, _, _, _) in enumerate(functions_with_annotations):

for i, (function) in enumerate(INTERNAL_FUNCTIONS):
f.write(
"#define RPC_{name} {value}\n".format(
name=function.name.format(),
name=function.format(),
value=i,
)
)
lastIndex += 1

for i, (function, _, _, _) in enumerate(functions_with_annotations):
f.write(
"#define RPC_{name} {value}\n".format(
name=function.name.format(),
value=i + lastIndex,
)
)

with open("gen_client.cpp", "w") as f:
f.write(
"#include <nvml.h>\n"
Expand Down Expand Up @@ -423,6 +448,12 @@ def main():
f.write("std::unordered_map<std::string, void *> functionMap = {\n")

# we need the base nvmlInit, this is important and should be kept here in the codegen.
for function in INTERNAL_FUNCTIONS:
f.write(
' {{"{name}", (void *){name}}},\n'.format(
name=function.format()
)
)
f.write(' {"nvmlInit", (void *)nvmlInit_v2},\n')
for function, _, _, disabled in functions_with_annotations:
if disabled: continue
Expand Down Expand Up @@ -683,6 +714,8 @@ def main():
f.write("}\n\n")

f.write("static RequestHandler opHandlers[] = {\n")
for function in INTERNAL_FUNCTIONS:
f.write(" handle_{name},\n".format(name=function.format()))
for function, _, _, disabled in functions_with_annotations:
f.write(" handle_{name},\n".format(name=function.name.format()))
f.write("};\n\n")
Expand Down
Loading

0 comments on commit 99562ab

Please sign in to comment.