xmos / ai_tools

AI applications and tools
Other
25 stars 10 forks source link

Can't build xformer #909

Closed andresovela closed 4 months ago

andresovela commented 4 months ago

I'm not familiar with Bazel, but running bazel build //:xcore-opt as suggested in the README fails with the following error:

ERROR: /home/andy/dev/projects/xmos/ai_tools/xformer/WORKSPACE:110:21: fetching new_local_repository rule //external:lib_tflmc: /home/andy/dev/projects/xmos/ai_tools/xformer/external/lib_tflmc.BUILD is not a regular file; if you're using a relative or absolute path for `build_file` in your `new_local_repository` rule, please switch to using a label instead
ERROR: no such package '@@lib_tflmc//': /home/andy/dev/projects/xmos/ai_tools/xformer/external/lib_tflmc.BUILD is not a regular file; if you're using a relative or absolute path for `build_file` in your `new_local_repository` rule, please switch to using a label instead
ERROR: /home/andy/dev/projects/xmos/ai_tools/xformer/BUILD:247:10: //:xcore-opt depends on @@lib_tflmc//:tflmc_lib in repository @@lib_tflmc which failed to fetch. no such package '@@lib_tflmc//': /home/andy/dev/projects/xmos/ai_tools/xformer/external/lib_tflmc.BUILD is not a regular file; if you're using a relative or absolute path for `build_file` in your `new_local_repository` rule, please switch to using a label instead
ERROR: Analysis of target '//:xcore-opt' failed; build aborted: Analysis failed

It seems the problem is that for some reason the build system is looking for lib_tflmc.BUILD under ai_tools/xformer/external instead of just ai_tools/xformer.

Note: I'm trying to build using Bazel 7.2.0, I updated .bazelversion to reflect my installed version.

panickal-xmos commented 4 months ago

You would have to use the supported bazel version. Could you please try building using bazelisk, as that would download the supported bazel version? As in bazelisk build //:xcore-opt.

andresovela commented 4 months ago

Using bazelisk I now do not have that problem, but the build still fails with the following error:

ERROR: /home/andy/.cache/bazel/_bazel_andy/8b429239a50f407a9e6918483356d160/external/lib_tflmc/BUILD.bazel:175:11: Compiling lib_tflite_micro/src/tflite-xcore-kernels/xcore_utils.cc failed: (Exit 1): gcc failed: error executing command (from target @lib_tflmc//:tflmc_lib) /usr/bin/gcc -U_FORTIFY_SOURCE -fstack-protector -Wall -Wunused-but-set-parameter -Wno-free-nonheap-object -fno-omit-frame-pointer '-std=c++0x' -MD -MF ... (remaining 118 arguments skipped)
In file included from external/lib_tflite_micro/lib_tflite_micro/submodules/flatbuffers/include/flatbuffers/array.h:21,
                 from external/lib_tflite_micro/lib_tflite_micro/submodules/flatbuffers/include/flatbuffers/flatbuffers.h:22,
                 from external/lib_tflite_micro/lib_tflite_micro/submodules/tflite-micro/tensorflow/lite/micro/flatbuffer_utils.h:19,
                 from external/lib_tflite_micro/lib_tflite_micro/submodules/tflite-micro/tensorflow/lite/micro/micro_allocator.h:23,
                 from external/lib_tflite_micro/lib_tflite_micro/submodules/tflite-micro/tensorflow/lite/micro/micro_resource_variable.h:22,
                 from external/lib_tflite_micro/lib_tflite_micro/submodules/tflite-micro/tensorflow/lite/micro/micro_graph.h:21,
                 from external/lib_tflite_micro/lib_tflite_micro/submodules/tflite-micro/tensorflow/lite/micro/micro_context.h:20,
                 from external/lib_tflite_micro/lib_tflite_micro/submodules/tflite-micro/tensorflow/lite/micro/kernels/kernel_util.h:26,
                 from external/lib_tflite_micro/lib_tflite_micro/src/tflite-xcore-kernels/xcore_utils.h:9,
                 from external/lib_tflite_micro/lib_tflite_micro/src/tflite-xcore-kernels/xcore_utils.cc:1:
external/lib_tflite_micro/lib_tflite_micro/submodules/flatbuffers/include/flatbuffers/stl_emulation.h: In member function 'constexpr flatbuffers::span<T, Extent>& flatbuffers::span<T, Extent>::operator=(const flatbuffers::span<T, Extent>&)':
external/lib_tflite_micro/lib_tflite_micro/submodules/flatbuffers/include/flatbuffers/stl_emulation.h:386:12: error: assignment of read-only member 'flatbuffers::span<T, Extent>::count_'
  386 |     count_ = other.count_;
      |     ~~~~~~~^~~~~~~~~~~~~~
Target //:xcore-opt failed to build
panickal-xmos commented 4 months ago

I'm not sure what's going wrong. A patch has to be applied to lib_tflite_micro repo, which maybe has not been done. Could you please try these steps, https://github.com/xmos/ai_tools/blob/develop/docs/rst/build-from-source.rst ?

andresovela commented 4 months ago

I hadn't done that, but now I did and I get the same error.

andresovela commented 4 months ago

I was able to compile xformer by manually removing const from the count_ variable the compiler is complaining about. No idea what's the right way to fix this.

panickal-xmos commented 4 months ago

ERROR: /home/andy/.cache/bazel/_bazel_andy/8b429239a50f407a9e6918483356d160/external/lib_tflmc/BUILD.bazel:175:11: Compiling lib_tflite_micro/src/tflite-xcore-kernels/xcore_utils.cc failed: (Exit 1): gcc failed: error executing command (from target @lib_tflmc//:tflmc_lib) /usr/bin/gcc -U_FORTIFY_SOURCE -fstack-protector -Wall -Wunused-but-set-parameter -Wno-free-nonheap-object -fno-omit-frame-pointer '-std=c++0x' -MD -MF ... (remaining 118 arguments skipped)

Hmmm, I wonder if "-std=c++0x" is an issue. You could try a full clean and rebuild with the instructions from the build-from-source.rst . Another option is to look through https://github.com/xmos/ai_tools/blob/develop/.github/workflows/build-and-test.yml in case you notice something that is different.

andresovela commented 4 months ago

I did run bazel clean --expunge to do a full clean (not sure what that does, just saw it on StackOverflow) and tried to build again, but I got the same error.

Nothing in particular caught my eye in the build-and-test.yml file.

I did test what I had to test already by manually patching the bad file, so I don't really need to solve this anymore. I'm not sure if you wanna keep the issue open for tracking or if we should close it considering that it apparently only affects me.

panickal-xmos commented 4 months ago

No worries, I'll close this issue for now.