Skip to content

Commit 9756a40

Browse files
committed
Recommit "[HIP] Add option --gpu-instrument-lib="
recommit 64f7790 after fixing hip-device-libs.hip.
1 parent fef0ebb commit 9756a40

File tree

4 files changed

+26
-2
lines changed

4 files changed

+26
-2
lines changed

clang/include/clang/Driver/Options.td

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -672,6 +672,9 @@ defm gpu_allow_device_init : OptInFFlag<"gpu-allow-device-init",
672672
def gpu_max_threads_per_block_EQ : Joined<["--"], "gpu-max-threads-per-block=">,
673673
Flags<[CC1Option]>,
674674
HelpText<"Default max threads per block for kernel launch bounds for HIP">;
675+
def gpu_instrument_lib_EQ : Joined<["--"], "gpu-instrument-lib=">,
676+
HelpText<"Instrument device library for HIP, which is a LLVM bitcode containing "
677+
"__cyg_profile_func_enter and __cyg_profile_func_exit">;
675678
def libomptarget_nvptx_path_EQ : Joined<["--"], "libomptarget-nvptx-path=">, Group<i_Group>,
676679
HelpText<"Path to libomptarget-nvptx libraries">;
677680
def dD : Flag<["-"], "dD">, Group<d_Group>, Flags<[CC1Option]>,

clang/lib/Driver/ToolChains/HIP.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,17 @@ void HIPToolChain::addClangTargetOptions(
330330
RocmInstallation.addCommonBitcodeLibCC1Args(
331331
DriverArgs, CC1Args, LibDeviceFile, Wave64, DAZ, FiniteOnly,
332332
UnsafeMathOpt, FastRelaxedMath, CorrectSqrt);
333+
334+
// Add instrument lib.
335+
auto InstLib =
336+
DriverArgs.getLastArgValue(options::OPT_gpu_instrument_lib_EQ);
337+
if (InstLib.empty())
338+
return;
339+
if (llvm::sys::fs::exists(InstLib)) {
340+
CC1Args.push_back("-mlink-builtin-bitcode");
341+
CC1Args.push_back(DriverArgs.MakeArgString(InstLib));
342+
} else
343+
getDriver().Diag(diag::err_drv_no_such_file) << InstLib;
333344
}
334345
}
335346

clang/test/Driver/Inputs/hip_multiple_inputs/instrument.bc

Whitespace-only changes.

clang/test/Driver/hip-device-libs.hip

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@
9292

9393
// Test --hip-device-lib-path flag
9494
// RUN: %clang -### -target x86_64-linux-gnu \
95-
// RUN: --cuda-gpu-arch=gfx803 \
95+
// RUN: --cuda-gpu-arch=gfx803 -nogpuinc \
9696
// RUN: --hip-device-lib-path=%S/Inputs/rocm/amdgcn/bitcode \
9797
// RUN: %S/Inputs/hip_multiple_inputs/b.hip \
9898
// RUN: 2>&1 | FileCheck %s --check-prefixes=ALL,FLUSHD
@@ -101,10 +101,19 @@
101101
// Test environment variable HIP_DEVICE_LIB_PATH
102102
// RUN: env HIP_DEVICE_LIB_PATH=%S/Inputs/rocm/amdgcn/bitcode \
103103
// RUN: %clang -### -target x86_64-linux-gnu \
104-
// RUN: --cuda-gpu-arch=gfx900 \
104+
// RUN: --cuda-gpu-arch=gfx900 -nogpuinc \
105105
// RUN: %S/Inputs/hip_multiple_inputs/b.hip \
106106
// RUN: 2>&1 | FileCheck %s --check-prefixes=ALL
107107

108+
// Test --gpu-instrument-lib
109+
// RUN: %clang -### -target x86_64-linux-gnu \
110+
// RUN: --cuda-gpu-arch=gfx900 \
111+
// RUN: --rocm-path=%S/Inputs/rocm \
112+
// RUN: --gpu-instrument-lib=%S/Inputs/hip_multiple_inputs/instrument.bc \
113+
// RUN: %S/Inputs/hip_multiple_inputs/b.hip \
114+
// RUN: 2>&1 | FileCheck %s --check-prefixes=ALL,INST
115+
116+
// ALL-NOT: error:
108117
// ALL: {{"[^"]*clang[^"]*"}}
109118
// ALL-SAME: "-mlink-builtin-bitcode" "{{.*}}hip.bc"
110119
// ALL-SAME: "-mlink-builtin-bitcode" "{{.*}}ocml.bc"
@@ -118,3 +127,4 @@
118127
// ALL-SAME: "-mlink-builtin-bitcode" "{{.*}}oclc_correctly_rounded_sqrt_on.bc"
119128
// ALL-SAME: "-mlink-builtin-bitcode" "{{.*}}oclc_wavefrontsize64_on.bc"
120129
// ALL-SAME: "-mlink-builtin-bitcode" "{{.*}}oclc_isa_version_{{[0-9]+}}.bc"
130+
// INST-SAME: "-mlink-builtin-bitcode" "{{.*}}instrument.bc"

0 commit comments

Comments
 (0)