Skip to content

Commit

Permalink
Hack: Manually patch hipSYCL to enable ccache
Browse files Browse the repository at this point in the history
  • Loading branch information
psalz committed Dec 5, 2023
1 parent 7b2c401 commit c07586a
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 0 deletions.
3 changes: 3 additions & 0 deletions hipsycl/build/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ RUN bash /root/install-system.sh clang libclang-dev llvm-dev libomp-dev \

COPY common/build-with-cmake.sh build-hipsycl.sh /root/

# HACK: Until https://github.com/AdaptiveCpp/AdaptiveCpp/pull/1276 is merged, we patch it manually
COPY common/hipsycl/build/patches /root/patches/

RUN mkdir /ccache && \
mkdir -p /opt/hipsycl
ENV CCACHE_DIR=/ccache \
Expand Down
1 change: 1 addition & 0 deletions hipsycl/build/build-hipsycl.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

set -eu
rm -rf /opt/hipsycl/*
bash /patches/apply.sh
bash ~/build-with-cmake.sh /root/build /src --target install -- \
-DCMAKE_PREFIX_PATH=/usr/lib/llvm-10/lib/cmake/llvm \
-DWITH_CUDA_BACKEND=YES \
Expand Down
46 changes: 46 additions & 0 deletions hipsycl/build/patches/1276_HEAD.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
diff --git a/bin/acpp b/bin/acpp
index 7d7db4cc..2dd39fc3 100755
--- a/bin/acpp
+++ b/bin/acpp
@@ -1987,7 +1987,7 @@ if __name__ == '__main__':
if not config.has_optimization_flag():
print("acpp warning: No optimization flag was given, optimizations are "
"disabled by default. Performance may be degraded. Compile with e.g. -O2/-O3 to "
- "enable optimizations.")
+ "enable optimizations.", file=sys.stderr)

c = compiler(config)
sys.exit(c.run())
diff --git a/cmake/syclcc-launcher b/cmake/syclcc-launcher
index 41a626f8..37e884ff 100755
--- a/cmake/syclcc-launcher
+++ b/cmake/syclcc-launcher
@@ -63,14 +63,22 @@ if __name__ == '__main__':
'command [command-args...]'.format(sys.argv[0], CXX_COMPILER_ARG, SYCLCC_ARG), file=sys.stderr)
sys.exit(1)

- command_in = sys.argv[command_offset]
- command_in_args = sys.argv[command_offset + 1:]
+ # If this is a compilation step, attempt to find the expected compiler (e.g. clang++).
+ # This may not be the first argument, in case additional CMAKE_CXX_COMPILER_LAUNCHERs are set.
+ compiler_offset = command_offset
+ while compiler_offset < len(sys.argv) and (
+ not os.path.isfile(sys.argv[compiler_offset]) or
+ not os.path.samefile(cxx_compiler_exe, sys.argv[compiler_offset])):
+ compiler_offset += 1
+ is_compilation_step = compiler_offset < len(sys.argv)

- # When invoked with a command line for expected compiler (e.g. clang++), replace with a syclcc invocation.
+ # When invoked with a command line for expected compiler, replace with a syclcc invocation.
+ if is_compilation_step:
+ launcher_commands = sys.argv[command_offset:compiler_offset]
+ compiler_args = sys.argv[compiler_offset + 1:]
+ command_line = [*launcher_commands, *syclcc_exe, *syclcc_specific_args, *compiler_args]
# Otherwise, e.g. for invocations of `ar` for linking static libraries, just continue with the command as-is.
- if os.path.samefile(cxx_compiler_exe, command_in):
- command_line = [*syclcc_exe, *syclcc_specific_args, *command_in_args]
else:
- command_line = [command_in, *command_in_args]
+ command_line = sys.argv[command_offset:]

sys.exit(subprocess.run(command_line).returncode)
46 changes: 46 additions & 0 deletions hipsycl/build/patches/1276_stable.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
diff --git a/bin/syclcc-clang b/bin/syclcc-clang
index 862c7a70..00c623b3 100755
--- a/bin/syclcc-clang
+++ b/bin/syclcc-clang
@@ -1931,7 +1931,7 @@ if __name__ == '__main__':
if not config.has_optimization_flag():
print("syclcc warning: No optimization flag was given, optimizations are "
"disabled by default. Performance may be degraded. Compile with e.g. -O2/-O3 to "
- "enable optimizations.")
+ "enable optimizations.", file=sys.stderr)

c = compiler(config)
sys.exit(c.run())
diff --git a/cmake/syclcc-launcher b/cmake/syclcc-launcher
index 41a626f8..37e884ff 100755
--- a/cmake/syclcc-launcher
+++ b/cmake/syclcc-launcher
@@ -63,14 +63,22 @@ if __name__ == '__main__':
'command [command-args...]'.format(sys.argv[0], CXX_COMPILER_ARG, SYCLCC_ARG), file=sys.stderr)
sys.exit(1)

- command_in = sys.argv[command_offset]
- command_in_args = sys.argv[command_offset + 1:]
+ # If this is a compilation step, attempt to find the expected compiler (e.g. clang++).
+ # This may not be the first argument, in case additional CMAKE_CXX_COMPILER_LAUNCHERs are set.
+ compiler_offset = command_offset
+ while compiler_offset < len(sys.argv) and (
+ not os.path.isfile(sys.argv[compiler_offset]) or
+ not os.path.samefile(cxx_compiler_exe, sys.argv[compiler_offset])):
+ compiler_offset += 1
+ is_compilation_step = compiler_offset < len(sys.argv)

- # When invoked with a command line for expected compiler (e.g. clang++), replace with a syclcc invocation.
+ # When invoked with a command line for expected compiler, replace with a syclcc invocation.
+ if is_compilation_step:
+ launcher_commands = sys.argv[command_offset:compiler_offset]
+ compiler_args = sys.argv[compiler_offset + 1:]
+ command_line = [*launcher_commands, *syclcc_exe, *syclcc_specific_args, *compiler_args]
# Otherwise, e.g. for invocations of `ar` for linking static libraries, just continue with the command as-is.
- if os.path.samefile(cxx_compiler_exe, command_in):
- command_line = [*syclcc_exe, *syclcc_specific_args, *command_in_args]
else:
- command_line = [command_in, *command_in_args]
+ command_line = sys.argv[command_offset:]

sys.exit(subprocess.run(command_line).returncode)
7 changes: 7 additions & 0 deletions hipsycl/build/patches/apply.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/sh

set -o errexit -o pipefail -o noclobber -o nounset

cd /src
# We have to try two different patches depending on which hipSYCL version is checked out, as `syclcc-clang` has recently been renamed to `acpp`
git apply /root/patches/1276_stable.patch || git apply /root/patches/1276_HEAD.patch

0 comments on commit c07586a

Please sign in to comment.