Skip to content

Commit 3806d68

Browse files
Merge address sanitizer build to 6.3
1 parent 26241f2 commit 3806d68

File tree

4 files changed

+59
-8
lines changed

4 files changed

+59
-8
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ Documentation for rocFFT is available at
2828

2929
* Compilation uses amdclang++ instead of hipcc.
3030
* CLI11 replaces Boost Program Options as the command line parser for clients and samples.
31+
* Building with the address sanitizer option sets xnack+ on relevant GPU
32+
architectures and address-sanitizer support is added to runtime-compiled
33+
kernels.
3134

3235
## rocFFT 1.0.30 for ROCm 6.2.4
3336

CMakeLists.txt

Lines changed: 46 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -116,12 +116,6 @@ option(ROCFFT_RUNTIME_COMPILE_DEFAULT "Compile kernels at runtime by default" OF
116116
# Set default to OFF since users are not likely to tune
117117
option(ROCFFT_BUILD_OFFLINE_TUNER "Build with offline tuner executable rocfft_offline_tuner" OFF)
118118

119-
if(BUILD_ADDRESS_SANITIZER)
120-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address -shared-libasan")
121-
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address -shared-libasan")
122-
add_link_options(-fuse-ld=lld)
123-
endif()
124-
125119
# FOR HANDLING ENABLE/DISABLE OPTIONAL BACKWARD COMPATIBILITY for FILE/FOLDER REORG
126120
option(BUILD_FILE_REORG_BACKWARD_COMPATIBILITY "Build with file/folder reorg with backward compatibility enabled" OFF)
127121
if(BUILD_FILE_REORG_BACKWARD_COMPATIBILITY AND NOT WIN32)
@@ -138,6 +132,52 @@ if( WERROR )
138132
set( WARNING_FLAGS ${WARNING_FLAGS} -Werror )
139133
endif( )
140134

135+
set(DEFAULT_GPUS
136+
gfx803
137+
gfx900
138+
gfx906
139+
gfx908
140+
gfx90a
141+
gfx940
142+
gfx941
143+
gfx942
144+
gfx1030
145+
gfx1100
146+
gfx1101
147+
gfx1102
148+
gfx1151
149+
gfx1200
150+
gfx1201)
151+
152+
if(BUILD_ADDRESS_SANITIZER)
153+
add_compile_options(-fsanitize=address)
154+
add_link_options(-fsanitize=address)
155+
add_link_options(-shared-libasan)
156+
SET(DEFAULT_GPUS
157+
gfx908:xnack+
158+
gfx90a:xnack+
159+
gfx940:xnack+
160+
gfx941:xnack+
161+
gfx942:xnack+)
162+
add_link_options(-fuse-ld=lld)
163+
set(ROCFFT_KERNEL_CACHE_ENABLE off)
164+
add_compile_definitions(ADDRESS_SANITIZER)
165+
endif()
166+
167+
# Build only for local GPU architecture
168+
if (BUILD_LOCAL_GPU_TARGET_ONLY)
169+
message(STATUS "Building only for local GPU target")
170+
if (COMMAND rocm_local_targets)
171+
rocm_local_targets(DEFAULT_GPUS)
172+
else()
173+
message(WARNING "Unable to determine local GPU targets. Falling back to default GPUs.")
174+
endif()
175+
endif()
176+
177+
178+
set(AMDGPU_TARGETS "${DEFAULT_GPUS}" CACHE STRING "Target default GPUs if AMDGPU_TARGETS is not defined.")
179+
rocm_check_target_ids(AMDGPU_TARGETS TARGETS "${AMDGPU_TARGETS}")
180+
141181
# Use target ID syntax if supported for AMDGPU_TARGETS
142182
rocm_check_target_ids(DEFAULT_AMDGPU_TARGETS
143183
TARGETS "gfx803;gfx900;gfx906;gfx908;gfx90a;gfx940;gfx941;gfx942;gfx1030;gfx1100;gfx1101;gfx1102;gfx1151;gfx1200;gfx1201")

library/src/rtc_cache.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -565,6 +565,11 @@ std::vector<char> RTCCache::cached_compile(const std::string& kernel_na
565565
kernel_src_gen_t generate_src,
566566
const std::array<char, 32>& generator_sum)
567567
{
568+
#ifdef ADDRESS_SANITIZER
569+
// The address sanitizer is reported to work better when we include xnack+, so don't strip this
570+
// from the architecture string when building:
571+
const std::string gpu_arch = gpu_arch_with_flags;
572+
#else
568573
// Supplied gpu arch may have extra flags on it
569574
// (e.g. gfx90a:sramecc+:xnack-), Strip those from the arch name
570575
// since omitting them will generate code that handles either
@@ -573,7 +578,8 @@ std::vector<char> RTCCache::cached_compile(const std::string& kernel_na
573578
// As of this writing, there are no known performance benefits to
574579
// including the flags. If that changes, we may need to be more
575580
// selective about which flags to strip.
576-
std::string gpu_arch = gpu_arch_strip_flags(gpu_arch_with_flags);
581+
const std::string gpu_arch = gpu_arch_strip_flags(gpu_arch_with_flags);
582+
#endif
577583

578584
std::shared_future<std::vector<char>> result;
579585

library/src/rtc_compile.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,13 @@ std::vector<char> compile_inprocess(const std::string& kernel_src, const std::st
3636
std::string gpu_arch_arg = "--gpu-architecture=" + gpu_arch;
3737

3838
std::vector<const char*> options;
39-
options.reserve(4);
4039
options.push_back("-O3");
4140
options.push_back("-std=c++14");
4241
options.push_back(gpu_arch_arg.c_str());
4342
options.push_back("-mcumode");
43+
#ifdef ADDRESS_SANITIZER
44+
options.push_back("-fsanitize=address");
45+
#endif
4446

4547
auto compileResult = hiprtcCompileProgram(prog, options.size(), options.data());
4648
if(compileResult != HIPRTC_SUCCESS)

0 commit comments

Comments
 (0)