avx512fp16 causing invalid static_cast with cuda12.2 python 3.12
Hi @OH-AU 

Tensorflow supports `--copt=-mavx` flag as per [source](https://github.com/tensorflow/tensorflow/blob/master/.bazelrc#L421C1-L422C1) ,but not sure of the `avx512fp16` flag.

Need to hear from Engg team.Thanks you!
 Hi,

You seem to be using very old bazel version, could you please use below listed configurations and let us know the outcome.



Version | Python version | Compiler | Build tools | cuDNN | CUDA
-- | -- | -- | -- | -- | --
tensorflow-2.14.0 | 3.9-3.11 | Clang 16.0.0 | Bazel 6.1.0 | 8.7 | 11.8

 My apologies - not sure where that came from in the original report - the version of bazel used in the original report was 6.1.0 (I also had 6.3.2 available however that was too new for tensorflow to work with). Can you try with above published CUDA and cuDNN version. This issue is stale because it has been open for 7 days with no activity. It will be closed if no further activity occurs. Thank you. Unfortunately I don't have access to older versions of python, cuda or cudnn on this system. I attempted to compile with llvm/clang 17.0.1 but not being familiar with how to build in that environment I just got an error of:
clang-17: error: unknown argument: '-fno-canonical-system-headers' - which points me to:
https://github.com/llvm/llvm-project/issues/61699
and
https://github.com/bazelbuild/bazel/issues/16107
I can probably grab a clang 16 binary, and the older cuda/cudnn but that won't optimize well for the h100 hardware - and presumably I'd run into the same build issue with -fno-canonical...? python/3.12.0 is also the only python available on this test system at this time.
I did try with CC=clang CXX=clang++ and then using:
Please specify which gcc should be used by nvcc as the host compiler. [Default is /gcc/12.3/bin/gcc]
to see if I could  somehow combine clang+gcc but that resulted in the same error as the original ticket. I may try gcc/13.2. Canonical issue #62003 Are you satisfied with the resolution of your issue?
<a href="https://docs.google.com/forms/d/e/1FAIpQLSfaP12TRhd9xSxjXZjcZFNXPGk4kc1-qMdv3gc6bEP90vY1ew/viewform?entry.85265664=Yes&entry.2137816233=https://github.com/tensorflow/tensorflow/issues/62047">Yes</a>
<a href="https://docs.google.com/forms/d/e/1FAIpQLSfaP12TRhd9xSxjXZjcZFNXPGk4kc1-qMdv3gc6bEP90vY1ew/viewform?entry.85265664=No&entry.2137816233=https://github.com/tensorflow/tensorflow/issues/62047">No</a>
 I have the same static_cast build error on 2.16.1 building with CUDA 12.4, cudnn 8.9.7, TritonRT 8.6, clang 17, and python 3.10 (stock) on Ubuntu 22.04 if I use either copt "-march=native" or "-mavx".  I can successfully build without either march=native or mavx if I also have copt "-Wno-error=unused-command-line-argument" (see issue 62459).
### Issue type

Bug

### Have you reproduced the bug with TensorFlow Nightly?

Yes

### Source

source

### TensorFlow version

tf 2.15

### Custom code

No

### OS platform and distribution

Linux SuSE 15 SP4

### Mobile device

_No response_

### Python version

3.12.0

### Bazel version

3.6.0

### GCC/compiler version

gcc 12.3.0

### CUDA/cuDNN version

cuda 12.2.2 cudnn 8.9.5

### GPU model and memory

H100

### Current behavior?

I am aware this is an unsupported, non-working configuration - reporting early in case it's a real bug requiring fixing.
CPU is Sapphire Rapids; Compiling with --copt=-mavx512fp16
results in the following build error:

tensorflow/core/kernels/linalg/matrix_inverse_op.cc:113:31:   required from here
external/eigen_archive/Eigen/src/Core/MathFunctions.h:429:12: error: invalid ‘static_cast’ from type ‘const Eigen::internal::eigen_packet_wrapper<__vector(4) long long int, 1>’ to type ‘__vector(16) float’
  429 |     return static_cast<NewType>(x);
  
 Removing --copt=-mavx512fp16 allows the compile to finish. The following options resulted in a successfully build of a tensorflow whl file (although unusable until python 3.12 compatibility is available).
 --config=opt -c opt --copt=-mfpmath=sse --copt=-msse4.2 --copt=-mavx --copt=-mavx2
--copt=-mfma --copt=-mavx512f --copt=-mavx512vnni --copt=-mavx512f --copt=-mavx512bf16 --copt=-mavx512vl  


### Standalone code to reproduce the issue

```shell
TF_PYTHON_VERSION=3.11 CFLAGS="-O3 -march=native -fPIC" CXXFLAGS=$CFLAGS LIBRARY_PATH=$LD_RUN_PATH LD_LIBRARY_PATH=$LD_RUN_PATH \
LDFLAGS="-fPIC  -Wl,--disable-new-dtags -Wl,--rpath -Wl,${LD_RUN_PATH}" bazel build -j 24 --config=opt -c opt --copt=-mavx --copt=-mavx2 \
--copt=-mfma --copt=-mfpmath=sse --copt=-msse4.2 \
--copt=-mavx512f --copt=-mavx512vnni --copt=-mavx512f --copt=-mavx512fp16 --copt=-mavx512bf16 --copt=-mavx512vl \
--config=cuda --config=mkl --config=tensorrt  //tensorflow/tools/pip_package:build_pip_package --repo_env=TF_PYTHON_VERSION=3.11
```


### Relevant log output

```shell
external/eigen_archive/Eigen/src/Core/Matrix.h:227:24:   required from ‘Eigen::Matrix<Scalar_, Rows_, Cols_, Options_, MaxRows_, MaxCols_>& Eigen::Matrix<Scalar_, Rows_, Cols_, Options_, MaxRows_, MaxCols_>::operator=(const Eigen::DenseBase<OtherDerived>&) [with OtherDerived = Eigen::CwiseUnaryOp<Eigen::internal::core_cast_op<Eigen::half, float>, const Eigen::Map<const Eigen::Matrix<Eigen::half, -1, -1, 1, -1, -1>, 0, Eigen::Stride<0, 0> > >; Scalar_ = float; int Rows_ = -1; int Cols_ = -1; int Options_ = 1; int MaxRows_ = -1; int MaxCols_ = -1]’
external/eigen_archive/Eigen/src/LU/PartialPivLU.h:135:12:   required from ‘Eigen::PartialPivLU<MatrixType, PermutationIndex>& Eigen::PartialPivLU<MatrixType, PermutationIndex>::compute(const Eigen::EigenBase<OtherDerived>&) [with InputType = Eigen::CwiseUnaryOp<Eigen::internal::core_cast_op<Eigen::half, float>, const Eigen::Map<const Eigen::Matrix<Eigen::half, -1, -1, 1, -1, -1>, 0, Eigen::Stride<0, 0> > >; MatrixType_ = Eigen::Matrix<float, -1, -1, 1, -1, -1>; PermutationIndex_ = int]’
tensorflow/core/kernels/linalg/matrix_inverse_op.cc:113:31:   required from here
external/eigen_archive/Eigen/src/Core/MathFunctions.h:429:12: error: invalid ‘static_cast’ from type ‘const Eigen::internal::eigen_packet_wrapper<__vector(4) long long int, 1>’ to type ‘__vector(16) float’
  429 |     return static_cast<NewType>(x);
      |            ^~~~~~~~~~~~~~~~~~~~~~~
Target //tensorflow/tools/pip_package:build_pip_package failed to build
Use --verbose_failures to see the command lines of failed build steps.
```
