CUDA segmentation error I cannot resolve

Joined
Mar 7, 2024
Messages
1
Reaction score
0
Hi! I have these struct:
C:
typedef struct Edge {
    int start;
    int end;
} Edge;

typedef struct {
    int dest;
    int deg;
    int nome;
    Edge *edges;
} Vertex;

typedef struct {
    int numberOfVertices;
    Vertex *vertices;
} Graph;
I have then a list of vertex called initial_partition and I want to create the d_initial_partition to pass on the device. the rpoblem is that I'm having problems copying the Edge* field of the elements of initial_partition to the elements of d_initial_partition. As you can see I do:
C:
    Vertex* d_initial_partition;
    cudaMalloc((void **)&d_initial_partition, numNodes * sizeof(Vertex));
    cudaMemcpy(d_initial_partition, initial_partition, numNodes * sizeof(Vertex), cudaMemcpyHostToDevice);

    for (int i = 0; i < numNodes; i++) {
        Edge* edges;

        cudaMalloc((void **)&edges, initial_partition[i].deg * sizeof(Edge));
        
        if(initial_partition[i].deg != 0){
            cudaMemcpy(edges, initial_partition[i].edges, initial_partition[i].deg * sizeof(Edge), cudaMemcpyHostToDevice);
            cudaMalloc((void**)&(d_initial_partition[i].edges), initial_partition[i].deg * sizeof(Edge));
        }
        cudaMemcpy(&d_initial_partition[i].edges, &edges, initial_partition[i].deg * sizeof(Edge), cudaMemcpyHostToDevice);
    }

In particular, the edge variable in the loop takes well the informations, but then the problem is copy these informations into d_initial_partition.
I noticed that the problematic line is the cudaMalloc on d_initial_partition, and I don't understand why I need the presence of & in the last cudaMemcpy, which is an operation equal to the other cudaMemcpy that doesn't use that symbol. I really don't understand this part and I really need to go ahead in my project
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,074
Latest member
StanleyFra

Latest Threads

Top