FBGEMM icon indicating copy to clipboard operation
FBGEMM copied to clipboard

Clang 14 Build Failure

Open juanpaez22 opened this issue 2 years ago • 18 comments

Building FBGEMM with clang 14 fails. The errors look like this:

In file included from /home/juanpaez/FBGEMM/src/EmbeddingSpMDM.cc:11: In file included from /home/juanpaez/FBGEMM/third_party/asmjit/src/asmjit/asmjit.h:27: In file included from /home/juanpaez/FBGEMM/third_party/asmjit/src/asmjit/./core.h:2009: In file included from /home/juanpaez/FBGEMM/third_party/asmjit/src/asmjit/core/archtraits.h:28: /home/juanpaez/FBGEMM/third_party/asmjit/src/asmjit/core/../core/operand.h:910:79: error: use of bitwise '&' with boolean operands [-Werror,-Wbitwise-instead-of-logical] static inline bool isGp(const Operand_& op, uint32_t rId) noexcept { return isGp(op) & (op.id() == rId); } ^~~~~~~~~~~~~~~~~~~~~~~~~~~ && /home/juanpaez/FBGEMM/third_party/asmjit/src/asmjit/core/../core/operand.h:910:79: note: cast one or both operands to int to silence this warning

This is due to a warning thrown by asmjit, and FBGEMM compiles asmjit with -Werror flag.

asmjit has suppressed this in https://github.com/asmjit/asmjit/commit/06d0badec53710a4f572cf5642881ce570c5d274, so this should be fixable by simply updating to the latest asmjit

juanpaez22 avatar Jun 22 '22 22:06 juanpaez22

Updating to latest asmjit does cause other errors, though. Seems like kIdHost and kGroupVec no longer exist. Should either refactor to avoid using these deprecated constructs, or add compilation flag -Wno-bitwise-instead-of-logical to suppress warning and allow building with clang 14

[ 5%] Building CXX object CMakeFiles/fbgemm_generic.dir/src/EmbeddingSpMDM.cc.o /home/juanpaez/FBGEMM/src/EmbeddingSpMDM.cc:316:49: error: no member named 'kIdHost' in 'asmjit::CallConv' const int*>(asmjit::CallConv::kIdHost), ~~~~~~~~~~~~~~~~~~^ /home/juanpaez/FBGEMM/src/EmbeddingSpMDM.cc:330:49: error: no member named 'kIdHost' in 'asmjit::CallConv' const int*>(asmjit::CallConv::kIdHost), ~~~~~~~~~~~~~~~~~~^ /home/juanpaez/FBGEMM/src/EmbeddingSpMDM.cc:339:25: error: no member named 'kGroupVec' in 'asmjit::_abi_1_9::x86::Reg' x86::Reg::kGroupVec, ~~~~~~~~~~^ /home/juanpaez/FBGEMM/src/EmbeddingSpMDM.cc:344:25: error: no member named 'kGroupVec' in 'asmjit::_abi_1_9::x86::Reg' x86::Reg::kGroupVec, ~~~~~~~~~~^ /home/juanpaez/FBGEMM/src/EmbeddingSpMDM.cc:352:23: error: no member named 'kGroupGp' in 'asmjit::_abi_1_9::x86::Reg' x86::Reg::kGroupGp, ~~~~~~~~~~^

juanpaez22 avatar Jun 22 '22 22:06 juanpaez22

Hi @juanpaez22, thanks for sharing the issue! We are working on the asmjit update https://github.com/pytorch/FBGEMM/issues/1070, stay tuned!

geyyer avatar Jun 23 '22 15:06 geyyer

Thanks @geyyer ! Just as a note, the draft PR mentioned in #1070 only updates the submodule to a commit from April, whereas the clang14 problem isn't solved until commit hash 06d0badec53710a4f572cf5642881ce570c5d274 (on 6/21). If updating to the most recent causes issues, it may be easier to just add the -Wno-bitwise-instead-of-logical flag, as I see there are other warning suppressing flags being added here too.

juanpaez22 avatar Jun 23 '22 16:06 juanpaez22

Hi @geyyer -- any update or eta on this? Thanks in advance

juanpaez22 avatar Jul 05 '22 18:07 juanpaez22

Hi @juanpaez22, thanks for reminding! We have updated internal deps to d3fbf7c9bc7c1d1365a94a45614b91c5a3706b81, currently working on FBGEMM API to support it.

geyyer avatar Jul 05 '22 19:07 geyyer

https://github.com/pytorch/FBGEMM/issues/1070 is closed, with the latest asmjit upgraded in the trunk. Please feel free to reopen the issue if the asmjit Clang 14 Build failure still exists.

jianyuh avatar Jul 09 '22 20:07 jianyuh

The issue is still present-- the commit that asmjit was updated to (752eb38a4dbe590995cbadaff06baadd8378eeeb) does not contain the fix (not solved until commit hash 06d0badec53710a4f572cf5642881ce570c5d274 and improved in latest commit c59847629d3a19da4d10f0be4ac33b43fc4a100f).

Repro steps (need to be using Clang 14 compiler):

git clone --recursive https://github.com/pytorch/FBGEMM.git
cd FBGEMM
cmake -B build
make -C build

I'm unable to reopen the issue as I'm not a contributor. Can one of you please reopen? @geyyer @jianyuh

