当前位置: 首页>>代码示例>>Java>>正文


Java Kernel.execute方法代码示例

本文整理汇总了Java中com.aparapi.Kernel.execute方法的典型用法代码示例。如果您正苦于以下问题:Java Kernel.execute方法的具体用法?Java Kernel.execute怎么用?Java Kernel.execute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.aparapi.Kernel的用法示例。


在下文中一共展示了Kernel.execute方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: test

import com.aparapi.Kernel; //导入方法依赖的package包/类
@Test
public void test() {
    final int globalArray[] = new int[512];
    Kernel kernel = new Kernel() {
        @Override
        public void run() {
            globalArray[getGlobalId()] = getGlobalId();
        }
    };
    for (int loop = 0; loop < 100; loop++) {

        System.out.printf("%3d free = %10d\n", loop, Runtime.getRuntime().freeMemory());
        kernel.execute(Range.create(512, 64), 1);
        for (int i = 0; i < globalArray.length; ++i) {
            Assert.assertEquals("Wrong", i, globalArray[i]);
        }
    }
    for (int loop = 0; loop < 100; loop++) {

        System.out.printf("%3d free = %10d\n", loop, Runtime.getRuntime().freeMemory());
        kernel.execute(Range.create(512, 64), 2);
        for (int i = 0; i < globalArray.length; ++i) {
            Assert.assertEquals("Wrong", i, globalArray[i]);
        }
    }
}
 
开发者ID:Syncleus,项目名称:aparapi,代码行数:27,代码来源:Issue69Test.java

示例2: Zrun1D

import com.aparapi.Kernel; //导入方法依赖的package包/类
public static void Zrun1D() {
   final boolean[] A = new boolean[N * N];
   final boolean[] B = new boolean[N * N];
   final boolean[] gpu = new boolean[N * N];
   boolean[] cpu = new boolean[N * N];

   for (int i = 0; i < N; i++) {
      for (int j = 0; j < N; j++) {
         A[(i * N) + j] = ((i % 2) == 0) ^ ((j % 2) == 0);
         B[(i * N) + j] = ((i % 2) == 0) & ((j % 2) == 0);
         cpu[(i * N) + j] = false;
         gpu[(i * N) + j] = false;
      }
   }

   long gs = System.currentTimeMillis();
   final Kernel kernel = new ZMatMul1D(A, B, gpu, N);
   kernel.execute(N * N);
   gs = System.currentTimeMillis() - gs;

   long cs = System.currentTimeMillis();
   cpu = matMull(A, B, N);
   cs = System.currentTimeMillis() - cs;

   System.out.println("gpu time: " + gs + "\ncpu time: " + cs);
   System.out.print("valid? ");

   if (checkResults(cpu, gpu)) {
      System.out.println("yes");
   } else {
      System.out.println("no");
   }
}
 
开发者ID:Syncleus,项目名称:aparapi-examples,代码行数:34,代码来源:MDArray.java

示例3: Brun1D

import com.aparapi.Kernel; //导入方法依赖的package包/类
public static void Brun1D() {
   final byte[] A = new byte[N * N];
   final byte[] B = new byte[N * N];
   final byte[] gpu = new byte[N * N];
   byte[] cpu = new byte[N * N];

   for (int i = 0; i < N; i++) {
      for (int j = 0; j < N; j++) {
         A[(i * N) + j] = (byte) (i + j);
         B[(i * N) + j] = (byte) (i - j);
         cpu[(i * N) + j] = (byte) 0;
         gpu[(i * N) + j] = (byte) 0;
      }
   }

   long gs = System.currentTimeMillis();
   final Kernel kernel = new BMatMul1D(A, B, gpu, N);
   kernel.execute(N * N);
   gs = System.currentTimeMillis() - gs;

   long cs = System.currentTimeMillis();
   cpu = matMull(A, B, N);
   cs = System.currentTimeMillis() - cs;

   System.out.println("gpu time: " + gs + "\ncpu time: " + cs);
   System.out.print("valid? ");

   if (checkResults(cpu, gpu)) {
      System.out.println("yes");
   } else {
      System.out.println("no");
   }
}
 
