CUBLAS - is it possible to strengthen the matrix element?

I use the CUBLAS (Cuda Blas) libraries for matrix operations.

Can CUBLAS be used to achieve average exponentiality / root of matrix elements?

I mean, having a 2x2 matrix

1 4
9 16

What I want is a function to raise to a given value, for example. 2

1 16
81 256

and computing the root mean square, for example

1 2
3 4

Is this possible with CUBLAS? I cannot find a function suitable for this purpose, but I will ask here to start coding my own kernel first.

+5
source share
1 answer

, -, , . (, - BLAS 3- - , - . , d squareroot). , ; - .

, CUDA. , , , .

, NxM (N * M); . , N * M. ( , float , SGEMM SAXPY.)

, CUDA, , . ( squareroot) . ( , , ). , . , - B_ij = (A_ij) ^ 2; inplace, A_ij = (A_ij) ^ 2, :

__global__ void squareElements(float *a, float *b, int N) {
    /* which element does this compute? */
    int tid = blockDim.x * blockIdx.x + threadIdx.x;

    /* if valid, squre the array element */
    if (tid < N) 
            b[tid] = (a[tid]*a[tid]);
}

__global__ void sqrtElements(float *a, float *b, int N) {
    /* which element does this compute? */
    int tid = blockDim.x * blockIdx.x + threadIdx.x;

    /* if valid, sqrt the array element */
    if (tid < N) 
            b[tid] = sqrt(a[tid]);   /* or sqrtf() */
}

, , sqrtf(), 3 ulp ( ), .

, , . CUBLAS , , .

+9

All Articles