This is an archive of the discontinued LLVM Phabricator instance.

[test-suite] Bitcode tests: Update cmake to build driver and halide runtime only once.
ClosedPublic

Authored by asbirlea on Aug 3 2016, 11:30 AM.

Details

Summary

The simd_ops bitcode tests used to build the common driver and the halide runtime for each test.
Update cmake so they are build just once.
Note that in the future the halide runtime could be taken up one directory level and used in common for
multiple tests and benchmark. However building just the one .bc file into a static library failed on OSX.

Diff Detail

Repository
rL LLVM

Event Timeline

asbirlea updated this revision to Diff 66684.Aug 3 2016, 11:30 AM
asbirlea retitled this revision from to [test-suite] Bitcode tests: Update cmake to build driver and halide runtime only once..
asbirlea updated this object.
asbirlea added reviewers: mehdi_amini, MatzeB.
asbirlea added a subscriber: llvm-commits.
MatzeB accepted this revision.Aug 3 2016, 12:27 PM
MatzeB edited edge metadata.

Looks good to me when the code duplication issue is addressed:

Bitcode/simd_ops/CMakeLists.txt
9 ↗(On Diff #66684)

You can probably simplify this by leaving out the ${CMAKE_CURRENT_SOURCE_DIR}/ prefixes.

11–14 ↗(On Diff #66684)

Could you factor this code into a helper function (test_suite_add_build_dependencies(target) maybe?) so we avoid the code duplication with SingleMultiSource.cmake?

This revision is now accepted and ready to land.Aug 3 2016, 12:27 PM
asbirlea updated this revision to Diff 66701.Aug 3 2016, 1:07 PM
asbirlea edited edge metadata.

Address comments.
@MatzeB: Could you please lgtm the change?

MatzeB added a comment.Aug 3 2016, 1:10 PM

I already wanted to express with my first message that you can address the issue as you see fit and I am fine with it. Anyway here's an explicit LGTM!

@mehdi_amini: Do you have any insight into why having a single .bc into a static library is not allowed on OSX and how/if this can be bypassed?
The link error I see is "ar: no archive members specified", which I found comes up if you try something like adding a single header into a static library and force it to use CXX linker language, just like I did for the .bc.
I haven't found a solution to go around this, and it would be nice to factor out building the halide runtime between all bitcode tests coming from the Halide suite.

MatzeB added a comment.Aug 3 2016, 1:16 PM

@mehdi_amini: Do you have any insight into why having a single .bc into a static library is not allowed on OSX and how/if this can be bypassed?
The link error I see is "ar: no archive members specified", which I found comes up if you try something like adding a single header into a static library and force it to use CXX linker language, just like I did for the .bc.
I haven't found a solution to go around this, and it would be nice to factor out building the halide runtime between all bitcode tests coming from the Halide suite.

Not sure if that is what you are discussing here, but maybe the macOS build currently fails because function names are mangled with a "_" prefix, will this work correctly when you link with generic .bc files (constructed on linux I presume)?

Hmm, not the issue I was referring to right now. Looks like cmake cannot have just the .bc file in a static lib, it needs to go together with a .cpp file, then things work fine on both linux and osx.
However, it may be the linking issue we've been seeing on osx aarch64 green dragon, where the methods _*halide_name* are not found, and they do exist as *halide_name* in the halide runtime. I thought that issue is more likely related to the fact that the bot command line seems to not have the runtime file present at all, than with the name mangling...

mehdi_amini edited edge metadata.Aug 3 2016, 1:26 PM

@mehdi_amini: Do you have any insight into why having a single .bc into a static library is not allowed on OSX and how/if this can be bypassed?

It is allowed:

echo "" | clang -x c - -c -emit-llvm -o test.o
ar -rv test.a test.o
ar: creating archive test.a
a - test.o

(Now of course, if you're using ToT LLVM/Clang, you need to set DYLD_LIBRARY_PATH to points to your libLTO.dylib, there is no way the system ar can have support for "future" bitcode )

The link error I see is "ar: no archive members specified", which I found comes up if you try something like adding a single header into a static library and force it to use CXX linker language, just like I did for the .bc.

Can you post the command you're using?

asbirlea added a comment.EditedAug 3 2016, 1:28 PM

I've edited the cmake file to create two libraries:

add_library(simd_ops STATIC simd_ops.cpp)
add_library(halide_runtime STATIC ${ARCH}_halide_runtime.bc)

And duplicated all the current lines using simd_ops, with halide_runtime.
Running ninja test-suite gives the ar link error.

*Unintentionally early comment submit*

Relevant cmake part:

add_library(simd_ops STATIC simd_ops.cpp)
target_link_libraries(simd_ops)
test_suite_add_build_dependencies(simd_ops)

add_library(halide_runtime STATIC ${ARCH}_halide_runtime.bc)
target_link_libraries(halide_runtime)
test_suite_add_build_dependencies(halide_runtime)
set_target_properties(halide_runtime PROPERTIES LINKER_LANGUAGE CXX)

foreach(sourcebc ${uosources})
  string(REGEX REPLACE ".[cp]+$" "" pathbc ${sourcebc})
  string(REGEX REPLACE ".*/" "" namebc ${pathbc})
  string(REPLACE "." "" namebc ${namebc})
  set(Source ${CMAKE_CURRENT_SOURCE_DIR}/${ARCH}_tests/${namebc}.bc ${CMAKE_CURRENT_SOURCE_DIR}/${ARCH}_scalar_tests/scalar_${namebc}.bc)
  set(PROG simd_ops_${namebc})
  llvm_multisource()
  target_link_libraries(${PROG} halide_runtime)
  target_link_libraries(${PROG} simd_ops)
endforeach()

I'll land this today in the current format, but I'd like to follow up on the right way to create a library from a bitcode file.

Complete error on OSX:

Linking CXX static library Bitcode/simd_ops/libhalide_runtime.a
FAILED: : && /usr/local/Cellar/cmake/3.5.2/bin/cmake -E remove Bitcode/simd_ops/libhalide_runtime.a && /usr/bin/ar qc Bitcode/simd_ops/libhalide_runtime.a   && /usr/bin/ranlib Bitcode/simd_ops/libhalide_runtime.a && :
ar: no archive members specified

@mehdi_amini: Looks like what's missing is the "-rv" argument from your example?

This revision was automatically updated to reflect the committed changes.