NVIDIA / CUDALibrarySamples

CUDA Library Samples
Other
1.5k stars 311 forks source link

Getting issue when trying cusparse with custom atomic operation for sparse multiplication #184

Closed Pavanmahaveer7 closed 2 months ago

Pavanmahaveer7 commented 3 months ago

Hi, team. I am trying to do sparse vector multilpication for my customer data points and i trying to use cuda to make use of gpu potential,

global void atomic_spmv_kernel(const int row_ptr, const int col_ind, const float values, const float user_features, float predicted_ratings, int num_users, int num_movies, int num_features) { int user = blockIdx.x blockDim.x + threadIdx.x; if (user < num_users) { int start = row_ptr[user]; int end = row_ptr[user + 1];

    for (int i = start; i < end; i++) {
        int movie = col_ind[i];
        float rating = values[i];
        float dot_product = 0.0f;

        for (int j = 0; j < num_features; j++) {
            dot_product += rating * user_features[user * num_features + j];
        }

        atomicAdd(&predicted_ratings[user * num_movies + movie], dot_product);
    }
}

}

this is the kernal. and i am getting the undefined values after the multiplication like these User 1: 348.0 348.0 348.0 348.0 348.0 348.0 User 2: 231.0 231.0 231.0 231.0 231.0 231.0 User 3: -353696225980204911446080825342296064.0. what could be the issue here, cant we use cusparese with atomic operations along with.

fbusato commented 3 months ago

Hi @Pavanmahaveer7, we don't cover user kernels in the repository. My suggestion is to use cusparseSpMV https://docs.nvidia.com/cuda/cusparse/index.html#cusparsespmv for calling sparse matrix - vector multiplication. Otherwise, you can post your issue in the devforum https://forums.developer.nvidia.com/