Skip to content

[SYCL] Using a lambda in a kernel causes a linker crash #2376

Closed
@krasznaa

Description

@krasznaa

Dear All,

Similar to #2353 (but definitely not the same thing), I now ran into a linking issue while using lambdas. 😦

Take the following code:

// SYCL include(s).
#include <CL/sycl.hpp>

// System include(s).
#include <vector>

int main() {

   // Allocate a small buffer.
   static constexpr std::size_t BUFFER_SIZE = 1000;
   std::vector< float > testVector( BUFFER_SIZE, 1.23f );
   cl::sycl::buffer< float, 1 > testBuffer( testVector.data(), BUFFER_SIZE );

   // Set up the queue.
   cl::sycl::default_selector selector;
   cl::sycl::queue queue( selector );

   // Let the user know what device they're running on.
   cl::sycl::device device = queue.get_device();
   std::cout << "Running on device:" << std::endl;
   std::cout << "  Name  : "
             << device.get_info< cl::sycl::info::device::name >() << std::endl;
   std::cout << "  Vendor: "
             << device.get_info< cl::sycl::info::device::vendor >()
             << std::endl;

   // Set up a test lambda.
   auto testLambda = []( float value ) -> float {
      return value * 2.0f;
   };

   // A helper declaration.
   using am = cl::sycl::access::mode;

   // Submit a job on the buffer.
   const cl::sycl::range< 1 > workRange( BUFFER_SIZE );
   queue.submit( [&]( cl::sycl::handler& h ) {
         auto acc = testBuffer.get_access< am::read_write >( h );
         h.parallel_for< class func >( workRange,
                                       [=]( cl::sycl::id< 1 > id ) {
                                          if( id < BUFFER_SIZE ) {
                                             acc[ id ] =
                                                testLambda( acc[ id ] );
                                          }
                                       } );
      } );

   // Check the result.
   {
      auto acc = testBuffer.get_access< am::read >();
      std::cout << "acc[ 0 ] = " << acc[ 0 ] << std::endl;
   }

   return 0;
}

With a few-day-old version of the compiler, I get the following while trying to build it:

[bash][Elrond]:lambda > source /data/software/intel/clang/12.0.0-2020-08-24/x86_64-ubuntu1804-gcc8-opt/setup.sh 
Configured CUDA from: /data/software/cuda/10.1.243/x86_64-ubuntu1804
Configured Clang from: /data/software/intel/clang/12.0.0-2020-08-24/x86_64-ubuntu1804-gcc8-opt
[bash][Elrond]:lambda > make
clang++ -fsycl -c -o test.o test.cxx
clang++ -fsycl -o test test.o
LLVM ERROR: llvm.memmove of non-constant length not supported
PLEASE submit a bug report to https://bugs.llvm.org/ and include the crash backtrace.
Stack dump:
0.      Program arguments: /data/software/intel/clang/12.0.0-2020-08-24/x86_64-ubuntu1804-gcc8-opt/bin/llvm-spirv -o /tmp/test-50fa17-72de44.spv -spirv-max-version=1.1 -spirv-ext=+all,-SPV_INTEL_usm_storage_classes /tmp/test-0eb506.bc 
1.      Running pass 'Lower llvm.memmove into llvm.memcpy' on module '/tmp/test-0eb506.bc'.
 #0 0x00005613b2bfcd4a llvm::sys::PrintStackTrace(llvm::raw_ostream&) (/data/software/intel/clang/12.0.0-2020-08-24/x86_64-ubuntu1804-gcc8-opt/bin/llvm-spirv+0x58cd4a)
 #1 0x00005613b2bfac14 llvm::sys::RunSignalHandlers() (/data/software/intel/clang/12.0.0-2020-08-24/x86_64-ubuntu1804-gcc8-opt/bin/llvm-spirv+0x58ac14)
 #2 0x00005613b2bfad58 SignalHandler(int) (/data/software/intel/clang/12.0.0-2020-08-24/x86_64-ubuntu1804-gcc8-opt/bin/llvm-spirv+0x58ad58)
 #3 0x00007f6905d918a0 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x128a0)
 #4 0x00007f6904c46f47 raise /build/glibc-2ORdQG/glibc-2.27/signal/../sysdeps/unix/sysv/linux/raise.c:51:0
 #5 0x00007f6904c488b1 abort /build/glibc-2ORdQG/glibc-2.27/stdlib/abort.c:81:0
 #6 0x00005613b2bc2426 llvm::report_fatal_error(llvm::Twine const&, bool) (/data/software/intel/clang/12.0.0-2020-08-24/x86_64-ubuntu1804-gcc8-opt/bin/llvm-spirv+0x552426)
 #7 0x00005613b2bc2558 (/data/software/intel/clang/12.0.0-2020-08-24/x86_64-ubuntu1804-gcc8-opt/bin/llvm-spirv+0x552558)
 #8 0x00005613b2901ff5 SPIRV::SPIRVLowerMemmove::visitMemMoveInst(llvm::MemMoveInst&) (/data/software/intel/clang/12.0.0-2020-08-24/x86_64-ubuntu1804-gcc8-opt/bin/llvm-spirv+0x291ff5)
 #9 0x00005613b2900998 SPIRV::SPIRVLowerMemmove::runOnModule(llvm::Module&) (/data/software/intel/clang/12.0.0-2020-08-24/x86_64-ubuntu1804-gcc8-opt/bin/llvm-spirv+0x290998)
#10 0x00005613b2b48981 llvm::legacy::PassManagerImpl::run(llvm::Module&) (/data/software/intel/clang/12.0.0-2020-08-24/x86_64-ubuntu1804-gcc8-opt/bin/llvm-spirv+0x4d8981)
#11 0x00005613b28366c2 llvm::writeSpirv(llvm::Module*, SPIRV::TranslatorOpts const&, std::ostream&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&) (/data/software/intel/clang/12.0.0-2020-08-24/x86_64-ubuntu1804-gcc8-opt/bin/llvm-spirv+0x1c66c2)
#12 0x00005613b277f8a4 main (/data/software/intel/clang/12.0.0-2020-08-24/x86_64-ubuntu1804-gcc8-opt/bin/llvm-spirv+0x10f8a4)
#13 0x00007f6904c29b97 __libc_start_main /build/glibc-2ORdQG/glibc-2.27/csu/../csu/libc-start.c:344:0
#14 0x00005613b278edda _start (/data/software/intel/clang/12.0.0-2020-08-24/x86_64-ubuntu1804-gcc8-opt/bin/llvm-spirv+0x11edda)
llvm-foreach: Aborted (core dumped)
clang-12: error: llvm-spirv command failed with exit code 1 (use -v to see invocation)
Makefile:6: recipe for target 'test' failed
make: *** [test] Error 1
[bash][Elrond]:lambda >

I may be wrong, but I'm 99% sure that code like this did work in the past... 😕 Do you have any ideas on what's going wrong?

Cheers,
Attila

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions