Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 24 additions & 24 deletions src/main/java/com/aparapi/internal/writer/BlockWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -411,32 +411,32 @@ public void writeInstruction(Instruction _instruction) throws CodeGenException {

final LocalVariableInfo localVariableInfo = assignToLocalVariable.getLocalVariableInfo();

if ((_instruction.getFirstChild() instanceof I_NEWARRAY)) {
if (localVariableInfo == null) {
throw new CodeGenException("outOfScope" + _instruction.getThisPC() + " = ");
} else {
final String descriptor = localVariableInfo.getVariableDescriptor();
write(convertType(descriptor, true, true));
write(localVariableInfo.getVariableName());
}
if (localVariableInfo == null) {
// A javac local variable table can omit unused locals. Preserve any
// RHS side effects without inventing a name or scope for the local.
for (Instruction operand = _instruction.getFirstChild(); operand != null; operand = operand.getNextExpr()) {
writeInstruction(operand);
}
} else {
if (assignToLocalVariable.isDeclaration()) {
final String descriptor = localVariableInfo.getVariableDescriptor();
// Arrays always map to __global arrays
if (descriptor.startsWith("[")) {
if ((_instruction.getFirstChild() instanceof I_NEWARRAY)) {
final String descriptor = localVariableInfo.getVariableDescriptor();
write(convertType(descriptor, true, true));
write(localVariableInfo.getVariableName());
} else {
if (assignToLocalVariable.isDeclaration()) {
final String descriptor = localVariableInfo.getVariableDescriptor();
// Arrays always map to __global arrays
if (descriptor.startsWith("[")) {
write(" __global ");
}
write(convertType(descriptor, true, false));
}
if (localVariableInfo == null) {
throw new CodeGenException("outOfScope" + _instruction.getThisPC() + " = ");
} else {
write(localVariableInfo.getVariableName() + " = ");
}
}

for (Instruction operand = _instruction.getFirstChild(); operand != null; operand = operand.getNextExpr()) {
writeInstruction(operand);
}
write(convertType(descriptor, true, false));
}
write(localVariableInfo.getVariableName() + " = ");
}

for (Instruction operand = _instruction.getFirstChild(); operand != null; operand = operand.getNextExpr()) {
writeInstruction(operand);
}
}

} else if (_instruction instanceof AssignToArrayElement) {
Expand Down
106 changes: 50 additions & 56 deletions src/test/java/com/aparapi/codegen/test/ArbitraryScopeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,75 +15,69 @@
*/
package com.aparapi.codegen.test;

import org.junit.Ignore;
import org.junit.Test;

public class ArbitraryScopeTest extends com.aparapi.codegen.CodeGenJUnitBase {

private static final String[] expectedOpenCL = {
"typedef struct This_s{\n"
+ " int width;\n"
+ " float scale;\n"
+ " int maxIterations;\n"
+ "\n"
+ " int passid;\n"
+ " }This;\n"
+ " int get_pass_id(This *this){\n"
+ " return this->passid;\n"
+ " }\n"
+ "\n"
+ " __kernel void run(\n"
+ " int width,\n"
+ " float scale,\n"
+ " int maxIterations,\n"
+ " int passid\n"
+ " ){\n"
+ " This thisStruct;\n"
+ " This* this=&thisStruct;\n"
+ " this->width = width;\n"
+ " this->scale = scale;\n"
+ " this->maxIterations = maxIterations;\n"
+ " this->passid = passid;\n"
+ " {\n"
+ " int tid = 0;\n"
+ " int i = tid % this->width;\n"
+ " int j = tid / this->width;\n"
+ " float x0 = (((float)i * this->scale) - ((this->scale / 2.0f) * (float)this->width)) / (float)this->width;\n"
+ " float y0 = (((float)j * this->scale) - ((this->scale / 2.0f) * (float)this->width)) / (float)this->width;\n"
+ " float x = x0;\n"
+ " float y = y0;\n"
+ " float x2 = x * x;\n"
+ " float y2 = y * y;\n"
+ " {\n"
+ " float scaleSquare = this->scale * this->scale;\n"
+ " int count = 0;\n"
+ " for (int iter = 0; iter<this->maxIterations; iter++){\n"
+ " if ((x2 + y2)<=scaleSquare){\n"
+ " y = ((2.0f * x) * y) + y0;\n"
+ " x = (x2 - y2) + x0;\n"
+ " x2 = x * x;\n"
+ " y2 = y * y;\n"
+ " count++;\n"
+ " } else {\n"
+ " count--;\n"
+ " }\n"
+ " }\n"
+ " int value = (256 * count) / this->maxIterations;\n"
+ " }\n"
+ " float scaleSquare = 1.0f;\n"
+ " return;\n"
+ " }\n"
+ " }\n"
+ " "};
+ " int width;\n"
+ " float scale;\n"
+ " int maxIterations;\n"
+ " int passid;\n"
+ "}This;\n"
+ "int get_pass_id(This *this){\n"
+ " return this->passid;\n"
+ "}\n"
+ "__kernel void run(\n"
+ " int width, \n"
+ " float scale, \n"
+ " int maxIterations, \n"
+ " int passid\n"
+ "){\n"
+ " This thisStruct;\n"
+ " This* this=&thisStruct;\n"
+ " this->width = width;\n"
+ " this->scale = scale;\n"
+ " this->maxIterations = maxIterations;\n"
+ " this->passid = passid;\n"
+ " {\n"
+ " int tid = 0;\n"
+ " int i = tid % this->width;\n"
+ " int j = tid / this->width;\n"
+ " float x0 = (((float)i * this->scale) - ((this->scale / 2.0f) * (float)this->width)) / (float)this->width;\n"
+ " float y0 = (((float)j * this->scale) - ((this->scale / 2.0f) * (float)this->width)) / (float)this->width;\n"
+ " float x = x0;\n"
+ " float y = y0;\n"
+ " float x2 = x * x;\n"
+ " float y2 = y * y;\n"
+ " {\n"
+ " float scaleSquare = this->scale * this->scale;\n"
+ " int count = 0;\n"
+ " for (int iter = 0; iter<this->maxIterations; iter++){\n"
+ " if ((x2 + y2)<=scaleSquare){\n"
+ " y = ((2.0f * x) * y) + y0;\n"
+ " x = (x2 - y2) + x0;\n"
+ " x2 = x * x;\n"
+ " y2 = y * y;\n"
+ " count++;\n"
+ " } else {\n"
+ " count--;\n"
+ " }\n"
+ " }\n"
+ " (256 * count) / this->maxIterations;\n"
+ " }\n"
+ " float scaleSquare = 1.0f;\n"
+ " return;\n"
+ " }\n"
+ "}\n"};
private static final Class<? extends com.aparapi.internal.exception.AparapiException> expectedException = null;

@Ignore
@Test
public void ArbitraryScopeTest() {
test(com.aparapi.codegen.test.ArbitraryScope.class, expectedException, expectedOpenCL);
}

@Ignore
@Test
public void ArbitraryScopeTestWorksWithCaching() {
test(com.aparapi.codegen.test.ArbitraryScope.class, expectedException, expectedOpenCL);
Expand Down
6 changes: 0 additions & 6 deletions src/test/java/com/aparapi/runtime/ArbitraryScopeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,10 @@
package com.aparapi.runtime;

import com.aparapi.Kernel;
import com.aparapi.Range;
import org.junit.Ignore;
import org.junit.Test;

import static org.junit.Assert.assertEquals;

public class ArbitraryScopeTest
{
@Ignore("Known bug, ignoring test")
@Test
public void UnusedInArbitraryScopeTest()
{
Expand All @@ -40,7 +35,6 @@ public void run() {
kernel.execute(1);
}

@Ignore("Known bug, ignoring test")
@Test
public void UnusedInNormalScopeTest()
{
Expand Down