Skip to content

Commit 0a74cbf

Browse files
authored
[libclc] Pass -fapprox-func when compiling 'native' builtins (#133119)
The libclc build system isn't well set up to pass arbitrary options to arbitrary source files in a non-intrusive way. There isn't currently any other motivating example to warrant rewriting the build system just to satisfy this requirement. So this commit uses a filename-based approach to inserting this option into the list of compile flags.
1 parent f5f4da6 commit 0a74cbf

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

libclc/CMakeLists.txt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,28 @@ if ( clspv-- IN_LIST LIBCLC_TARGETS_TO_BUILD OR clspv64-- IN_LIST LIBCLC_TARGETS
262262
set_target_properties( generate-clspv-convert.cl PROPERTIES FOLDER "libclc/Sourcegenning" )
263263
endif()
264264

265+
set_source_files_properties(
266+
${CMAKE_CURRENT_SOURCE_DIR}/generic/lib/math/native_cos.cl
267+
${CMAKE_CURRENT_SOURCE_DIR}/generic/lib/math/native_divide.cl
268+
${CMAKE_CURRENT_SOURCE_DIR}/generic/lib/math/native_exp.cl
269+
${CMAKE_CURRENT_SOURCE_DIR}/generic/lib/math/native_exp10.cl
270+
${CMAKE_CURRENT_SOURCE_DIR}/generic/lib/math/native_exp2.cl
271+
${CMAKE_CURRENT_SOURCE_DIR}/generic/lib/math/native_log.cl
272+
${CMAKE_CURRENT_SOURCE_DIR}/generic/lib/math/native_log10.cl
273+
${CMAKE_CURRENT_SOURCE_DIR}/generic/lib/math/native_log2.cl
274+
${CMAKE_CURRENT_SOURCE_DIR}/generic/lib/math/native_powr.cl
275+
${CMAKE_CURRENT_SOURCE_DIR}/generic/lib/math/native_recip.cl
276+
${CMAKE_CURRENT_SOURCE_DIR}/generic/lib/math/native_rsqrt.cl
277+
${CMAKE_CURRENT_SOURCE_DIR}/generic/lib/math/native_sin.cl
278+
${CMAKE_CURRENT_SOURCE_DIR}/generic/lib/math/native_sqrt.cl
279+
${CMAKE_CURRENT_SOURCE_DIR}/generic/lib/math/native_tan.cl
280+
${CMAKE_CURRENT_SOURCE_DIR}/amdgpu/lib/math/native_exp.cl
281+
${CMAKE_CURRENT_SOURCE_DIR}/amdgpu/lib/math/native_log.cl
282+
${CMAKE_CURRENT_SOURCE_DIR}/amdgpu/lib/math/native_log10.cl
283+
${CMAKE_CURRENT_SOURCE_DIR}/r600/lib/math/native_rsqrt.cl
284+
PROPERTIES COMPILE_OPTIONS -fapprox-func
285+
)
286+
265287
enable_testing()
266288

267289
foreach( t ${LIBCLC_TARGETS_TO_BUILD} )

libclc/cmake/modules/AddLibclc.cmake

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,11 +261,17 @@ function(add_libclc_builtin_set)
261261

262262
get_filename_component( file_dir ${file} DIRECTORY )
263263

264+
set( file_specific_compile_options )
265+
get_source_file_property( compile_opts ${file} COMPILE_OPTIONS)
266+
if( compile_opts )
267+
set( file_specific_compile_options "${compile_opts}" )
268+
endif()
269+
264270
compile_to_bc(
265271
TRIPLE ${ARG_TRIPLE}
266272
INPUT ${input_file}
267273
OUTPUT ${output_file}
268-
EXTRA_OPTS -fno-builtin -nostdlib
274+
EXTRA_OPTS -fno-builtin -nostdlib "${file_specific_compile_options}"
269275
"${ARG_COMPILE_FLAGS}" -I${CMAKE_CURRENT_SOURCE_DIR}/${file_dir}
270276
DEPENDENCIES ${input_file_dep}
271277
)

0 commit comments

Comments
 (0)