elixir-nx / xla

Pre-compiled XLA extension
Apache License 2.0
83 stars 21 forks source link

`struct CompileOptions` compiler error when linking with Bazel #13

Closed joelberkeley closed 2 years ago

joelberkeley commented 2 years ago

I'm getting a compiler error when linking to the binary. Wondered if you'd seen it before.

I'm wrapping libxla_extension with a C wrapper. Originally I was using g++ and that worked fine, but I want to use Bazel instead. However, I'm now getting the compiler error at the bottom (I've shortened it because it repeats itself). If I manually edit

..., CompileOptions{device_allocator});

to

CompileOptions c;
c.device_allocator = device_allocator;
..., c);

It compiles fine.

I've tried with Bazel 3.7.2 and 4.2.2. My gcc version is 9.3.0

In file included from xla_extension/include/tensorflow/compiler/xla/service/backend.h:28,
                 from xla_extension/include/tensorflow/compiler/xla/service/compile_only_service.h:19,
                 from xla_extension/include/tensorflow/compiler/xla/client/compile_only_client.h:21,
                 from xla_extension/include/tensorflow/compiler/xla/client/client_library.h:31,
                 from src/tensorflow/compiler/xla/client/xla_builder.cpp:19:
xla_extension/include/tensorflow/compiler/xla/service/compiler.h: In member function 'tensorflow::StatusOr<std::unique_ptr<xla::HloModule> > xla::Compiler::RunHloPasses(std::unique_ptr<xla::HloModule>, stream_executor::StreamExecutor*, stream_executor::DeviceMemoryAllocator*)':
xla_extension/include/tensorflow/compiler/xla/service/compiler.h:188:56: error: no matching function for call to 'xla::Compiler::CompileOptions::CompileOptions(<brace-enclosed initializer list>)'
  188 |                         CompileOptions{device_allocator});
      |                                                        ^
xla_extension/include/tensorflow/compiler/xla/service/compiler.h:162:10: note: candidate: 'constexpr xla::Compiler::CompileOptions::CompileOptions()'
  162 |   struct CompileOptions {
      |          ^~~~~~~~~~~~~~
xla_extension/include/tensorflow/compiler/xla/service/compiler.h:162:10: note:   candidate expects 0 arguments, 1 provided
xla_extension/include/tensorflow/compiler/xla/service/compiler.h:162:10: note: candidate: 'constexpr xla::Compiler::CompileOptions::CompileOptions(const xla::Compiler::CompileOptions&)'
xla_extension/include/tensorflow/compiler/xla/service/compiler.h:162:10: note:   no known conversion for argument 1 from 'stream_executor::DeviceMemoryAllocator*' to 'const xla::Compiler::CompileOptions&'
xla_extension/include/tensorflow/compiler/xla/service/compiler.h:162:10: note: candidate: 'constexpr xla::Compiler::CompileOptions::CompileOptions(xla::Compiler::CompileOptions&&)'
xla_extension/include/tensorflow/compiler/xla/service/compiler.h:162:10: note:   no known conversion for argument 1 from 'stream_executor::DeviceMemoryAllocator*' to 'xla::Compiler::CompileOptions&&'
seanmor5 commented 2 years ago

I believe what you are running into is some constraints on the C++ standard Bazel inserts in the compilation options. Bazel will use your system's available compilers. You can force a compiler version with export CC=/path/to/c/compiler and export CXX=/path/to/cxx/compiler. Additionally, to force specific options per compiler, you can use export BAZEL_CXXOPTS='-std=c++14' or whatever version you want. I believe the feature you're looking for is only valid in C++11 or greater (don't quote me on that).

joelberkeley commented 2 years ago

ah most helpful thanks. It worked with 14 but not 11.