开发者ID:Syncleus,项目名称:aparapi-examples,代码行数:34,代码来源:MDArray.java

示例4: Srun1D

import com.aparapi.Kernel; //导入方法依赖的package包/类
public static void Srun1D() {
   final short[] A = new short[N * N];
   final short[] B = new short[N * N];
   final short[] gpu = new short[N * N];
   short[] cpu = new short[N * N];

   for (int i = 0; i < N; i++) {
      for (int j = 0; j < N; j++) {
         A[(i * N) + j] = (short) (i + j);
         B[(i * N) + j] = (short) (i - j);
         cpu[(i * N) + j] = (short) 0;
         gpu[(i * N) + j] = (short) 0;
      }
   }

   long gs = System.currentTimeMillis();
   final Kernel kernel = new SMatMul1D(A, B, gpu, N);
   kernel.execute(N * N);
   gs = System.currentTimeMillis() - gs;

   long cs = System.currentTimeMillis();
   cpu = matMull(A, B, N);
   cs = System.currentTimeMillis() - cs;

   System.out.println("gpu time: " + gs + "\ncpu time: " + cs);
   System.out.print("valid? ");

   if (checkResults(cpu, gpu)) {
      System.out.println("yes");
   } else {
      System.out.println("no");
   }
}
 
开发者ID:Syncleus,项目名称:aparapi-examples,代码行数:34,代码来源:MDArray.java

示例5: Irun1D

import com.aparapi.Kernel; //导入方法依赖的package包/类
public static void Irun1D() {
   final int[] A = new int[N * N];
   final int[] B = new int[N * N];
   final int[] gpu = new int[N * N];
   int[] cpu = new int[N * N];

   for (int i = 0; i < N; i++) {
      for (int j = 0; j < N; j++) {
         A[(i * N) + j] = i + j;
         B[(i * N) + j] = i - j;
         cpu[(i * N) + j] = 0;
         gpu[(i * N) + j] = 0;
      }
   }

   long gs = System.currentTimeMillis();
   final Kernel kernel = new IMatMul1D(A, B, gpu, N);
   kernel.execute(N * N);
   gs = System.currentTimeMillis() - gs;

   long cs = System.currentTimeMillis();
   cpu = matMull(A, B, N);
   cs = System.currentTimeMillis() - cs;

   System.out.println("gpu time: " + gs + "\ncpu time: " + cs);
   System.out.print("valid? ");

   if (checkResults(cpu, gpu)) {
      System.out.println("yes");
   } else {
      System.out.println("no");
   }
}
 
开发者ID:Syncleus,项目名称:aparapi-examples,代码行数:34,代码来源:MDArray.java

示例6: Lrun1D

import com.aparapi.Kernel; //导入方法依赖的package包/类
public static void Lrun1D() {
   final long[] A = new long[N * N];
   final long[] B = new long[N * N];
   final long[] gpu = new long[N * N];
   long[] cpu = new long[N * N];

   for (int i = 0; i < N; i++) {
      for (int j = 0; j < N; j++) {
         A[(i * N) + j] = i + j;
         B[(i * N) + j] = i - j;
         cpu[(i * N) + j] = 0l;
         gpu[(i * N) + j] = 0l;
      }
   }

   long gs = System.currentTimeMillis();
   final Kernel kernel = new LMatMul1D(A, B, gpu, N);
   kernel.execute(N * N);
   gs = System.currentTimeMillis() - gs;

   long cs = System.currentTimeMillis();
   cpu = matMull(A, B, N);
   cs = System.currentTimeMillis() - cs;

   System.out.println("gpu time: " + gs + "\ncpu time: " + cs);
   System.out.print("valid? ");

   if (checkResults(cpu, gpu)) {
      System.out.println("yes");
   } else {
      System.out.println("no");
   }
}
 
