openGPMP
Open Source Mathematics Package
Functions
_gpu_mtx_kernel.c File Reference

Go to the source code of this file.

Functions

__kernel void gpu_mtx_add (__global const int *A, __global const int *B, __global int *C)
 
__kernel void matrixMul (__global float *C, __global float *A, __global float *B, int wA, int wB)
 

Function Documentation

◆ gpu_mtx_add()

__kernel void gpu_mtx_add ( __global const int *  A,
__global const int *  B,
__global int *  C 
)

This file implements OpenCL matrix operation related kernel functions add vectors using GPU

Definition at line 9 of file _gpu_mtx_kernel.c.

9  {
10  int i = get_global_id(0);
11  int j = get_global_id(1);
12  int index = i * get_global_size(1) + j;
13  C[index] = A[index] + B[index];
14 }
list C
Definition: linalg.py:24
list A
Definition: linalg.py:22
list B
Definition: linalg.py:23

References python.linalg::A, python.linalg::B, and python.linalg::C.

◆ matrixMul()

__kernel void matrixMul ( __global float *  C,
__global float *  A,
__global float *  B,
int  wA,
int  wB 
)

Definition at line 16 of file _gpu_mtx_kernel.c.

20  {
21 
22  int tx = get_global_id(0);
23  int ty = get_global_id(1);
24 
25  // value stores the element that is
26  // computed by the thread
27  float value = 0;
28  for (int k = 0; k < wA; ++k) {
29  float elementA = A[ty * wA + k];
30  float elementB = B[k * wB + tx];
31  value += elementA * elementB;
32  }
33 
34  // Write the matrix to device memory each
35  // thread writes one element
36  C[ty * wA + tx] = value;
37 }

References python.linalg::A, python.linalg::B, and python.linalg::C.