Skip to content

[NVPTX] shared memory issue between threads #116079

@AlexTru96

Description

@AlexTru96

While using nvptx64-nvidia-cuda as target and taking advantage of the recent libc for gpu feature I found the following issue

#include <stdlib.h>
void print_array(float *a, const int N, char *d);

int main (int argc, char **argv, char **envp) {

float shared[3];
int tid=__nvvm_read_ptx_sreg_tid_x();

if(tid == 0) {shared[0]=1.0;shared[1]=2.0;shared[2]=3.0;}
if(tid<3){
    printf('%f check vector [%d] \n', shared[tid]);
    print_array(shared, 3, 'shared-vector');
 __syncthreads();
    return 0;
}
};

void print_array(float *b, const int N, char *d) {
    int i;
    for(i=0; i<N; i++)
            printf("\n%s[%d,%d]: %f\n",d, i,__nvvm_read_ptx_sreg_tid_x(), b[i]);
}

after compiling with
clang++ main.cpp --target=nvptx64-nvidia-cuda -O3 -march=native -lc -lm /path-to/llvm-20.0_devel/lib/nvptx64-nvidia-cuda/crt1.o -gpulibc -o test.x

when i ran it with
nvptx-loader --threads 3 test.x

each thread tries to access a different index of the shared vector, the thread 0 is the only one that gets the right value, the rest just returns 0, but if we set only fixed indexes all threads return the correct values.
Apart from this problem, If I do a malloc each thread will allocate a private memory region, is there a way to get a dynamic shared memory allocation between threads?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions