Skip to content

Commit 6cd1236

Browse files
authored
[libspirv] Reduce CMake downstream changes (#19364)
This commit reduces the number of downstream CMake changes in libclc/libspirv. It's still not perfect in that some changes we've made impact the (upstream) OpenCL builtins as well as our SPIR-V builtins.
1 parent c018b49 commit 6cd1236

File tree

1 file changed

+27
-41
lines changed

1 file changed

+27
-41
lines changed

libclc/CMakeLists.txt

Lines changed: 27 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ configure_file( libclc.pc.in libclc.pc @ONLY )
244244
install( FILES ${CMAKE_CURRENT_BINARY_DIR}/libclc.pc DESTINATION "${CMAKE_INSTALL_DATADIR}/pkgconfig" )
245245

246246
if( ENABLE_RUNTIME_SUBNORMAL )
247-
foreach( file subnormal_use_default subnormal_disable )
247+
foreach( file IN ITEMS subnormal_use_default subnormal_disable )
248248
link_bc(
249249
TARGET ${file}
250250
RSP_DIR ${LIBCLC_ARCH_OBJFILE_DIR}
@@ -364,6 +364,7 @@ foreach( t ${LIBCLC_TARGETS_TO_BUILD} )
364364
else()
365365
set( DARCH ${ARCH} )
366366
endif()
367+
367368
# Append a variety of target- and triple-based directories to search,
368369
# increasing in specificity.
369370
list( APPEND opencl_dirs ${DARCH} ${DARCH}-${OS} ${DARCH}-${VENDOR}-${OS} )
@@ -419,13 +420,9 @@ foreach( t ${LIBCLC_TARGETS_TO_BUILD} )
419420
set( libspirv_gen_files )
420421
set( BUILD_LIBSPIRV_${t} TRUE )
421422

422-
if( NOT ARCH STREQUAL spirv AND NOT ARCH STREQUAL spirv64 )
423-
if( ARCH STREQUAL clspv OR ARCH STREQUAL clspv64 )
424-
list( APPEND libspirv_gen_files clspv-convert.cl )
425-
elseif ( NOT ENABLE_RUNTIME_SUBNORMAL )
426-
list( APPEND libspirv_gen_files spirv-convert.cl )
427-
list( APPEND libspirv_lib_files libspirv/lib/generic/subnormal_use_default.ll )
428-
endif()
423+
if ( NOT ENABLE_RUNTIME_SUBNORMAL )
424+
list( APPEND libspirv_gen_files spirv-convert.cl )
425+
list( APPEND libspirv_lib_files libspirv/lib/generic/subnormal_use_default.ll )
429426
endif()
430427

431428
libclc_configure_lib_source(
@@ -444,61 +441,61 @@ foreach( t ${LIBCLC_TARGETS_TO_BUILD} )
444441
CLANG_TRIPLE clang_triple
445442
)
446443

447-
# Some targets don't have a specific GPU to target
448-
set( build_flags )
449-
if( d STREQUAL none OR ARCH STREQUAL spirv OR ARCH STREQUAL spirv64 )
450-
# FIXME: Ideally we would not be tied to a specific PTX ISA version
451-
if( ARCH STREQUAL nvptx OR ARCH STREQUAL nvptx64 )
452-
# Disables NVVM reflection to defer to after linking
453-
list( APPEND build_flags -Xclang -target-feature -Xclang +ptx72
454-
-march=sm_86 -mllvm --nvvm-reflect-enable=false)
455-
elseif( ARCH STREQUAL amdgcn )
456-
# AMDGCN needs libclc to be compiled to high bc version since all atomic
457-
# clang builtins need to be accessible
458-
list( APPEND build_flags -mcpu=gfx942 -mllvm --amdgpu-oclc-reflect-enable=false )
459-
elseif( ARCH STREQUAL native_cpu )
460-
list( APPEND build_flags -Xclang -fsycl-is-native-cpu )
461-
endif()
462-
endif()
463-
464444
message( STATUS " device: ${d} ( ${${d}_aliases} )" )
465445

466446
if ( ARCH STREQUAL spirv OR ARCH STREQUAL spirv64 )
467-
set( opt_flags -O3 )
468-
list( APPEND build_flags -DCLC_SPIRV )
447+
set( build_flags -O0 -finline-hint-functions -DCLC_SPIRV )
448+
set( opt_flags )
469449
set( spvflags --spirv-max-version=1.1 )
470450
set( MACRO_ARCH SPIRV32 )
471451
if( ARCH STREQUAL spirv64 )
472452
set( MACRO_ARCH SPIRV64 )
473453
endif()
474454
elseif( ARCH STREQUAL clspv OR ARCH STREQUAL clspv64 )
455+
set( build_flags "-Wno-unknown-assumption" -DCLC_CLSPV )
475456
set( opt_flags -O3 )
476-
list( APPEND build_flags -DCLC_CLSPV )
477457
set( MACRO_ARCH CLSPV32 )
478458
if( ARCH STREQUAL clspv64 )
479459
set( MACRO_ARCH CLSPV64 )
480460
endif()
481461
elseif( ARCH STREQUAL nvptx OR ARCH STREQUAL nvptx64 )
462+
set( build_flags )
482463
set( opt_flags -O3 "--nvvm-reflect-enable=false" )
483464
elseif( ARCH STREQUAL amdgcn )
465+
set( build_flags )
484466
set( opt_flags -O3 --amdgpu-oclc-reflect-enable=false )
485467
elseif( ARCH STREQUAL native_cpu )
468+
set( build_flags -Xclang -fsycl-is-native-cpu )
486469
set( opt_flags -O3 )
487470
else()
471+
set( build_flags )
488472
set( opt_flags -O3 )
489473
set( MACRO_ARCH ${ARCH} )
490474
endif()
491475

476+
# Some targets don't have a specific GPU to target
477+
if( ARCH STREQUAL nvptx OR ARCH STREQUAL nvptx64 )
478+
# Disable NVVM reflection to deferring to after linking
479+
list( APPEND build_flags -Xclang -target-feature -Xclang +ptx72
480+
-march=sm_86 -mllvm --nvvm-reflect-enable=false )
481+
elseif( t STREQUAL amdgcn--amdhsa )
482+
# Disable AMDGPU reflection, deferring to after linking
483+
list( APPEND build_flags -mllvm --amdgpu-oclc-reflect-enable=false )
484+
endif()
485+
492486
set( LIBCLC_ARCH_OBJFILE_DIR "${LIBCLC_OBJFILE_DIR}/${arch_suffix}" )
493487
file( MAKE_DIRECTORY ${LIBCLC_ARCH_OBJFILE_DIR} )
494488

489+
# Build for OpenCL 3.0 independently of the target or device.
490+
list( APPEND build_flags -cl-std=CL3.0 )
491+
495492
# OpenCL 3.0 extensions
496493
string(CONCAT CL_3_0_EXTENSIONS
497494
"-cl-ext="
498495
"+__opencl_c_3d_image_writes,"
499496
"+__opencl_c_images,"
500497
"+cl_khr_3d_image_writes")
501-
list( APPEND build_flags -cl-std=CL3.0 "-Xclang" ${CL_3_0_EXTENSIONS} )
498+
list( APPEND build_flags "-Xclang" ${CL_3_0_EXTENSIONS} )
502499

503500
# Add platform specific flags
504501
if(WIN32)
@@ -543,8 +540,7 @@ foreach( t ${LIBCLC_TARGETS_TO_BUILD} )
543540
if( ARCH STREQUAL amdgcn OR ARCH STREQUAL r600 OR ARCH STREQUAL amdgcn-amdhsa )
544541
set ( private_addrspace_val 5 )
545542
endif()
546-
if( ARCH STREQUAL spirv OR ARCH STREQUAL spirv64
547-
OR ARCH STREQUAL clspv OR ARCH STREQUAL clspv64 )
543+
if( ARCH STREQUAL spirv OR ARCH STREQUAL spirv64)
548544
set ( generic_addrspace_val 4 )
549545
endif()
550546
list( APPEND build_flags
@@ -618,21 +614,11 @@ install(DIRECTORY ${LIBCLC_LIBRARY_OUTPUT_INTDIR}
618614
COMPONENT libspirv-builtins
619615
FILES_MATCHING PATTERN "libspirv-*")
620616

621-
install(DIRECTORY ${LIBCLC_LIBRARY_OUTPUT_INTDIR}
622-
DESTINATION lib${LLVM_LIBDIR_SUFFIX}
623-
COMPONENT clc-builtins
624-
FILES_MATCHING PATTERN "clc-*")
625-
626617
if( LIBCLC_GENERATE_REMANGLED_VARIANTS )
627618
install(DIRECTORY ${LIBCLC_LIBRARY_OUTPUT_INTDIR}
628619
DESTINATION lib${LLVM_LIBDIR_SUFFIX}
629620
COMPONENT libspirv-builtins
630621
FILES_MATCHING PATTERN "remangled-*libspirv-*")
631-
632-
install(DIRECTORY ${LIBCLC_LIBRARY_OUTPUT_INTDIR}
633-
DESTINATION lib${LLVM_LIBDIR_SUFFIX}
634-
COMPONENT clc-builtins
635-
FILES_MATCHING PATTERN "remangled-*clc-*")
636622
endif()
637623

638624
add_subdirectory(test)

0 commit comments

Comments
 (0)