Syncleus / aparapi

The New Official Aparapi: a framework for executing native Java and Scala code on the GPU.

Home Page:http://aparapi.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Bounty $20] Unused variable at end of scope results in OutOfScope exceptions

freemo opened this issue · comments

When defining variables inside an arbitrary java scope it can result in out of scope exceptions.

Unit test demonstrating this bug located here: https://github.com/Syncleus/aparapi/blob/master/src/test/java/com/aparapi/runtime/ArbitraryScopeTest.java

The following is a related test that was the source of the above test. It only passes right now because the exception is accepted as a pass:
https://github.com/Syncleus/aparapi/blob/master/src/test/java/com/aparapi/codegen/test/ArbitraryScopeTest.java

Exception thrown is as follows:

Apr 19, 2018 9:03:40 PM com.aparapi.internal.kernel.KernelRunner fallBackToNextDevice
WARNING: Device failed for ArbitraryScopeTest$1, devices={NVIDIA<GPU>|Java Alternative Algorithm|Java Thread Pool}: outOfScope5 = 
com.aparapi.internal.exception.CodeGenException: outOfScope5 = 
	at com.aparapi.internal.writer.BlockWriter.writeInstruction(BlockWriter.java:432)
	at com.aparapi.internal.writer.KernelWriter.writeInstruction(KernelWriter.java:780)
	at com.aparapi.internal.writer.BlockWriter.writeSequence(BlockWriter.java:299)
	at com.aparapi.internal.writer.BlockWriter.writeBlock(BlockWriter.java:323)
	at com.aparapi.internal.writer.BlockWriter.writeMethodBody(BlockWriter.java:848)
	at com.aparapi.internal.writer.KernelWriter.write(KernelWriter.java:738)
	at com.aparapi.internal.writer.KernelWriter.writeToString(KernelWriter.java:792)
	at com.aparapi.internal.kernel.KernelRunner.executeInternalInner(KernelRunner.java:1475)
	at com.aparapi.internal.kernel.KernelRunner.executeInternalOuter(KernelRunner.java:1323)
	at com.aparapi.internal.kernel.KernelRunner.execute(KernelRunner.java:1313)
	at com.aparapi.Kernel.execute(Kernel.java:2665)
	at com.aparapi.Kernel.execute(Kernel.java:2622)
	at com.aparapi.Kernel.execute(Kernel.java:2597)
	at com.aparapi.runtime.ArbitraryScopeTest.UnusedInScopeTest(ArbitraryScopeTest.java:40)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
	at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
	at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
	at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
	at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
	at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
	at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
Apr 19, 2018 9:03:40 PM com.aparapi.internal.kernel.KernelRunner fallBackToNextDevice
WARNING: Trying next device: Java Alternative Algorithm

This appears to be unrelated to the arbitrary scope, the following unit test appear to fail for the same reason, it throws the same exception and has a similar structure. No arbitrary scope though. In both cases the variable is at the end of the scope and unused.

https://github.com/Syncleus/aparapi/blob/master/src/test/java/com/aparapi/codegen/test/NullCheckTest.java