-
-
Save dcunited001/eba5027134089619e703 to your computer and use it in GitHub Desktop.
Aparapi Example Class for GPU Integration.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package aparapi_matrix; | |
import java.util.Random; | |
import com.amd.aparapi.Kernel; | |
public class MatMul extends Kernel | |
{ | |
private float matA[]; | |
private float matB[]; | |
private float matC[]; | |
private int rowA, colArowB, colB; | |
@Override | |
public void run() | |
{ | |
int i = getGlobalId() / colB; | |
int j = getGlobalId() % colB; | |
float v = 0; | |
for(int k = 0; k<colArowB; k++) { | |
v += matA[i * colArowB + k] * matB[k * colB + j]; | |
} | |
matC[i * colB + j] = v; | |
} | |
public MatMul(float matA[], float matB[], int rowA, int colArowB, int colB) | |
{ | |
this.rowA = rowA; | |
this.colArowB = colArowB; | |
this.colB = colB; | |
this.matA = matA; | |
this.matB = matB; | |
matC = new float [rowA * colB ]; | |
for(int i=0; i<rowA; i++) { | |
for(int j=0; j<colB; j++) { | |
matC[i * colB + j] = 0; | |
} | |
} | |
} | |
public float[] result() | |
{ | |
return this.matC; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Wondering if there's a good way to come up with Clojure DSL for generating these classes.