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
1 change: 1 addition & 0 deletions CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
* Toon Baeyens <toon.baeyens@gmail.com>
* Luis Mendes <luis.p.mendes@gmail.com>
* Saurabh Rawat <saurabh.rawat90@gmail.com>
* jynbil1 - https://github.com/jynbil1

# Details

Expand Down
6 changes: 5 additions & 1 deletion src/main/java/com/aparapi/internal/model/MethodModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -1484,7 +1484,7 @@ class Var implements LocalVariableInfo{
descriptor = "/* arg */";
} else {
name = _storeSpec.toString().toLowerCase() + "_" + _slotIndex;
descriptor = _storeSpec.toString();
descriptor = getTypeDescriptor(_storeSpec);
}
}

Expand Down Expand Up @@ -1531,6 +1531,10 @@ public String toString() {

List<LocalVariableInfo> list = new ArrayList<LocalVariableInfo>();

private String getTypeDescriptor(StoreSpec _storeSpec) {
return _storeSpec == StoreSpec.L ? "J" : _storeSpec.toString();
}

public FakeLocalVariableTableEntry(Map<Integer, Instruction> _pcMap, ClassModelMethod _method) {
int numberOfSlots = _method.getCodeEntry().getMaxLocals();

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/**
* Copyright (c) 2016 - 2018 Syncleus, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.aparapi.codegen.test;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

import com.aparapi.Kernel;
import com.aparapi.internal.model.CacheEnabler;
import com.aparapi.internal.model.ClassModel;
import com.aparapi.internal.model.Entrypoint;
import com.aparapi.internal.writer.KernelWriter;

import java.net.URL;
import java.net.URLClassLoader;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import javax.tools.JavaCompiler;
import javax.tools.ToolProvider;
import org.junit.Test;

public class Issue10NoDebugMonteCarloTest {

@Test
public void noDebugMonteCarloLongLocalIsDeclared() throws Exception {
Path root = Files.createTempDirectory("aparapi-issue10-");
Path sourceRoot = root.resolve("src");
Path classesRoot = root.resolve("classes");
Path source = sourceRoot.resolve("issue10").resolve("MonteCarloNoDebug.java");
Files.createDirectories(source.getParent());
Files.createDirectories(classesRoot);
Files.write(source, sourceText().getBytes(StandardCharsets.UTF_8));

JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
assertTrue("JDK compiler is required for this regression test", compiler != null);
int exit = compiler.run(null, null, null,
"-g:none",
"-classpath", System.getProperty("java.class.path"),
"-d", classesRoot.toString(),
source.toString());
assertTrue("dynamic javac failed: " + exit, exit == 0);

try (URLClassLoader loader = new URLClassLoader(new URL[] { classesRoot.toUri().toURL() },
Thread.currentThread().getContextClassLoader())) {
Class<?> kernelClass = Class.forName("issue10.MonteCarloNoDebug", true, loader);
CacheEnabler.setCachesEnabled(false);
ClassModel classModel = ClassModel.createClassModel(kernelClass);
Object kernelInstance = kernelClass.getConstructor().newInstance();
Entrypoint entrypoint = classModel.getEntrypoint("run", kernelInstance instanceof Kernel ? (Kernel) kernelInstance : null);
String opencl = KernelWriter.writeToString(entrypoint);

assertTrue(opencl, opencl.contains("long l_3 = (long)i_1;"));
assertFalse(opencl, opencl.contains("\n l_3 = (long)i_1;"));
}
}

private static String sourceText() {
return "package issue10;\n"
+ "import com.aparapi.Kernel;\n"
+ "public class MonteCarloNoDebug extends Kernel {\n"
+ " private int size;\n"
+ " private float[] result;\n"
+ " public MonteCarloNoDebug() { this.size = 4; this.result = new float[size]; }\n"
+ " @Override public void run() {\n"
+ " int idx = getGlobalId();\n"
+ " int iter = 25000;\n"
+ " long seed = idx;\n"
+ " float sum = 0.0f;\n"
+ " for (int j = 0; j < iter; ++j) {\n"
+ " seed = (seed * 0x5DEECE66DL + 0xBL) & ((1L << 48) - 1);\n"
+ " seed = (seed * 0x5DEECE66DL + 0xBL) & ((1L << 48) - 1);\n"
+ " float x = ((float)(seed & 0x0FFFFFFF)) / 268435455f;\n"
+ " seed = (seed * 0x5DEECE66DL + 0xBL) & ((1L << 48) - 1);\n"
+ " seed = (seed * 0x5DEECE66DL + 0xBL) & ((1L << 48) - 1);\n"
+ " float y = ((float)(seed & 0x0FFFFFFF)) / 268435455f;\n"
+ " float dist = (float)Math.sqrt(x * x + y * y);\n"
+ " if (dist <= 1.0f) sum += 1.0f;\n"
+ " }\n"
+ " sum *= 4;\n"
+ " result[idx] = sum / (float)iter;\n"
+ " }\n"
+ "}\n";
}
}