juanpaez22 avatar Jul 11 '22 18:07 juanpaez22

Hi @juanpaez22, thanks for double checking! Could you try https://github.com/pytorch/FBGEMM/pull/1202 and test if it works with Clang 14?

geyyer avatar Jul 11 '22 20:07 geyyer

Thanks @geyyer . The asmjit error seems to be gone when using the forked branch from the PR. Still seem to be a couple minor warnings that get promoted to errors due to the flags, so build still fails. E.g.:

[ 76%] Building CXX object bench/CMakeFiles/GEMMsBenchmark.dir/GEMMsBenchmark.cc.o
/home/juanpaez/FBGEMM/bench/GEMMsBenchmark.cc:125:6: error: expression result unused [-Werror,-Wunused-value]
    ((volatile char*)(llc.data()));
     ^               ~~~~~~~~~~~~
1 error generated.

juanpaez22 avatar Jul 11 '22 22:07 juanpaez22

Looks like it is something Clang-specific... I have added a compilation flag to the CMakeLists, @juanpaez22 could you re-check https://github.com/pytorch/FBGEMM/pull/1202?

geyyer avatar Jul 12 '22 16:07 geyyer

Hi @geyyer , sorry for the late reply. Still facing the same build error as above (expression result unused) with the latest #1202.

juanpaez22 avatar Jul 19 '22 04:07 juanpaez22

Thanks, @juanpaez22! I won't be able to help at this point, so pinging @jianyuh and @brad-mengchi ;-)

geyyer avatar Jul 20 '22 18:07 geyyer

@jianyuh @brad-mengchi any update on this?

juanpaez22 avatar Jul 27 '22 19:07 juanpaez22

cc @mjanderson09

This specific error is only for the GEMM benchmark not for the library (where we use ((volatile char*)(llc.data())); to flush cache). Is it possible to comment it out to unblock?

jianyuh avatar Jul 27 '22 21:07 jianyuh

Thank you! I see... I disabled FBGEMM_BUILD_BENCHMARKS to ignore the benchmarks, and that build succeeded. I believe pytorch disables this option as well (the issue first arose when trying to build pytorch from source), so I'll most likely be unblocked once #1202 goes in and promotes the asmjit version.

https://github.com/pytorch/pytorch/blob/99c464ae26ca4dbdb39e136da0f15c50d245f2d3/cmake/Dependencies.cmake#:~:text=set(FBGEMM_BUILD_BENCHMARKS%20OFF%20CACHE%20BOOL%20%22%22)

However, others building FBGEMM from source with the benchmarks using clang14 will still face this issue. Is the line causing the issue actually needed?

juanpaez22 avatar Jul 28 '22 16:07 juanpaez22

Right: FBGEMM_BUILD_BENCHMARKS is disabled for PyTorch build. https://github.com/pytorch/FBGEMM/pull/1202 , https://github.com/pytorch/pytorch/pull/82396, https://github.com/pytorch/pytorch/pull/82676, https://github.com/pytorch/FBGEMM/issues/1227, #1233 all merged.

jianyuh avatar Aug 10 '22 17:08 jianyuh

The line is needed for avoiding the cache effects in the benchmark. It will help flush the cache. We need to check the proper clang14 flags for that. But this is only for benchmark not part of the FBGEMM core lib so Clang14 build should be unblocked with the above PR/issues.

jianyuh avatar Aug 10 '22 17:08 jianyuh

As a workaround for pytorch we suppress some of the error coming from asmjit in OSS PyTorch build, see https://github.com/pytorch/pytorch/blob/8a7b4b85592dc7736cc29ede0f5f47b5f52b8965/cmake/Dependencies.cmake#L825

# See https://github.com/pytorch/pytorch/issues/74352
target_compile_options_if_supported(asmjit -Wno-deprecated-copy)
target_compile_options_if_supported(asmjit -Wno-unused-but-set-variable)

malfet avatar Aug 10 '22 20:08 malfet

Closing with https://github.com/pytorch/FBGEMM/pull/1246. Feel free to reopen if the issue still exists.

jianyuh avatar Aug 16 '22 21:08 jianyuh

I just ran into this compiling FBGEMM from source.

% clang --version
Apple clang version 14.0.0 (clang-1400.0.29.202)
Target: x86_64-apple-darwin22.1.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

...
[ 82%] Building CXX object bench/CMakeFiles/GEMMsBenchmark.dir/GEMMsBenchmark.cc.o
/Users/davidlaxer/pytorch/FBGEMM/bench/GEMMsBenchmark.cc:125:6: error: expression result unused [-Werror,-Wunused-value]
    ((volatile char*)(llc.data()));
     ^               ~~~~~~~~~~~~
1 error generated.
make[2]: *** [bench/CMakeFiles/GEMMsBenchmark.dir/GEMMsBenchmark.cc.o] Error 1
make[1]: *** [bench/CMakeFiles/GEMMsBenchmark.dir/all] Error 2
make: *** [all] Error 2

dbl001 avatar Nov 14 '22 22:11 dbl001

@dbl001 Could you comment out /Users/davidlaxer/pytorch/FBGEMM/bench/GEMMsBenchmark.cc:125 ? The line of ((volatile char*)(llc.data())); is for flushing the caches for better benchmarking the code. It doesn't affect the library build.

jianyuh avatar Nov 15 '22 08:11 jianyuh