Question

I would like to make a boolean multiplication using cuda 6, but I can't do it in a right way. B is a boolean symmetric matrix and I have to do B^n boolean multiplication.

My C++ code is:

for (m=0; m<dimension; m++) {
    for (n=0; n<dimension; n++) {
        for (k=0; k<dimension; k++) {
            temp=mat[m*dimension+k] && mat[k*dimension+n];
            B[m*dimension+n]= B[m*dimension+n] || temp;
        }
    }
}

I've found a piece of code, but I can't adapt it for my case.

__global__ void gpuMM(float *A, float *B, float *C, int N)
{
    int row = blockIdx.y*blockDim.y + threadIdx.y;
    int col = blockIdx.x*blockDim.x + threadIdx.x;

    float sum = 0.f;
    for (int n = 0; n < N; ++n)
         sum += A[row*N+n]*B[n*N+col];

    C[row*N+col] = sum;
}
Was it helpful?

Solution

Using the notation for your kernel for the first part of your code you get this.

for (row=0; row<N; row++) {
    for (col=0; col<N; col++) {
        for (n=0; n<N; n++) {
            temp=mat[row*N+n] && mat[n*N+col];
            B[row*N+col] = B[row*N+col] || temp; 
        }       
    }
}

So your kernel should be something like this:

__global__ void gpu_booleanMM(char *mat, char *B, int N)
{
    int row = blockIdx.y*blockDim.y + threadIdx.y;
    int col = blockIdx.x*blockDim.x + threadIdx.x;

    for (int n=0; n<N; n++) {
        temp=mat[row*N+n] && mat[n*N+col];
        B[row*N+col] = B[row*N+col] || temp; 
    }   
}

I doubt this is very efficient but something like this should nevertheless give the correct result.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top