构建TensorFlow时的歧义错误
我正在从官方仓库的发行分支v2.20.0的源码构建TensorFlow 2.20.0
使用ROCm,编译选项为 -march=native
我使用以下配置:
export HERMETIC_PYTHON_VERSION=3.13
export ROCM_PATH=/opt/rocm/
export PATH="$PATH:/opt/rocm/bin"
Tools:
Python 3.13
Clang version 18.1.8
Bazel 7.4.1 (via bazelisk)
就像官方页面上所说的一样!在此添加图片描述
在Linux 6.19.6-arch1-1 x86_64上
我使用的命令:
bazel build //tensorflow/tools/pip_package:wheel --repo_env=USE_PYWRAP_RULES=1 --repo_env=WHEEL_NAME=tensorflow_cpu --copt=-w --config=nonccl -j 16
但在构建fft时一直失败:类似如下的错误:
call of overloaded ‘raw(ptrdiff_t)’ is ambiguous
if (src == &dst.raw(it.oofs(0))) return; // in-place
bazel-out/k8-opt/bin/external/ducc/_virtual_includes/fft/ducc/src/ducc0/fft/fftnd_impl.h:486:22: note: there are 2 candidates
external/ducc/src/ducc0/infra/mav.h:118:35: note: candidate 1: ‘const T& ducc0::detail_mav::cmembuf::raw(I) const [with I = long int; T = double]’
118 | templateconst T &raw(I i) const
./configure文件如下:
build --action_env PYTHON_BIN_PATH="/usr/bin/python3.13"
build --action_env PYTHON_LIB_PATH="/usr/lib/python3.13/site-packages"
build --python_path="/usr/bin/python3.13"
build --config=rocm
build --action_env ROCM_PATH="/opt/rocm/"
build --action_env CLANG_COMPILER_PATH="/usr/lib/llvm18/bin/clang-18"
build --repo_env=CC=/usr/lib/llvm18/bin/clang-18
build --repo_env=BAZEL_COMPILER=/usr/lib/llvm18/bin/clang-18
build:opt --copt=-march=native
build:opt --host_copt=-march=native
test --test_size_filters=small,medium
test --test_env=LD_LIBRARY_PATH
test:v1 --test_tag_filters=-benchmark-test,-no_oss,-oss_excluded,-no_gpu,-oss_serial
test:v1 --build_tag_filters=-benchmark-test,-no_oss,-oss_excluded,-no_gpu
test:v2 --test_tag_filters=-benchmark-test,-no_oss,-oss_excluded,-no_gpu,-oss_serial,-v1only
test:v2 --build_tag_filters=-benchmark-test,-no_oss,-oss_excluded,-no_gpu,-v1only
解决方案
通过以下参数成功构建了它:
bazel --repo_env=USE_PYWRAP_RULES=1 \
--repo_env=WHEEL_NAME=tensorflow_cpu \
--copt=-w \
--copt=-O3 \
--copt=-march=znver4 \
--copt=-mtune=znver4 \
--copt=-flto=thin \
--copt=-fomit-frame-pointer \
--copt=-fstrict-aliasing \
--copt=-DEIGEN_MAX_ALIGN_BYTES=64 \
--copt=-DEIGEN_VECTORIZE_AVX2 \
--copt=-fno-math-errno \
--copt=-fno-trapping-math \
--copt=-fassociative-math \
--copt=-fprofile-generate \
--cxxopt=-std=c++17 \
--cxxopt=-include \
--cxxopt=cstdint \
--linkopt=-flto=thin \
--linkopt=-Wl,-O3 \
--linkopt=-Wl,--as-needed \
--linkopt=-fprofile-generate \
--strip=always \
--experimental_strict_action_env \
--jobs=16 \
--local_resources=memory=32768
真正解决问题的是
--cxxopt=-std=c++17 \
随后出现的错误通过以下方法修复
--cxxopt=-include \
--cxxopt=cstdint \
并且在不使用nccl、非mk1的构建、没有CUDA,也没有ROCM的情况下也能工作。
我没有试过CUDA(因为没有合适的硬件),但ROCM和 mk1再次导致构建失败。
mk1可以稍后通过环境变量启用(据ChatGPT所述)。
对我来说没有ROCM并不算大问题(硬件限制),但如果你确实需要它,那就同情你点吧。
如果你找到了在ROCM下构建它的方法,请在这里作为答案发布。
同时TF 2.21.0已经发布,并且使用我在此指定的选项无法构建。
请注意
-copt=-march=znver4 \
--copt=-mtune=znver4 \
是针对amd-zen特定架构的,对于通用情况
-copt=-march=native \
--copt=-mtune=native \
就足够了。
另外请注意
--copt=-fprofile-generate
and
--linkopt=-fprofile-generate
会收集性能统计信息,因此你要么完全移除该标志,要么改用
--copt=-fprofile-use \
and
--linkopt=-fprofile-use \ 来替代。