开发者ID:Syncleus,项目名称:aparapi-examples,代码行数:34,代码来源:MDArray.java

示例7: Frun1D

import com.aparapi.Kernel; //导入方法依赖的package包/类
public static void Frun1D() {
   final float[] A = new float[N * N];
   final float[] B = new float[N * N];
   final float[] gpu = new float[N * N];
   float[] cpu = new float[N * N];

   for (int i = 0; i < N; i++) {
      for (int j = 0; j < N; j++) {
         A[(i * N) + j] = i + j;
         B[(i * N) + j] = i - j;
         cpu[(i * N) + j] = 0.0f;
         gpu[(i * N) + j] = 0.0f;
      }
   }

   long gs = System.currentTimeMillis();
   final Kernel kernel = new FMatMul1D(A, B, gpu, N);
   kernel.execute(N * N);
   gs = System.currentTimeMillis() - gs;

   long cs = System.currentTimeMillis();
   cpu = matMull(A, B, N);
   cs = System.currentTimeMillis() - cs;

   System.out.println("gpu time: " + gs + "\ncpu time: " + cs);
   System.out.print("valid? ");

   if (checkResults(cpu, gpu)) {
      System.out.println("yes");
   } else {
      System.out.println("no");
   }
}
 
开发者ID:Syncleus,项目名称:aparapi-examples,代码行数:34,代码来源:MDArray.java

示例8: Zrun2D

import com.aparapi.Kernel; //导入方法依赖的package包/类
public static void Zrun2D() {
   final boolean[][] A = new boolean[N][N];
   final boolean[][] B = new boolean[N][N];
   final boolean[][] gpu = new boolean[N][N];
   boolean[][] cpu = new boolean[N][N];

   for (int i = 0; i < N; i++) {
      for (int j = 0; j < N; j++) {
         A[i][j] = ((i % 2) == 0) ^ ((j % 2) == 0);
         B[i][j] = ((i % 2) == 0) & ((j % 2) == 0);
         cpu[i][j] = false;
         gpu[i][j] = false;
      }
   }

   long gs = System.currentTimeMillis();
   final Kernel kernel = new ZMatMul2D(A, B, gpu, N);
   kernel.execute(N * N);
   gs = System.currentTimeMillis() - gs;

   long cs = System.currentTimeMillis();
   cpu = matMull(A, B, N);
   cs = System.currentTimeMillis() - cs;

   System.out.println("gpu time: " + gs + "\ncpu time: " + cs);
   System.out.print("valid? ");

   if (checkResults(cpu, gpu)) {
      System.out.println("yes");
   } else {
      System.out.println("no");
   }
}
 
开发者ID:Syncleus,项目名称:aparapi-examples,代码行数:34,代码来源:MDArray.java

示例9: Brun2D

import com.aparapi.Kernel; //导入方法依赖的package包/类
public static void Brun2D() {
   final byte[][] A = new byte[N][N];
   final byte[][] B = new byte[N][N];
   final byte[][] gpu = new byte[N][N];
   byte[][] cpu = new byte[N][N];

   for (int i = 0; i < N; i++) {
      for (int j = 0; j < N; j++) {
         A[i][j] = (byte) (i + j);
         B[i][j] = (byte) (i - j);
         cpu[i][j] = (byte) 0;
         gpu[i][j] = (byte) 0;
      }
   }

   long gs = System.currentTimeMillis();
   final Kernel kernel = new BMatMul2D(A, B, gpu, N);
   kernel.execute(N * N);
   gs = System.currentTimeMillis() - gs;

   long cs = System.currentTimeMillis();
   cpu = matMull(A, B, N);
   cs = System.currentTimeMillis() - cs;

   System.out.println("gpu time: " + gs + "\ncpu time: " + cs);
   System.out.print("valid? ");

   if (checkResults(cpu, gpu)) {
      System.out.println("yes");
   } else {
      System.out.println("no");
   }
}
 
