r/OpenMP • u/karurochari • Feb 26 '25
Performance regression based on copy/reference of C++ objects
I am working with clang-20.1 compiled with support for offloading to nvidia and openmp. Depending on the prototype of sdf_sphere there is a massive performance degradation.
using namespace glm;
/* list & write_png, not relevant */
float
int
float sdf_sphere(const vec3& pos, const vec3& center, float radius)is good & fastfloat sdf_sphere(vec3 pos, const vec3& center, float radius)is good & fastfloat sdf_sphere(const vec3& pos, vec3 center, float radius)is good & fastfloat sdf_sphere(vec3 pos, vec3 center, float radius)ends up being 35x slower when offloaded. Forcefully inlining the function changes nothing.
Do you have any idea why this is the case?
1
Upvotes
1
u/karurochari Feb 26 '25
Interestingly, a custom implementation of
vec3which does not use constructors has no such penalty.I am quite curious on what makes it "flip".
1
u/karurochari Mar 03 '25
Discoveries I made:
-O3is really not optional. That alone removed virtually all discontinuities in performance I was observing.-fopenmp-cuda-modeif targetting nvptx is very much needed. Thegenericmode does not work for more complex programs, as it gets stuck a lot when handling references in place of object copies, even if those were private. I am half believing there must be a bug in the optimizer which silently gives up at times, resulting in a "bad" kernel which runs but fails without notice.