Skip to content

Commit

Permalink
fix GPU + only generate files instantiations
Browse files Browse the repository at this point in the history
  • Loading branch information
philipportner committed Sep 26, 2024
1 parent 16f933c commit a629d8d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 28 deletions.
2 changes: 1 addition & 1 deletion src/runtime/local/kernels/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ if(USE_CUDA AND CMAKE_CUDA_COMPILER)
add_custom_command(
OUTPUT ${PROJECT_BINARY_DIR}/src/runtime/local/kernels/CUDAkernels.cpp ${PROJECT_SOURCE_DIR}/lib/CUDAcatalog.json
COMMAND python3 ARGS genKernelInst.py kernels.json
${PROJECT_BINARY_DIR}/src/runtime/local/kernels/CUDAkernels.cpp ${PROJECT_SOURCE_DIR}/lib/CUDAcatalog.json CUDA
${PROJECT_BINARY_DIR}/src/runtime/local/kernels/CUDAkernels ${PROJECT_SOURCE_DIR}/lib/CUDAcatalog.json CUDA
MAIN_DEPENDENCY ${PROJECT_SOURCE_DIR}/src/runtime/local/kernels/kernels.json
DEPENDS ${PROJECT_SOURCE_DIR}/src/runtime/local/kernels/genKernelInst.py
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/src/runtime/local/kernels/
Expand Down
36 changes: 9 additions & 27 deletions src/runtime/local/kernels/genKernelInst.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,10 +280,10 @@ def getDefaultHeaders() -> str:
"#include <runtime/local/context/DaphneContext.h>\n" \
"#include <runtime/local/instrumentation/KernelInstrumentation.h>\n"

def codegenKernelInfos(kernelInfos, catalog_entries) -> Tuple[str,
List[str]]:
def codegenKernelInfos(kernelInfos, catalog_entries) -> Tuple[bool, str]:
ops_inst_str: str = ""
header_str: str = getDefaultHeaders()
didGenerateCode = False

for kernelInfo in kernelInfos:
kernelTemplateInfo = kernelInfo["kernelTemplate"]
Expand Down Expand Up @@ -312,6 +312,7 @@ def codegenKernelInfos(kernelInfos, catalog_entries) -> Tuple[str,
generateKernelInstantiation(kernelTemplateInfo, instantiation,
api.get("opCodes", None), outBuf, catalog_entries, API)
ops_inst_str += outBuf.getvalue()
didGenerateCode = True
else:
if API == "CPP":
# Comment reporting the kernel name.
Expand All @@ -327,9 +328,10 @@ def codegenKernelInfos(kernelInfos, catalog_entries) -> Tuple[str,
for instantiation in kernelInfo["instantiations"]:
generateKernelInstantiation(kernelTemplateInfo, instantiation, opCodes, outBuf, catalog_entries, API)
ops_inst_str += outBuf.getvalue()
didGenerateCode = True

file = header_str + '\nextern \"C\" {\n' + ops_inst_str + "}\n"
return file
return didGenerateCode, file


if __name__ == "__main__":
Expand All @@ -355,30 +357,10 @@ def codegenKernelInfos(kernelInfos, catalog_entries) -> Tuple[str,
with open(inSpecPath, "r") as inFile:
kernelInfos = json.load(inFile)

def getTImplCount(kernelInfo):
if "api" in kernelInfo:
sum = 0
for api in kernelInfo["api"]:
if api == API:
sum += len(api['instantiations'])
return sum
else:
return len(kernelInfo['instantiations'])
kernelInfos.sort(key=getTImplCount, reverse=True)

for kernelInfo in kernelInfos:
file = codegenKernelInfos([kernelInfo], catalog_entries)
cppCodegen.append(file)
# topN = 75
# for i in range(0, topN):
# file = codegenKernelInfos([kernelInfos[i]],
# catalog_entries)
# cppCodegen.append(file)
#
# # Generate a single .cpp file for all remaining kernels
# file = codegenKernelInfos(kernelInfos[topN:],
# catalog_entries)
# cppCodegen.append(file)
didGenerateCode, file = codegenKernelInfos([kernelInfo], catalog_entries)
if didGenerateCode:
cppCodegen.append(file)

cppFiles = []
# Write the generated C++ code to separate files.
Expand All @@ -393,4 +375,4 @@ def getTImplCount(kernelInfo):
outCatalog.write(json.dumps(catalog_entries, indent=2))

# Lists all generated *.cpp files.
print(cppFiles)
# print(cppFiles)

0 comments on commit a629d8d

Please sign in to comment.