开发者ID:Syncleus,项目名称:aparapi-examples,代码行数:34,代码来源:MDArray.java

示例10: Srun2D

import com.aparapi.Kernel; //导入方法依赖的package包/类
public static void Srun2D() {
   final short[][] A = new short[N][N];
   final short[][] B = new short[N][N];
   final short[][] gpu = new short[N][N];
   short[][] cpu = new short[N][N];

   for (int i = 0; i < N; i++) {
      for (int j = 0; j < N; j++) {
         A[i][j] = (short) (i + j);
         B[i][j] = (short) (i - j);
         cpu[i][j] = (short) 0;
         gpu[i][j] = (short) 0;
      }
   }

   long gs = System.currentTimeMillis();
   final Kernel kernel = new SMatMul2D(A, B, gpu, N);
   kernel.execute(N * N);
   gs = System.currentTimeMillis() - gs;

   long cs = System.currentTimeMillis();
   cpu = matMull(A, B, N);
   cs = System.currentTimeMillis() - cs;

   System.out.println("gpu time: " + gs + "\ncpu time: " + cs);
   System.out.print("valid? ");

   if (checkResults(cpu, gpu)) {
      System.out.println("yes");
   } else {
      System.out.println("no");
   }
}
 
开发者ID:Syncleus,项目名称:aparapi-examples,代码行数:34,代码来源:MDArray.java

示例11: Irun2D

import com.aparapi.Kernel; //导入方法依赖的package包/类
public static void Irun2D() {
   final int[][] A = new int[N][N];
   final int[][] B = new int[N][N];
   final int[][] gpu = new int[N][N];
   int[][] cpu = new int[N][N];

   for (int i = 0; i < N; i++) {
      for (int j = 0; j < N; j++) {
         A[i][j] = i + j;
         B[i][j] = i - j;
         cpu[i][j] = 0;
         gpu[i][j] = 0;
      }
   }

   long gs = System.currentTimeMillis();
   final Kernel kernel = new IMatMul2D(A, B, gpu, N);
   kernel.execute(N * N);
   gs = System.currentTimeMillis() - gs;

   long cs = System.currentTimeMillis();
   cpu = matMull(A, B, N);
   cs = System.currentTimeMillis() - cs;

   System.out.println("gpu time: " + gs + "\ncpu time: " + cs);
   System.out.print("valid? ");

   if (checkResults(cpu, gpu)) {
      System.out.println("yes");
   } else {
      System.out.println("no");
   }
}
 
开发者ID:Syncleus,项目名称:aparapi-examples,代码行数:34,代码来源:MDArray.java

示例12: main

import com.aparapi.Kernel; //导入方法依赖的package包/类
public static void main(String[] _args) {

      final int size = 512;

      final float[] a = new float[size];
      final float[] b = new float[size];

      for (int i = 0; i < size; i++) {
         a[i] = (float) (Math.random() * 100);
         b[i] = (float) (Math.random() * 100);
      }

      final float[] sum = new float[size];

      Kernel kernel = new Kernel(){
         @Override public void run() {
            int gid = getGlobalId();
            sum[gid] = a[gid] + b[gid];
         }
      };

      kernel.execute(Range.create(size));

      for (int i = 0; i < size; i++) {
         System.out.printf("%6.2f + %6.2f = %8.2f\n", a[i], b[i], sum[i]);
      }

      kernel.dispose();
   }
 
开发者ID:Syncleus,项目名称:aparapi-examples,代码行数:30,代码来源:Main.java

示例13: Frun2D

