Last active
August 29, 2015 14:27
-
-
Save kishida/9555f85f97fd6363fea4 to your computer and use it in GitHub Desktop.
Aparapi動作確認コード
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 kishida.aparapisample; | |
import com.amd.aparapi.Kernel; | |
import java.util.Arrays; | |
import java.util.Random; | |
/** | |
* | |
* @author kishida | |
*/ | |
public class AparapiSample extends Kernel{ | |
static float[] in = new float[50];// Mac book proのIntel Iris Proだとdouble使えない | |
static float[] filter = new float[11]; | |
static float[] out = new float[in.length]; // ローカル変数ではだめ | |
public static void main(String[] args) { | |
Random r = new Random(1234); | |
for(int i = 0; i < in.length; ++i){ | |
in[i] = r.nextFloat(); | |
} | |
for(int i = 0; i < filter.length; ++i){ | |
filter[i] = r.nextFloat(); | |
} | |
Kernel k = new AparapiSample(); // new Kernel(){}やnew AparapiSample(){}だとだめ | |
k.execute(in.length - filter.length + 1); | |
System.out.println(k.getExecutionMode()); | |
System.out.println(Arrays.toString(in)); | |
System.out.println(Arrays.toString(out)); | |
} | |
@Override | |
public void run() { | |
int id = getGlobalId(); | |
float result = 0; | |
for(int i = 0; i < 11; ++i){ // filter.lengthが使えない | |
result += filter[i] * in[id + i]; | |
} | |
out[id] = result;//result; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment