Skip to content

Commit

Permalink
Actually fix 64bit cblas (#898)
Browse files Browse the repository at this point in the history
  • Loading branch information
wsmoses authored Oct 13, 2022
1 parent 736092f commit 1efa420
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 2 deletions.
2 changes: 1 addition & 1 deletion enzyme/BCLoad/BCLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ bool provideDefinitions(Module &M) {
if (!F.empty())
continue;
int index = 0;
for (auto postfix : {"", "_", "_64_", "64_"}) {
for (auto postfix : {"", "_", "_64_"}) {
std::string str;
if (strlen(postfix) == 0)
str = F.getName().str();
Expand Down
16 changes: 15 additions & 1 deletion enzyme/BCLoad/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,20 @@ ExternalProject_Add(gsl
)
set_target_properties(gsl PROPERTIES EXCLUDE_FROM_ALL TRUE)

ExternalProject_Add(gsl64
GIT_REPOSITORY https://github.com/EnzymeAD/gsl
GIT_TAG 5805b8323f75834c121fd65464cc55f2828f5b05
PREFIX gsl64
BUILD_IN_SOURCE 1
INSTALL_DIR ${CMAKE_CURRENT_BINARY_DIR}/gsl64/install
CONFIGURE_COMMAND sh -c ${CMAKE_CURRENT_SOURCE_DIR}/fixgsl64.sh
BUILD_COMMAND sh -c "$<TARGET_FILE:clang> cblas/*.c ${BC_LOAD_FLAGS} -I . -I .. -S -emit-llvm -O1"
INSTALL_COMMAND ""
UPDATE_COMMAND ""
TEST_COMMAND ""
)
set_target_properties(gsl64 PROPERTIES EXCLUDE_FROM_ALL TRUE)


ExternalProject_Add(openblas
GIT_REPOSITORY https://github.com/xianyi/OpenBLAS
Expand Down Expand Up @@ -52,7 +66,7 @@ ExternalProject_Add(fblas
)
set_target_properties(fblas PROPERTIES EXCLUDE_FROM_ALL TRUE)

add_custom_target(blasheaders cp "${CMAKE_CURRENT_SOURCE_DIR}/makeblas.cmake" "${CMAKE_CURRENT_BINARY_DIR}/gsl/CMakeLists.txt" && cd "${CMAKE_CURRENT_BINARY_DIR}/gsl" && ${CMAKE_COMMAND} . DEPENDS gsl fblas ${CMAKE_CURRENT_SOURCE_DIR}/makeblas.cmake)
add_custom_target(blasheaders cp "${CMAKE_CURRENT_SOURCE_DIR}/makeblas.cmake" "${CMAKE_CURRENT_BINARY_DIR}/gsl/CMakeLists.txt" && cd "${CMAKE_CURRENT_BINARY_DIR}/gsl" && ${CMAKE_COMMAND} . DEPENDS gsl gsl64 fblas ${CMAKE_CURRENT_SOURCE_DIR}/makeblas.cmake)
set_target_properties(blasheaders PROPERTIES EXCLUDE_FROM_ALL TRUE)
endif()

Expand Down
21 changes: 21 additions & 0 deletions enzyme/BCLoad/fixgsl64.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
OS="`uname`"

cp sys/gsl_sys.h .
cp cblas/gsl_cblas.h .
rm cblas/test*.c
echo > config.h

case $OS in
'Darwin')
sed -i.bu "s/int/int64_t/g" cblas/*.c
sed -i.bu "s/gsl\//gsl64\//g" cblas/*.c cblas/*.h gsl_math.h gsl_precision.h gsl_pow_int.h gsl_minmax.h
sed -i.bu "s/cblas_\(.*\) (/cblas_\164_ (/g" cblas/*.c
sed -i.bu "1s/^/#include <stdint.h>\n/" cblas/*.c
;;
*)
sed "s/int/int64_t/g" -i cblas/*.c
sed "s/gsl\//gsl64\//g" -i cblas/*.c cblas/*.h gsl_math.h gsl_precision.h gsl_pow_int.h gsl_minmax.h
sed "s/cblas_\(.*\) (/cblas_\164_ (/g" -i cblas/*.c
sed "1s/^/#include <stdint.h>\n/" -i cblas/*.c
;;
esac
26 changes: 26 additions & 0 deletions enzyme/BCLoad/makeblas.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,22 @@ foreach(file ${BLAS_LL})
file(APPEND ${CMAKE_CURRENT_SOURCE_DIR}/blas_headers.h "const char __data_${variableName}[] = {${arrayValues}};\n")
endforeach()

file(GLOB BLAS64_LL "${CMAKE_CURRENT_SOURCE_DIR}/../gsl64/src/gsl64/*.ll")
list(FILTER BLAS64_LL EXCLUDE REGEX ".*test.*")

foreach(file ${BLAS64_LL})
get_filename_component(variableName ${file} NAME_WE)

file(READ ${file} hexString HEX)

set(hexString "${hexString}00")

string(REGEX REPLACE "([0-9a-f][0-9a-f])" "0x\\1," arrayValues ${hexString})
string(REGEX REPLACE ",$" "" arrayValues ${arrayValues})

file(APPEND ${CMAKE_CURRENT_SOURCE_DIR}/blas_headers.h "const char __data_${variableName}64_[] = {${arrayValues}};\n")
endforeach()

file(APPEND ${CMAKE_CURRENT_SOURCE_DIR}/blas_headers.h "std::map<std::string, const char*> DATA = {\n")
foreach(file ${BLAS_LL})
get_filename_component(variableName ${file} NAME_WE)
Expand All @@ -30,6 +46,16 @@ foreach(file ${BLAS_LL})
file(APPEND ${CMAKE_CURRENT_SOURCE_DIR}/blas_headers.h "${arrayDefinition}")
set (NEED_COMMA TRUE)
endforeach()
foreach(file ${BLAS64_LL})
get_filename_component(variableName ${file} NAME_WE)
# declares byte array and the length variables
if (${NEED_COMMA})
file(APPEND ${CMAKE_CURRENT_SOURCE_DIR}/blas_headers.h ",\n")
endif()
set(arrayDefinition "{ \"cblas_${variableName}64_\", __data_${variableName}64_ }")
file(APPEND ${CMAKE_CURRENT_SOURCE_DIR}/blas_headers.h "${arrayDefinition}")
set (NEED_COMMA TRUE)
endforeach()
file(APPEND ${CMAKE_CURRENT_BINARY_DIR}/blas_headers.h "\n};\n")

file(READ "${CMAKE_CURRENT_SOURCE_DIR}/../fblas/src/fblas/bclib32.ll" hexString HEX)
Expand Down

0 comments on commit 1efa420

Please sign in to comment.