import com.aparapi.Kernel; //导入方法依赖的package包/类
public static void Frun2D() {
   final float[][] A = new float[N][N];
   final float[][] B = new float[N][N];
   final float[][] gpu = new float[N][N];
   float[][] cpu = new float[N][N];

   for (int i = 0; i < N; i++) {
      for (int j = 0; j < N; j++) {
         A[i][j] = i + j;
         B[i][j] = i - j;
         cpu[i][j] = 0.0f;
         gpu[i][j] = 0.0f;
      }
   }

   long gs = System.currentTimeMillis();
   final Kernel kernel = new FMatMul2D(A, B, gpu, N);
   kernel.execute(N * N);
   gs = System.currentTimeMillis() - gs;

   long cs = System.currentTimeMillis();
   cpu = matMull(A, B, N);
   cs = System.currentTimeMillis() - cs;

   System.out.println("gpu time: " + gs + "\ncpu time: " + cs);
   System.out.print("valid? ");

   if (checkResults(cpu, gpu)) {
      System.out.println("yes");
   } else {
      System.out.println("no");
   }
}
 
开发者ID:Syncleus,项目名称:aparapi-examples,代码行数:34,代码来源:MDArray.java

示例14: Drun2D

import com.aparapi.Kernel; //导入方法依赖的package包/类
public static void Drun2D() {
   final double[][] A = new double[N][N];
   final double[][] B = new double[N][N];
   final double[][] gpu = new double[N][N];
   double[][] cpu = new double[N][N];

   for (int i = 0; i < N; i++) {
      for (int j = 0; j < N; j++) {
         A[i][j] = i + j;
         B[i][j] = i - j;
         cpu[i][j] = 0.0;
         gpu[i][j] = 0.0;
      }
   }

   long gs = System.currentTimeMillis();
   final Kernel kernel = new DMatMul2D(A, B, gpu, N);
   kernel.execute(N * N);
   gs = System.currentTimeMillis() - gs;

   long cs = System.currentTimeMillis();
   cpu = matMull(A, B, N);
   cs = System.currentTimeMillis() - cs;

   System.out.println("gpu time: " + gs + "\ncpu time: " + cs);
   System.out.print("valid? ");

   if (checkResults(cpu, gpu)) {
      System.out.println("yes");
   } else {
      System.out.println("no");
   }
}
 
开发者ID:Syncleus,项目名称:aparapi-examples,代码行数:34,代码来源:MDArray.java

示例15: Zrun3D

import com.aparapi.Kernel; //导入方法依赖的package包/类
public static void Zrun3D() {
   final boolean[][][] A = new boolean[M][M][M];
   final boolean[][][] B = new boolean[M][M][M];
   final boolean[][][] gpu = new boolean[M][M][M];
   boolean[][][] cpu = new boolean[M][M][M];

   for (int i = 0; i < M; i++) {
      for (int j = 0; j < M; j++) {
         for (int k = 0; k < M; k++) {
            A[i][j][k] = ((i % 2) == 0) ^ (((j % 2) == 0) & ((k % 2) == 0));
            B[i][j][k] = (((i % 2) == 0) & ((j % 2) == 0)) ^ ((k % 2) == 0);
            ;
            cpu[i][j][k] = false;
            gpu[i][j][k] = false;
         }
      }
   }

   long gs = System.currentTimeMillis();
   final Kernel kernel = new ZMatMul3D(A, B, gpu, M);
   kernel.execute(M * M * M);
   gs = System.currentTimeMillis() - gs;

   long cs = System.currentTimeMillis();
   cpu = matMull(A, B, M);
   cs = System.currentTimeMillis() - cs;

   System.out.println("gpu time: " + gs + "\ncpu time: " + cs);
   System.out.print("valid? ");

   if (checkResults(cpu, gpu)) {
      System.out.println("yes");
   } else {
      System.out.println("no");
   }
}
 
开发者ID:Syncleus,项目名称:aparapi-examples,代码行数:37,代码来源:MDArray.java


注:本文中的com.aparapi.Kernel.execute方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。