diff --git a/libclc/CMakeLists.txt b/libclc/CMakeLists.txt --- a/libclc/CMakeLists.txt +++ b/libclc/CMakeLists.txt @@ -39,12 +39,6 @@ set( LIBCLC_TARGETS_ALL ${LIBCLC_TARGETS_ALL} amdgcn-mesa-mesa3d ) endif() -if( LIBCLC_TARGETS_TO_BUILD STREQUAL "all" ) - set( LIBCLC_TARGETS_TO_BUILD ${LIBCLC_TARGETS_ALL} ) -endif() - -list( SORT LIBCLC_TARGETS_TO_BUILD ) - execute_process( COMMAND ${LLVM_CONFIG} "--system-libs" OUTPUT_VARIABLE LLVM_SYSTEM_LIBS OUTPUT_STRIP_TRAILING_WHITESPACE ) @@ -83,17 +77,29 @@ find_program( LLVM_AS llvm-as PATHS ${LLVM_BINDIR} NO_DEFAULT_PATH ) find_program( LLVM_LINK llvm-link PATHS ${LLVM_BINDIR} NO_DEFAULT_PATH ) find_program( LLVM_OPT opt PATHS ${LLVM_BINDIR} NO_DEFAULT_PATH ) +find_program( LLVM_SPIRV llvm-spirv PATHS ${LLVM_BINDIR} NO_DEFAULT_PATH ) # Print toolchain message( "clang: ${LLVM_CLANG}" ) message( "llvm-as: ${LLVM_AS}" ) message( "llvm-link: ${LLVM_LINK}" ) message( "opt: ${LLVM_OPT}" ) +message( "llvm-spirv: ${LLVM_SPIRV}" ) message( "" ) if( NOT LLVM_CLANG OR NOT LLVM_OPT OR NOT LLVM_AS OR NOT LLVM_LINK ) message( FATAL_ERROR "toolchain incomplete!" ) endif() +if( LLVM_SPIRV ) + list( APPEND LIBCLC_TARGETS_ALL spirv-mesa3d-dxil ) +endif() + +if( LIBCLC_TARGETS_TO_BUILD STREQUAL "all" ) + set( LIBCLC_TARGETS_TO_BUILD ${LIBCLC_TARGETS_ALL} ) +endif() + +list( SORT LIBCLC_TARGETS_TO_BUILD ) + set( CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake ) set( CMAKE_CLC_COMPILER ${LLVM_CLANG} ) set( CMAKE_CLC_ARCHIVE ${LLVM_LINK} ) @@ -127,6 +133,7 @@ set( nvptx64--_devices none ) set( nvptx--nvidiacl_devices none ) set( nvptx64--nvidiacl_devices none ) +set( spirv-mesa3d-dxil_devices none ) # Setup aliases set( cedar_aliases palm sumo sumo2 redwood juniper ) @@ -177,7 +184,10 @@ list( GET TRIPLE 1 VENDOR ) list( GET TRIPLE 2 OS ) - set( dirs generic ) + if ( NOT ${ARCH} STREQUAL spirv ) + set( dirs generic ) + endif() + if( ${ARCH} STREQUAL r600 OR ${ARCH} STREQUAL amdgcn ) set( dirs ${dirs} amdgpu ) endif() @@ -205,10 +215,15 @@ # Add the generated convert.cl here to prevent adding # the one listed in SOURCES - set( rel_files convert.cl ) - set( objects convert.cl ) - if( NOT ENABLE_RUNTIME_SUBNORMAL ) - list( APPEND rel_files generic/lib/subnormal_use_default.ll ) + if( NOT ${ARCH} STREQUAL spirv ) + set( rel_files convert.cl ) + set( objects convert.cl ) + if( NOT ENABLE_RUNTIME_SUBNORMAL ) + list( APPEND rel_files generic/lib/subnormal_use_default.ll ) + endif() + else() + set( rel_files ) + set( objects ) endif() foreach( l ${source_list} ) @@ -232,12 +247,28 @@ foreach( d ${${t}_devices} ) # Some targets don't have a specific GPU to target - if( ${d} STREQUAL "none" ) + if( ${ARCH} STREQUAL spirv ) set( mcpu ) set( arch_suffix "${t}" ) + set( t "spir--" ) + set( dflags "-DCLC_SPIRV" ) + set( oflags -O0 -finline-hint-functions ) + set( ooflags --structurizecfg ) + if( ${OS} STREQUAL dxil ) + set( spvflags --spirv-max-version=1.1 --spirv-ocl-builtins-version=1.2 ) + endif() + elseif( ${d} STREQUAL "none" ) + set( mcpu ) + set( arch_suffix "${t}" ) + set( dflags ) + set( oflags ) + set( ooflags -O3 ) else() set( mcpu "-mcpu=${d}" ) set( arch_suffix "${d}-${t}" ) + set( dflags ) + set( oflags ) + set( ooflags -O3 ) endif() message( " DEVICE: ${d} ( ${${d}_aliases} )" ) @@ -252,50 +283,62 @@ target_compile_definitions( builtins.link.${arch_suffix} PRIVATE "__CLC_INTERNAL" ) target_compile_options( builtins.link.${arch_suffix} PRIVATE -target - ${t} ${mcpu} -fno-builtin ) + ${t} ${mcpu} -fno-builtin ${dflags} ${oflags} ) set_target_properties( builtins.link.${arch_suffix} PROPERTIES LINKER_LANGUAGE CLC ) - set( obj_suffix ${arch_suffix}.bc ) - # Add opt target + set( obj_suffix ${arch_suffix}.bc ) add_custom_command( OUTPUT "builtins.opt.${obj_suffix}" - COMMAND ${LLVM_OPT} -O3 -o + COMMAND ${LLVM_OPT} ${ooflags} -o "builtins.opt.${obj_suffix}" "builtins.link.${obj_suffix}" DEPENDS "builtins.link.${arch_suffix}" ) add_custom_target( "opt.${obj_suffix}" ALL DEPENDS "builtins.opt.${obj_suffix}" ) - # Add prepare target - add_custom_command( OUTPUT "${obj_suffix}" - COMMAND prepare_builtins -o - "${obj_suffix}" - "builtins.opt.${obj_suffix}" - DEPENDS "opt.${obj_suffix}" - "builtins.opt.${obj_suffix}" - prepare_builtins ) - add_custom_target( "prepare-${obj_suffix}" ALL - DEPENDS "${obj_suffix}" ) - install( FILES ${CMAKE_CURRENT_BINARY_DIR}/${obj_suffix} DESTINATION ${CMAKE_INSTALL_DATADIR}/clc ) - # nvptx-- targets don't include workitem builtins - if( NOT ${t} MATCHES ".*ptx.*--$" ) - add_test( NAME external-calls-${obj_suffix} - COMMAND ./check_external_calls.sh ${CMAKE_CURRENT_BINARY_DIR}/${obj_suffix} - WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} ) - set_tests_properties( external-calls-${obj_suffix} - PROPERTIES ENVIRONMENT "LLVM_CONFIG=${LLVM_CONFIG}" ) - endif() + if( ${ARCH} STREQUAL spirv ) + set( spv_suffix ${arch_suffix}.spv ) + add_custom_command( OUTPUT "${spv_suffix}" + COMMAND ${LLVM_SPIRV} ${spvflags} + -o "${spv_suffix}" + "builtins.opt.${obj_suffix}" + DEPENDS "builtins.opt.${obj_suffix}" ) + add_custom_target( "prepare-${spv_suffix}" ALL + DEPENDS "${spv_suffix}" ) + install( FILES ${CMAKE_CURRENT_BINARY_DIR}/${spv_suffix} DESTINATION ${CMAKE_INSTALL_DATADIR}/clc ) + else() + # Add prepare target + add_custom_command( OUTPUT "${obj_suffix}" + COMMAND prepare_builtins -o + "${obj_suffix}" + "builtins.opt.${obj_suffix}" + DEPENDS "opt.${obj_suffix}" + "builtins.opt.${obj_suffix}" + prepare_builtins ) + add_custom_target( "prepare-${obj_suffix}" ALL + DEPENDS "${obj_suffix}" ) + + # nvptx-- targets don't include workitem builtins + if( NOT ${t} MATCHES ".*ptx.*--$" ) + add_test( NAME external-calls-${obj_suffix} + COMMAND ./check_external_calls.sh ${CMAKE_CURRENT_BINARY_DIR}/${obj_suffix} + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} ) + set_tests_properties( external-calls-${obj_suffix} + PROPERTIES ENVIRONMENT "LLVM_CONFIG=${LLVM_CONFIG}" ) + endif() - foreach( a ${${d}_aliases} ) - set( alias_suffix "${a}-${t}.bc" ) - add_custom_target( ${alias_suffix} ALL - COMMAND ${CMAKE_COMMAND} -E - create_symlink ${obj_suffix} - ${alias_suffix} - DEPENDS "prepare-${obj_suffix}" ) - install( FILES ${CMAKE_CURRENT_BINARY_DIR}/${alias_suffix} DESTINATION ${CMAKE_INSTALL_DATADIR}/clc ) - endforeach( a ) + install( FILES ${CMAKE_CURRENT_BINARY_DIR}/${obj_suffix} DESTINATION ${CMAKE_INSTALL_DATADIR}/clc ) + foreach( a ${${d}_aliases} ) + set( alias_suffix "${a}-${t}.bc" ) + add_custom_target( ${alias_suffix} ALL + COMMAND ${CMAKE_COMMAND} -E + create_symlink ${obj_suffix} + ${alias_suffix} + DEPENDS "prepare-${obj_suffix}" ) + install( FILES ${CMAKE_CURRENT_BINARY_DIR}/${alias_suffix} DESTINATION ${CMAKE_INSTALL_DATADIR}/clc ) + endforeach( a ) + endif() endforeach( d ) endforeach( t ) diff --git a/libclc/generic/include/clc/clcfunc.h b/libclc/generic/include/clc/clcfunc.h --- a/libclc/generic/include/clc/clcfunc.h +++ b/libclc/generic/include/clc/clcfunc.h @@ -1,4 +1,10 @@ #define _CLC_OVERLOAD __attribute__((overloadable)) #define _CLC_DECL -#define _CLC_DEF __attribute__((always_inline)) #define _CLC_INLINE __attribute__((always_inline)) inline + +/* avoid inlines for SPIR-V since we'll optimise later in the chain */ +#ifdef CLC_SPIRV +#define _CLC_DEF +#else +#define _CLC_DEF __attribute__((always_inline)) +#endif diff --git a/libclc/generic/lib/common/smoothstep.cl b/libclc/generic/lib/common/smoothstep.cl --- a/libclc/generic/lib/common/smoothstep.cl +++ b/libclc/generic/lib/common/smoothstep.cl @@ -46,10 +46,12 @@ _CLC_TERNARY_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, double, smoothstep, double, double, double); +#ifndef CLC_SPIRV SMOOTH_STEP_DEF(float, double, SMOOTH_STEP_IMPL_D); SMOOTH_STEP_DEF(double, float, SMOOTH_STEP_IMPL_D); _CLC_V_S_S_V_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, double, smoothstep, float, float, double); _CLC_V_S_S_V_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, float, smoothstep, double, double, float); +#endif #endif diff --git a/libclc/generic/lib/common/step.cl b/libclc/generic/lib/common/step.cl --- a/libclc/generic/lib/common/step.cl +++ b/libclc/generic/lib/common/step.cl @@ -45,10 +45,12 @@ _CLC_BINARY_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, double, step, double, double); _CLC_V_S_V_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, double, step, double, double); +#ifndef CLC_SPIRV STEP_DEF(float, double); STEP_DEF(double, float); _CLC_V_S_V_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, double, step, float, double); _CLC_V_S_V_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, float, step, double, float); +#endif #endif diff --git a/libclc/spirv-mesa3d-dxil/lib/SOURCES b/libclc/spirv-mesa3d-dxil/lib/SOURCES new file mode 100644 --- /dev/null +++ b/libclc/spirv-mesa3d-dxil/lib/SOURCES @@ -0,0 +1,82 @@ +subnormal_config.cl +../../generic/lib/common/degrees.cl +../../generic/lib/common/mix.cl +../../generic/lib/common/radians.cl +../../generic/lib/common/sign.cl +../../generic/lib/common/smoothstep.cl +../../generic/lib/common/step.cl +../../generic/lib/geometric/cross.cl +../../generic/lib/geometric/distance.cl +../../generic/lib/geometric/dot.cl +../../generic/lib/geometric/fast_distance.cl +../../generic/lib/geometric/fast_length.cl +../../generic/lib/geometric/fast_normalize.cl +../../generic/lib/geometric/length.cl +../../generic/lib/geometric/normalize.cl +../../generic/lib/integer/rotate.cl +../../generic/lib/integer/mad_sat.cl +../../generic/lib/math/acos.cl +../../generic/lib/math/acosh.cl +../../generic/lib/math/acospi.cl +../../generic/lib/math/asin.cl +../../generic/lib/math/asinh.cl +../../generic/lib/math/asinpi.cl +../../generic/lib/math/atan.cl +../../generic/lib/math/atan2.cl +../../generic/lib/math/atan2pi.cl +../../generic/lib/math/atanh.cl +../../generic/lib/math/atanpi.cl +../../generic/lib/math/cbrt.cl +../../generic/lib/math/cos.cl +../../generic/lib/math/cosh.cl +../../generic/lib/math/cospi.cl +../../generic/lib/math/ep_log.cl +../../generic/lib/math/erf.cl +../../generic/lib/math/erfc.cl +../../generic/lib/math/exp.cl +../../generic/lib/math/exp_helper.cl +../../generic/lib/math/expm1.cl +../../generic/lib/math/exp2.cl +../../generic/lib/math/clc_exp10.cl +../../generic/lib/math/exp10.cl +../../generic/lib/math/fract.cl +../../generic/lib/math/frexp.cl +../../generic/lib/math/half_rsqrt.cl +../../generic/lib/math/half_sqrt.cl +../../generic/lib/math/clc_hypot.cl +../../generic/lib/math/hypot.cl +../../generic/lib/math/ilogb.cl +../../generic/lib/math/lgamma.cl +../../generic/lib/math/lgamma_r.cl +../../generic/lib/math/log.cl +../../generic/lib/math/log10.cl +../../generic/lib/math/log1p.cl +../../generic/lib/math/log2.cl +../../generic/lib/math/logb.cl +../../generic/lib/math/modf.cl +../../generic/lib/math/tables.cl +../../generic/lib/math/clc_pow.cl +../../generic/lib/math/pow.cl +../../generic/lib/math/clc_pown.cl +../../generic/lib/math/pown.cl +../../generic/lib/math/clc_powr.cl +../../generic/lib/math/powr.cl +../../generic/lib/math/clc_remainder.cl +../../generic/lib/math/remainder.cl +../../generic/lib/math/clc_remquo.cl +../../generic/lib/math/remquo.cl +../../generic/lib/math/clc_rootn.cl +../../generic/lib/math/rootn.cl +../../generic/lib/math/sin.cl +../../generic/lib/math/sincos.cl +../../generic/lib/math/sincos_helpers.cl +../../generic/lib/math/sinh.cl +../../generic/lib/math/sinpi.cl +../../generic/lib/math/clc_tan.cl +../../generic/lib/math/tan.cl +../../generic/lib/math/tanh.cl +../../generic/lib/math/clc_tanpi.cl +../../generic/lib/math/tanpi.cl +../../generic/lib/math/tgamma.cl +../../generic/lib/shared/vload.cl +../../generic/lib/shared/vstore.cl diff --git a/libclc/generic/lib/common/step.cl b/libclc/spirv-mesa3d-dxil/lib/subnormal_config.cl copy from libclc/generic/lib/common/step.cl copy to libclc/spirv-mesa3d-dxil/lib/subnormal_config.cl --- a/libclc/generic/lib/common/step.cl +++ b/libclc/spirv-mesa3d-dxil/lib/subnormal_config.cl @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014,2015 Advanced Micro Devices, Inc. + * Copyright (c) 2015 Advanced Micro Devices, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -22,33 +22,17 @@ #include -#include "../clcmacro.h" +#include "config.h" -_CLC_OVERLOAD _CLC_DEF float step(float edge, float x) { - return x < edge ? 0.0f : 1.0f; +_CLC_DEF bool __clc_fp16_subnormals_supported() { + return false; } -_CLC_BINARY_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, float, step, float, float); - -_CLC_V_S_V_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, float, step, float, float); - -#ifdef cl_khr_fp64 -#pragma OPENCL EXTENSION cl_khr_fp64 : enable - -#define STEP_DEF(edge_type, x_type) \ - _CLC_OVERLOAD _CLC_DEF x_type step(edge_type edge, x_type x) { \ - return x < edge ? 0.0 : 1.0; \ - } - -STEP_DEF(double, double); - -_CLC_BINARY_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, double, step, double, double); -_CLC_V_S_V_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, double, step, double, double); - -STEP_DEF(float, double); -STEP_DEF(double, float); +_CLC_DEF bool __clc_fp32_subnormals_supported() { + return false; +} -_CLC_V_S_V_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, double, step, float, double); -_CLC_V_S_V_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, float, step, double, float); +_CLC_DEF bool __clc_fp64_subnormals_supported() { + return false; +} -#endif