-
Notifications
You must be signed in to change notification settings - Fork 371
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
rs_free_function #1494
Merged
lgritz
merged 4 commits into
AcademySoftwareFoundation:main
from
steenax86:rs_free_function
May 4, 2022
Merged
rs_free_function #1494
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
f8a158d
In order to move towards shader execution on devices, we need to replace
steenax86 3bcc8e2
Fixed cuda.macro to use new location of serialize-bc.py in src/build-…
steenax86 f3198b3
Disabled erasing llvm.global_ctors from LLVM module because of issues…
steenax86 c0ee2dd
Added better error checking for module_from_bitcode().
steenax86 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
# Copyright Contributors to the Open Shading Language project. | ||
# SPDX-License-Identifier: BSD-3-Clause | ||
# https://github.com/AcademySoftwareFoundation/OpenShadingLanguage | ||
|
||
|
||
function ( EMBED_LLVM_BITCODE_IN_CPP src_list suffix output_name list_to_append_cpp extra_clang_args) | ||
|
||
if (VERBOSE) | ||
message (STATUS "EMBED_LLVM_BITCODE_IN_CPP src_list=${src_list}") | ||
endif () | ||
|
||
foreach ( src ${src_list} ) | ||
get_filename_component ( src_we ${src} NAME_WE ) | ||
set ( src_asm "${CMAKE_CURRENT_BINARY_DIR}/${src_we}${suffix}.s" ) | ||
set ( src_bc "${CMAKE_CURRENT_BINARY_DIR}/${src_we}${suffix}.bc" ) | ||
if (VERBOSE) | ||
message (STATUS "EMBED_LLVM_BITCODE_IN_CPP in=${src}") | ||
message (STATUS "EMBED_LLVM_BITCODE_IN_CPP asm=${src_asm}") | ||
message (STATUS "EMBED_LLVM_BITCODE_IN_CPP bc=${src_bc}") | ||
endif () | ||
list ( APPEND src_bc_list ${src_bc} ) | ||
|
||
get_property (CURRENT_DEFINITIONS DIRECTORY PROPERTY COMPILE_DEFINITIONS) | ||
if (VERBOSE) | ||
message (STATUS "Current #defines are ${CURRENT_DEFINITIONS}") | ||
endif () | ||
foreach (def ${CURRENT_DEFINITIONS}) | ||
set (LLVM_COMPILE_FLAGS ${LLVM_COMPILE_FLAGS} "-D${def}") | ||
endforeach() | ||
set (LLVM_COMPILE_FLAGS ${LLVM_COMPILE_FLAGS} ${SIMD_COMPILE_FLAGS} ${CSTD_FLAGS} ${TOOLCHAIN_FLAGS}) | ||
# Avoid generating __dso_handle external global | ||
set (LLVM_COMPILE_FLAGS ${LLVM_COMPILE_FLAGS} "-fno-use-cxa-atexit") | ||
|
||
# Figure out what program we will use to make the bitcode. | ||
if (NOT LLVM_BC_GENERATOR) | ||
find_program (LLVM_BC_GENERATOR NAMES "clang++" | ||
PATHS "${LLVM_DIRECTORY}/bin" | ||
NO_CMAKE_PATH NO_DEFAULT_PATH NO_CMAKE_SYSTEM_PATH | ||
NO_SYSTEM_ENVIRONMENT_PATH NO_CMAKE_ENVIRONMENT_PATH) | ||
endif () | ||
# If that didn't work, look anywhere | ||
if (NOT LLVM_BC_GENERATOR) | ||
# Wasn't in their build, look anywhere | ||
find_program (LLVM_BC_GENERATOR NAMES clang++ llvm-g++) | ||
endif () | ||
|
||
if (NOT LLVM_BC_GENERATOR) | ||
message (FATAL_ERROR "You must have a valid llvm bitcode generator (clang++) somewhere.") | ||
endif () | ||
if (VERBOSE) | ||
message (STATUS "Using LLVM_BC_GENERATOR ${LLVM_BC_GENERATOR} to generate bitcode.") | ||
endif() | ||
|
||
# Fix specific problem I had on new Apple systems (e.g. Mavericks) with | ||
# LLVM/libc++ installed -- for some reason, LLVM 3.4 wasn't finding it, | ||
# so in that specific case, append another -I to point it in the right | ||
# direction. | ||
#if (APPLE AND ${LLVM_BC_GENERATOR} MATCHES ".*clang.*") | ||
# exec_program ( "${LLVM_BC_GENERATOR}" ARGS --version OUTPUT_VARIABLE MY_CLANG_VERSION ) | ||
# string (REGEX REPLACE "clang version ([0-9][.][0-9]+).*" "\\1" MY_CLANG_VERSION "${MY_CLANG_VERSION}") | ||
# if ((${MY_CLANG_VERSION} VERSION_GREATER "3.3") | ||
# AND (EXISTS "/usr/lib/libc++.dylib") | ||
# AND (EXISTS "/Library/Developer/CommandLineTools/usr/lib/c++/v1")) | ||
# set (LLVM_COMPILE_FLAGS ${LLVM_COMPILE_FLAGS} "-I/Library/Developer/CommandLineTools/usr/lib/c++/v1") | ||
# endif () | ||
#endif () | ||
|
||
list (TRANSFORM IMATH_INCLUDES PREPEND -I | ||
OUTPUT_VARIABLE ALL_IMATH_INCLUDES) | ||
list (TRANSFORM OPENEXR_INCLUDES PREPEND -I | ||
OUTPUT_VARIABLE ALL_OPENEXR_INCLUDES) | ||
list (TRANSFORM OpenImageIO_INCLUDES PREPEND -I | ||
OUTPUT_VARIABLE ALL_OpenImageIO_INCLUDES) | ||
|
||
|
||
# Command to turn the .cpp file into LLVM assembly language .s, into | ||
# LLVM bitcode .bc, then back into a C++ file with the bc embedded! | ||
add_custom_command ( OUTPUT ${src_bc} | ||
COMMAND ${LLVM_BC_GENERATOR} | ||
${LLVM_COMPILE_FLAGS} | ||
"-I${CMAKE_CURRENT_SOURCE_DIR}" | ||
"-I${CMAKE_SOURCE_DIR}/src/include" | ||
"-I${CMAKE_BINARY_DIR}/include" | ||
${ALL_OpenImageIO_INCLUDES} | ||
${ALL_IMATH_INCLUDES} | ||
#"-isystem ${Boost_INCLUDE_DIRS}" #Does not pick up usr installed boost/thread/tss.hpp for oslexec_pvt.h | ||
"-I${Boost_INCLUDE_DIRS}" | ||
-DOSL_COMPILING_TO_BITCODE=1 | ||
-Wno-deprecated-register | ||
# the following 2 warnings can be restored when all 3rd parties have fixed their export macros | ||
# (dllimport attribute is not supported when compiling for Cuda and triggers a ton of warnings) | ||
-Wno-ignored-attributes -Wno-unknown-attributes | ||
-O3 -fno-math-errno -S -emit-llvm ${extra_clang_args} | ||
-o ${src_asm} ${src} | ||
COMMAND "${LLVM_DIRECTORY}/bin/llvm-as" -f -o ${src_bc} ${src_asm} | ||
# Do NOT setup a MAIN_DEPENDENCY because only 1 may exist | ||
# and we may have the several outputs dependant on the same source | ||
DEPENDS ${src} ${exec_headers} ${PROJECT_PUBLIC_HEADERS} | ||
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" ) | ||
endforeach () | ||
|
||
|
||
if (VERBOSE) | ||
message ( STATUS "^^^^^^^^^^^^^^^^^^^^^^^^^^" ) | ||
message ( STATUS "src_bc_list: ${src_bc_list} ") | ||
message ( STATUS "^^^^^^^^^^^^^^^^^^^^^^^^^^" ) | ||
endif() | ||
|
||
# Link all of the individual LLVM bitcode files | ||
set ( linked_src_bc "${CMAKE_CURRENT_BINARY_DIR}/${output_name}.bc" ) | ||
add_custom_command ( OUTPUT ${linked_src_bc} | ||
COMMAND "${LLVM_DIRECTORY}/bin/llvm-link" -internalize ${src_bc_list} -o ${linked_src_bc} | ||
DEPENDS ${src_bc_list} ${exec_headers} ${PROJECT_PUBLIC_HEADERS} ${src_list} | ||
WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}" ) | ||
|
||
# Serialize the linked bitcode into a CPP file | ||
set ( src_bc_cpp "${CMAKE_CURRENT_BINARY_DIR}/${output_name}.bc.cpp" ) | ||
add_custom_command ( OUTPUT ${src_bc_cpp} | ||
COMMAND python "${CMAKE_SOURCE_DIR}/src/build-scripts/serialize-bc.py" | ||
${linked_src_bc} ${src_bc_cpp} ${output_name} | ||
DEPENDS "${CMAKE_SOURCE_DIR}/src/build-scripts/serialize-bc.py" ${linked_src_bc} | ||
${exec_headers} ${PROJECT_PUBLIC_HEADERS} | ||
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" ) | ||
|
||
# add generated .cpp with embedded bitcode to the list of soures | ||
set ( ${list_to_append_cpp} ${${list_to_append_cpp}} ${src_bc_cpp} PARENT_SCOPE ) | ||
|
||
endfunction ( ) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be good to unify this with
MAKE_CUDA_BITCODE
at some point, since they're largely identical. And to generalize to other targets like SPIR-V. But that can wait until we're compiling for other non-host targets.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed, they are very similar, but our ability to test the CUDA path is limited and we don't want to break it by accident, or create merge issues for any changes in the MAKE_CUDA_BITCODE that might happen. Maybe an interim solution would be to move both macros to a common file, so at least there right next to each other for reference.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is just fine for now. It'll be something to keep in mind when the time comes to add
MAKE_SPIRV_BITCODE
, or whatever the next target might be.