entity-toolkit / entity

New generation astrophysical plasma simulation code with CPU/GPU portability
https://entity-toolkit.github.io/wiki/
Other
27 stars 2 forks source link

compile with clang 13.0.0 #38

Closed StaticObserver closed 2 months ago

StaticObserver commented 7 months ago

1.In the file entity/framework/utils/qmath.h: line 58 & line 78: Clang can't find matched template for the two instantiations and gives out errors. Removing the key word "Inline" solves the issue. While gcc is not having any problem compiling this.

2.In the file entity/framework/meshblock/meshblock.cpp: line 128: if ((field == FieldID::Charge) && AlmostEqual(charge, ZERO)) { Variable "charge" is float while "ZERO" is double when double_precision is defined. This raises an ambiguity when using AlmostEqual() because only pure float and pure double versions are defined. Clang don't like this and gives out an error while gcc only gives out an warning. I changed it to: if ((field == FieldID::Charge) && AlmostEqual(charge, static_cast(ZERO))) {

haykh commented 7 months ago

is this clang or apple-clang? regardless, i'm not sure kokkos supports clang 13, their primary tested version is 8.0.

  1. removing Inline (which is an alias to KOKKOS_INLINE_FUNCTION) is not an option, because this code has to be run on the device. are you using CUDA too? let me try to reproduce this with the clang 13.0.
  2. this is a good catch! indeed, this should be 0.0f. could you make a PR?
StaticObserver commented 7 months ago

This is in another device I'm working on. It's not a nvidia platform. They use HIP as tools to deal with graphics cards. When compiling with C/C++ code with gpu codes, they use a compiler called hipcc which is a combination of clang and hip.

haykh commented 7 months ago

so do you use KOKKOS_ENABLE_HIP? i don't have access to any HIP machines to test, but removing Inline is definitely not an option, since it won't run on a device code. it's weird that it only complains about these two Inline-s though.

StaticObserver commented 7 months ago

Yes, I did used KOKKOS_ENABLE_HIP. Chatgpt told me inline function templates shall not be explicitly instantiated. Since inline function will be instantiated at every spot it is called. I removed line 83 ~94, it worked. Interesting, looks like clang is more strict than gcc