运行 Java 杂志文章中的 Concurnas GPU 内核
Run the Concurnas GPU Kernel in the Java Magazine article
我正在尝试 运行 introductory article 中给出的示例 GPU 内核。我将“图形处理单元”部分的代码片段合并到以下程序中:
gpukernel 1 twoArrayOp(global in A float[], global in B float[], global out result float[]) {
idx = get_global_id(0)
result[idx] = A[idx]**2 + B[idx] + 10
}
def runKernel() {
//select a GPU device...
device = gpus.GPU().getGPUDevices()[0].devices[0]
//create three arrays of size 10 on this GPU, two as input
inGPU1 = device.makeOffHeapArrayIn(float[].class, 10)
inGPU2 = device.makeOffHeapArrayIn(float[].class, 10)
//and one as output
result = device.makeOffHeapArrayOut(float[].class, 10)
//now write to the arrays on the GPU
c1 := inGPU1.writeToBuffer([ 1.f 2 3 4 5 6 7 8 9 10])
c2 := inGPU2.writeToBuffer([ 1.f 2 1 2 3 1 2 1 2 1])
inst = twoArrayOp(inGPU1, inGPU2, result)
compute := device.exe(inst, [10], c1, c2)//run 10 cores to process twoArrayOp
ret = result.readFromBuffer(compute)
return ret
}
h := runKernel()
System.out.println(h)
运行 带有 Java 14 和 Intel UHD Graphics 620 GPU 的 Windows 系统上的代码我收到以下错误:
PS C:\Users\johannes\Documents> concc gpu.conc; conc gpu
C:\Users\johannes\Documents\gpu.conc line 0:0
Bug Report: Internal compiler error on compilation of: C:\Users\johannes\Documents\gpu.conc due to java.lang.IndexOutOfBoundsException: Index 0 out of bounds for length 0: Index 0 out of bounds for length 0
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
File name: C:\Users\johannes\Documents\gpu.conc
Compiler build number: 1.14.020
Exception in phase: VectorizedRedirector
Exception at line: 27
Exception: java.lang.IndexOutOfBoundsException: Index 0 out of bounds for length 0
Exception message: Index 0 out of bounds for length 0
Exception stacktrace:
java.lang.IndexOutOfBoundsException: Index 0 out of bounds for length 0
at java.base/java.lang.Throwable.init(Throwable.java:272)
at java.base/java.lang.Exception.init(Exception.java:67)
at java.base/java.lang.RuntimeException.init(RuntimeException.java:63)
at java.base/java.lang.IndexOutOfBoundsException.init(IndexOutOfBoundsException.java:55)
at java.base/jdk.internal.util.Preconditions.outOfBounds(Preconditions.java:64)
at java.base/jdk.internal.util.Preconditions.outOfBoundsCheckIndex(Preconditions.java:70)
at java.base/jdk.internal.util.Preconditions.checkIndex(Preconditions.java:248)
at java.base/java.util.Objects.checkIndex(Objects.java:373)
at java.base/java.util.ArrayList.get(ArrayList.java:427)
at com.concurnas.compiler.visitors.VectorizedRedirector.remapVectorization(VectorizedRedirector.java:1139)
at com.concurnas.compiler.visitors.VectorizedRedirector.visit(VectorizedRedirector.java:1327)
at com.concurnas.compiler.ast.FuncInvoke.accept(FuncInvoke.java:125)
at com.concurnas.compiler.visitors.VectorizedRedirector.visit(VectorizedRedirector.java:1948)
at com.concurnas.compiler.ast.DotOperator.accept(DotOperator.java:312)
at com.concurnas.compiler.visitors.AbstractVisitor.visit(AbstractVisitor.java:556)
at com.concurnas.compiler.ast.DuffAssign.accept(DuffAssign.java:27)
at com.concurnas.compiler.visitors.AbstractErrorRaiseVisitor.visit(AbstractErrorRaiseVisitor.java:32)
at com.concurnas.compiler.ast.LineHolder.accept(LineHolder.java:26)
at com.concurnas.compiler.visitors.AbstractVisitor.visit(AbstractVisitor.java:740)
at com.concurnas.compiler.visitors.VectorizedRedirector.visit(VectorizedRedirector.java:2042)
at com.concurnas.compiler.ModuleCompiler.tryToProgressCompilation(ModuleCompiler.java:520)
at com.concurnas.compiler.MainLoop.compileFile(MainLoop.java:384)
at com.concurnas.concc.Concc.doMain(Concc.java:228)
at com.concurnas.concc.Concc.doit(Concc.java:145)
at com.concurnas.concc.Concc.main(Concc.java:89)
Source:
1: gpukernel 1 twoArrayOp(global in A float[], global in B float[], global out result float[]) {
2: idx = get_global_id(0)
3: result[idx] = A[idx]**2 + B[idx] + 10
4: }
5:
6: def runKernel() {
7: //select a GPU device...
8: device = gpus.GPU().getGPUDevices()[0].devices[0]
9:
10: //create three arrays of size 10 on this GPU, two as input
11: inGPU1 = device.makeOffHeapArrayIn(float[].class, 10)
12: inGPU2 = device.makeOffHeapArrayIn(float[].class, 10)
13: //and one as output
14: result = device.makeOffHeapArrayOut(float[].class, 10)
15:
16: //now write to the arrays on the GPU
17: c1 := inGPU1.writeToBuffer([ 1.f 2 3 4 5 6 7 8 9 10])
18: c2 := inGPU2.writeToBuffer([ 1.f 2 1 2 3 1 2 1 2 1])
19:
20: inst = twoArrayOp(inGPU1, inGPU2, result)
21: compute := device.exe(inst, [10], c1, c2)//run 10 cores to process twoArrayOp
22: ret = result.readFromBuffer(compute)
23: return ret
24: }
25:
26: h := runKernel()
-->27: System.out.println(h)
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Cannot find entry-point class to load: gpu
如何显示 运行 GPU 内核的结果?
我在 Discord 上联系了该语言的设计者,他说这是一个错误,他将在下一个版本中修复。
我正在尝试 运行 introductory article 中给出的示例 GPU 内核。我将“图形处理单元”部分的代码片段合并到以下程序中:
gpukernel 1 twoArrayOp(global in A float[], global in B float[], global out result float[]) {
idx = get_global_id(0)
result[idx] = A[idx]**2 + B[idx] + 10
}
def runKernel() {
//select a GPU device...
device = gpus.GPU().getGPUDevices()[0].devices[0]
//create three arrays of size 10 on this GPU, two as input
inGPU1 = device.makeOffHeapArrayIn(float[].class, 10)
inGPU2 = device.makeOffHeapArrayIn(float[].class, 10)
//and one as output
result = device.makeOffHeapArrayOut(float[].class, 10)
//now write to the arrays on the GPU
c1 := inGPU1.writeToBuffer([ 1.f 2 3 4 5 6 7 8 9 10])
c2 := inGPU2.writeToBuffer([ 1.f 2 1 2 3 1 2 1 2 1])
inst = twoArrayOp(inGPU1, inGPU2, result)
compute := device.exe(inst, [10], c1, c2)//run 10 cores to process twoArrayOp
ret = result.readFromBuffer(compute)
return ret
}
h := runKernel()
System.out.println(h)
运行 带有 Java 14 和 Intel UHD Graphics 620 GPU 的 Windows 系统上的代码我收到以下错误:
PS C:\Users\johannes\Documents> concc gpu.conc; conc gpu
C:\Users\johannes\Documents\gpu.conc line 0:0
Bug Report: Internal compiler error on compilation of: C:\Users\johannes\Documents\gpu.conc due to java.lang.IndexOutOfBoundsException: Index 0 out of bounds for length 0: Index 0 out of bounds for length 0
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
File name: C:\Users\johannes\Documents\gpu.conc
Compiler build number: 1.14.020
Exception in phase: VectorizedRedirector
Exception at line: 27
Exception: java.lang.IndexOutOfBoundsException: Index 0 out of bounds for length 0
Exception message: Index 0 out of bounds for length 0
Exception stacktrace:
java.lang.IndexOutOfBoundsException: Index 0 out of bounds for length 0
at java.base/java.lang.Throwable.init(Throwable.java:272)
at java.base/java.lang.Exception.init(Exception.java:67)
at java.base/java.lang.RuntimeException.init(RuntimeException.java:63)
at java.base/java.lang.IndexOutOfBoundsException.init(IndexOutOfBoundsException.java:55)
at java.base/jdk.internal.util.Preconditions.outOfBounds(Preconditions.java:64)
at java.base/jdk.internal.util.Preconditions.outOfBoundsCheckIndex(Preconditions.java:70)
at java.base/jdk.internal.util.Preconditions.checkIndex(Preconditions.java:248)
at java.base/java.util.Objects.checkIndex(Objects.java:373)
at java.base/java.util.ArrayList.get(ArrayList.java:427)
at com.concurnas.compiler.visitors.VectorizedRedirector.remapVectorization(VectorizedRedirector.java:1139)
at com.concurnas.compiler.visitors.VectorizedRedirector.visit(VectorizedRedirector.java:1327)
at com.concurnas.compiler.ast.FuncInvoke.accept(FuncInvoke.java:125)
at com.concurnas.compiler.visitors.VectorizedRedirector.visit(VectorizedRedirector.java:1948)
at com.concurnas.compiler.ast.DotOperator.accept(DotOperator.java:312)
at com.concurnas.compiler.visitors.AbstractVisitor.visit(AbstractVisitor.java:556)
at com.concurnas.compiler.ast.DuffAssign.accept(DuffAssign.java:27)
at com.concurnas.compiler.visitors.AbstractErrorRaiseVisitor.visit(AbstractErrorRaiseVisitor.java:32)
at com.concurnas.compiler.ast.LineHolder.accept(LineHolder.java:26)
at com.concurnas.compiler.visitors.AbstractVisitor.visit(AbstractVisitor.java:740)
at com.concurnas.compiler.visitors.VectorizedRedirector.visit(VectorizedRedirector.java:2042)
at com.concurnas.compiler.ModuleCompiler.tryToProgressCompilation(ModuleCompiler.java:520)
at com.concurnas.compiler.MainLoop.compileFile(MainLoop.java:384)
at com.concurnas.concc.Concc.doMain(Concc.java:228)
at com.concurnas.concc.Concc.doit(Concc.java:145)
at com.concurnas.concc.Concc.main(Concc.java:89)
Source:
1: gpukernel 1 twoArrayOp(global in A float[], global in B float[], global out result float[]) {
2: idx = get_global_id(0)
3: result[idx] = A[idx]**2 + B[idx] + 10
4: }
5:
6: def runKernel() {
7: //select a GPU device...
8: device = gpus.GPU().getGPUDevices()[0].devices[0]
9:
10: //create three arrays of size 10 on this GPU, two as input
11: inGPU1 = device.makeOffHeapArrayIn(float[].class, 10)
12: inGPU2 = device.makeOffHeapArrayIn(float[].class, 10)
13: //and one as output
14: result = device.makeOffHeapArrayOut(float[].class, 10)
15:
16: //now write to the arrays on the GPU
17: c1 := inGPU1.writeToBuffer([ 1.f 2 3 4 5 6 7 8 9 10])
18: c2 := inGPU2.writeToBuffer([ 1.f 2 1 2 3 1 2 1 2 1])
19:
20: inst = twoArrayOp(inGPU1, inGPU2, result)
21: compute := device.exe(inst, [10], c1, c2)//run 10 cores to process twoArrayOp
22: ret = result.readFromBuffer(compute)
23: return ret
24: }
25:
26: h := runKernel()
-->27: System.out.println(h)
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Cannot find entry-point class to load: gpu
如何显示 运行 GPU 内核的结果?
我在 Discord 上联系了该语言的设计者,他说这是一个错误,他将在下一个版本中修复。