Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 1 addition & 1 deletion sycl-jit/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ if (NOT WIN32 AND NOT CYGWIN)
endif(SYCL_JIT_ENABLE_WERROR)
endif()


add_subdirectory(jit-compiler-resource)
add_subdirectory(jit-compiler)
add_subdirectory(passes)

Expand Down
27 changes: 27 additions & 0 deletions sycl-jit/jit-compiler-resource/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# We use C23/C++26's `#embed` to implement this resource creation, and "host"
# CXX compiler might not have support for it. As such, use freshly built
# `clang++` instead. That, in turn, requires dedicated directory for CMake to
# allow to override `CMAKE_CXX_COMPILER`.


set(SYCL_JIT_RESOURCE_CPP "${CMAKE_CURRENT_BINARY_DIR}/resource.cpp")
add_custom_command(
OUTPUT ${SYCL_JIT_RESOURCE_CPP}
COMMAND ${Python3_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/generate.py --toolchain-dir ${CMAKE_BINARY_DIR} --output ${SYCL_JIT_RESOURCE_CPP} --prefix /sycl-jit-toolchain/
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
DEPENDS sycl-headers ${CMAKE_CURRENT_SOURCE_DIR}/generate.py
)

set_source_files_properties(${SYCL_JIT_RESOURCE_CPP} PROPERTIES
COMPILE_FLAGS -Wno-c23-extensions
)

add_llvm_library(sycl-jit-resource
${SYCL_JIT_RESOURCE_CPP}
OBJECT
DEPENDS
clang
# TODO: libdevice
)

set(CMAKE_CXX_COMPILER ${CMAKE_BINARY_DIR}/bin/clang++)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's not enough (see Win CI failure), but I don't know if we have some precedents to doing something similar. Any pointers would be greatly appreciated.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could try random combinations of PARENT_SCOPE CACHE and FORCE

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, maybe try setting the C compiler too because cl is both C and C++?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also doing it this way is unsupported, it seems if we make this a subproject then it will reliably work

70 changes: 70 additions & 0 deletions sycl-jit/jit-compiler-resource/generate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import os
import argparse


def main():
parser = argparse.ArgumentParser(
description="Generate SYCL Headers Resource C++ file"
)
parser.add_argument("-o", "--output", type=str, required=True, help="Output file")
parser.add_argument(
"-i",
"--toolchain-dir",
type=str,
required=True,
help="Path to toolchain root directory",
)
parser.add_argument(
"--prefix", type=str, required=True, help="Prefix for file locations"
)
args = parser.parse_args()

# abspath also strips trailing "/"
toolchain_dir = os.path.abspath(args.toolchain_dir)

with open(args.output, "w") as out:
out.write(
"""
#include <utility>
#include <string_view>

namespace jit_compiler {
extern const std::pair<std::string_view, std::string_view> ToolchainFiles[];
const std::pair<std::string_view, std::string_view> ToolchainFiles[] = {"""
)

def process_dir(dir):
for root, _, files in os.walk(dir):
for file in files:
file_path = os.path.join(root, file)
out.write(
f"""
{{
{{"{args.prefix}{os.path.relpath(file_path, toolchain_dir)}"}} ,
[]() {{
static const char data[] = {{
#embed "{file_path}"
, 0}};
return std::string_view(data);
}}()
}},"""
)

process_dir(os.path.join(args.toolchain_dir, "include/"))
process_dir(os.path.join(args.toolchain_dir, "lib/clang/"))

out.write(
f"""
}};

extern size_t NumToolchainFiles;
size_t NumToolchainFiles = std::size(ToolchainFiles);
extern std::string_view ToolchainPrefix;
std::string_view ToolchainPrefix = "{args.prefix}";
}} // namespace jit_compiler
"""
)


if __name__ == "__main__":
main()
1 change: 1 addition & 0 deletions sycl-jit/jit-compiler/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ add_llvm_library(sycl-jit
clangCodeGen
clangTooling
clangSerialization
sycl-jit-resource
)

if(WIN32)
Expand Down
Loading
Loading