Truncated reallocation error with constant

Hello,

I am currently working on a .cu project that includes two .cuh files: one containing structs, definitions, and constants, and the other containing functions. Recently, I started encountering an error related to the name of a constant in the project. Unfortunately, I am unsure about the cause of the error.

I would greatly appreciate it if anyone could provide insight into what might be causing this issue.

Thank you in advance for your help.
Rafael

I defined the constant in a .cuh file:

__constant__ double d_raio = 180;

The other .cuh file holds:

__device__  int rayIntersectsSphere(
double x0, double y0, double z0, // Ray origin
double x1, double y1, double z1, // Ray direction endpoint
Point &intersectionPoint      // Output: Intersection point x-coordinate    
 ) {
//    double raio2; raio2 = d_raio;                        // Sphere radius
double cx; double cy; double cz; // Sphere center
cx = dg_bounds[0];cy = dg_bounds[1];cz = dg_bounds[2];
// Calculate ray direction
double dx = x1 - x0;    double dy = y1 - y0;    double dz = z1 - z0;

// Quadratic coefficients
double a = dx * dx + dy * dy + dz * dz;
double b = 2 * (dx * (x0 - cx) + dy * (y0 - cy) + dz * (z0 - cz));
double c = (cx * cx + cy * cy + cz * cz) + (x0 * x0 + y0 * y0 + z0 * z0) -
           2 * (cx * x0 + cy * y0 + cz * z0) -  d_raio * d_raio;

// Compute discriminant
double discriminant = b * b - 4 * a * c;

// No intersection
if (discriminant < 0.0) {return 0;}

// Calculate the nearest intersection (smallest t)
double t = (-b - sqrt(discriminant)) / (2 * a);

// The intersection is behind the ray origin
if (t < 0.0) {return 0;}

// Compute the intersection point
intersectionPoint.x = x0 + t * dx;    intersectionPoint.y = y0 + t * dy;
intersectionPoint.z = z0 + t * dz;    return 1;}

the error is:

    CMakeFiles/prismatic.dir/prismatic.cu.o: in function "__nv_cudaEntityRegisterCallback(void**)":
    tmpxft_000e0bb6_00000000-7_prismatic.cudafe1.cpp:(.text+0x649): relocation truncated to fit: R_X86_64_PC32 against ".bss"
    tmpxft_000e0bb6_00000000-7_prismatic.cudafe1.cpp:(.text+0x676): relocation truncated to fit: R_X86_64_PC32 against ".bss"
    tmpxft_000e0bb6_00000000-7_prismatic.cudafe1.cpp:(.text+0x69e): relocation truncated to fit: R_X86_64_PC32 against ".bss"
    tmpxft_000e0bb6_00000000-7_prismatic.cudafe1.cpp:(.text+0x6c7): relocation truncated to fit: R_X86_64_PC32 against ".bss"
    tmpxft_000e0bb6_00000000-7_prismatic.cudafe1.cpp:(.text+0x6f1): relocation truncated to fit: R_X86_64_PC32 against ".bss"
    tmpxft_000e0bb6_00000000-7_prismatic.cudafe1.cpp:(.text+0x71a): relocation truncated to fit: R_X86_64_PC32 against ".bss"
    tmpxft_000e0bb6_00000000-7_prismatic.cudafe1.cpp:(.text+0x742): relocation truncated to fit: R_X86_64_PC32 against ".bss"
    tmpxft_000e0bb6_00000000-7_prismatic.cudafe1.cpp:(.text+0x76a): relocation truncated to fit: R_X86_64_PC32 against ".bss"
    tmpxft_000e0bb6_00000000-7_prismatic.cudafe1.cpp:(.text+0x793): relocation truncated to fit: R_X86_64_PC32 against ".bss"
    tmpxft_000e0bb6_00000000-7_prismatic.cudafe1.cpp:(.text+0x7bd): relocation truncated to fit: R_X86_64_PC32 against undefined symbol "d_raio" in section .bss in CMakeFiles/prismatic.dir/prismatic.cu.o
    tmpxft_000e0bb6_00000000-7_prismatic.cudafe1.cpp:(.text+0x7e6): relocation overflow adds omitted from output
    /usr/lib/gcc/x86_64-linux-gnu/12/../../../x86_64-linux-gnu/libcudadevrt.a(cuda_device_runtime.o): in function "__nv_cudaEntityRegisterCallback(void**)":
    cuda_device_runtime.compute_90.cudafe1.cpp:(.text+0x6a1): failed to convert GOTPCREL relocation against "cudartErrorTable"; relink with --no-relax
    cuda_device_runtime.compute_90.cudafe1.cpp:(.text+0x71b): failed to convert GOTPCREL relocation against "cudartErrorCnpMap"; relink with --no-relax
    cuda_device_runtime.compute_90.cudafe1.cpp:(.text+0x76b): failed to convert GOTPCREL relocation against "__CNPRT_VERSION_NUMBER__"; reconnect with --no-relax
    collect2: error: ld returned 1 exit status
    make[2]: *** [CMakeFiles/prismatic.dir/build.make:136: prismatic] Error 1
    make[1]: *** [CMakeFiles/Makefile2:83: CMakeFiles/prismatic.dir/all] Error 2
    make: *** [Makefile:91: all] Error 2

With header files it is important, which .cu or .cpp or .c translation units import them in which order, e.g. prismatic.cu.
It is, as if the headers are directly inserted into the .cu file.

For compile-time constants, better use constexpr instead of __constant__.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.