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


Java Kernel类代码示例

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


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

示例1: reportProfilingSummary

import com.aparapi.Kernel; //导入依赖的package包/类
public void reportProfilingSummary(StringBuilder builder) {
   builder.append("\nProfiles by Kernel Subclass (mean elapsed times in milliseconds)\n\n");
   builder.append(KernelDeviceProfile.getTableHeader()).append("\n");
   for (Class<? extends Kernel> kernelClass : profiles.keySet()) {
      String simpleName = Reflection.getSimpleName(kernelClass);
      String kernelName = "----------------- [[ " + simpleName + " ]] ";
      builder.append(kernelName);
      int dashes = 132 - kernelName.length();
      for (int i = 0; i < dashes; ++i) {
         builder.append('-');
      }
      builder.append("\n");
      KernelProfile kernelProfile = profiles.get(kernelClass);
      for (KernelDeviceProfile deviceProfile : kernelProfile.getDeviceProfiles()) {
         builder.append(deviceProfile.getAverageAsTableRow()).append("\n");
      }
   }
}
 
开发者ID:Syncleus,项目名称:aparapi,代码行数:19,代码来源:KernelManager.java

示例2: getSharedKernelInstance

import com.aparapi.Kernel; //导入依赖的package包/类
private <T extends Kernel> T getSharedKernelInstance(Class<T> kernelClass) {
   synchronized (sharedInstances) {
      T shared = (T) sharedInstances.get(kernelClass);
      if (shared == null) {
         try {
            Constructor<T> constructor = kernelClass.getConstructor();
            constructor.setAccessible(true);
            shared = constructor.newInstance();
            sharedInstances.put(kernelClass, shared);
         }
         catch (Exception e) {
            throw new RuntimeException(e);
         }
      }
      return shared;
   }
}
 
开发者ID:Syncleus,项目名称:aparapi,代码行数:18,代码来源:KernelManager.java

示例3: 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

示例4: 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

示例5: 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

示例6: 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

示例7: 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

示例8: 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

示例9: 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

示例10: Drun1D

import com.aparapi.Kernel; //导入依赖的package包/类
public static void Drun1D() {
   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 * N) + j] = i + j;
         B[(i * N) + j] = i - j;
         cpu[(i * N) + j] = 0.0;
         gpu[(i * N) + j] = 0.0;
      }
   }

   long gs = System.currentTimeMillis();
   final Kernel kernel = new DMatMul1D(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: 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

示例12: 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

示例13: 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

示例14: 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

示例15: Lrun2D

import com.aparapi.Kernel; //导入依赖的package包/类
public static void Lrun2D() {
   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][j] = i + j;
         B[i][j] = i - j;
         cpu[i][j] = 0l;
         gpu[i][j] = 0l;
      }
   }

   long gs = System.currentTimeMillis();
   final Kernel kernel = new LMatMul2D(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


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