public static String readTextClose(Reader in) throws IOException { try { return readText(in); } finally { in.close(); } } public static String readText(Reader in) throws IOException {
public static String readText(URL url) throws IOException { return readTextClose(url.openStream()); } public static String readTextClose(InputStream in) throws IOException {
protected Runnable copyIncludesToTemporaryDirectory() throws IOException { Map<String, URL> inclusions = resolveInclusions(); File includesDir = JavaCL.createTempDirectory("includes", "", "includes"); final List<File> filesToDelete = new ArrayList<File>(); for (Map.Entry<String, URL> e : inclusions.entrySet()) { assert log(Level.INFO, "Copying include '" + e.getKey() + "' from '" + e.getValue() + "' to '" + includesDir + "'"); File f = new File(includesDir, e.getKey().replace('/', File.separatorChar)); File p = f.getParentFile(); filesToDelete.add(f); if (p != null) { p.mkdirs(); filesToDelete.add(p); } InputStream in = e.getValue().openStream(); OutputStream out = new FileOutputStream(f); IOUtils.readWrite(in, out); in.close(); out.close(); f.deleteOnExit(); } filesToDelete.add(includesDir); addInclude(includesDir.toString()); return new Runnable() { public void run() { for (File f : filesToDelete) f.delete(); }}; } public Map<String, URL> resolveInclusions() throws IOException {
protected Runnable copyIncludesToTemporaryDirectory() throws IOException { Map<String, URL> inclusions = resolveInclusions(); File includesDir = JavaCL.createTempDirectory("includes", "", "includes"); final List<File> filesToDelete = new ArrayList<File>(); for (Map.Entry<String, URL> e : inclusions.entrySet()) { assert log(Level.INFO, "Copying include '" + e.getKey() + "' from '" + e.getValue() + "' to '" + includesDir + "'"); File f = new File(includesDir, e.getKey().replace('/', File.separatorChar)); File p = f.getParentFile(); filesToDelete.add(f); if (p != null) { p.mkdirs(); filesToDelete.add(p); } InputStream in = e.getValue().openStream(); OutputStream out = new FileOutputStream(f); IOUtils.readWrite(in, out); in.close(); out.close(); f.deleteOnExit(); } filesToDelete.add(includesDir); addInclude(includesDir.toString()); return new Runnable() { public void run() { for (File f : filesToDelete) f.delete(); }}; } public Map<String, URL> resolveInclusions() throws IOException {
public static String readText(InputStream in) throws IOException { return readText(new InputStreamReader(in)); } public static String readText(URL url) throws IOException {
public static String readTextClose(InputStream in) throws IOException { return readTextClose(new InputStreamReader(in)); } public static String readTextClose(Reader in) throws IOException {
public static String readText(File f) throws IOException { Reader in = new FileReader(f); try { return readText(in); } finally { in.close(); } } public static String readText(InputStream in) throws IOException {
String src = IOUtils.readTextClose(MandelbrotDemo.class.getResourceAsStream("Mandelbrot.cl"));
protected static String readRawSourceForClass(Class<?> c) throws IOException { String simpleName = c.getSimpleName(); InputStream srcIn = c.getResourceAsStream(simpleName + ".cl"); try { if (srcIn == null) srcIn = c.getResourceAsStream(simpleName + ".c"); if (srcIn == null) throw new FileNotFoundException("OpenCL source code not found : '" + simpleName + "'"); return IOUtils.readText(srcIn); } finally { if (srcIn != null) srcIn.close(); } } protected CLAbstractUserProgram(CLProgram program, String rawSource) {
String src = IOUtils.readTextClose(MandelbrotDemo.class.getResourceAsStream("Mandelbrot.cl"));
public String getIncludedSourceContent(String path) throws IOException { URL url = getIncludedSourceURL(path); if (url == null) return null; String src = IOUtils.readText(url); return src; }
String src = IOUtils.readTextClose(MandelbrotDemo.class.getResourceAsStream("Mandelbrot.cl"));
protected static String readRawSourceForClass(Class<?> c) throws IOException { String simpleName = c.getSimpleName(); InputStream srcIn = c.getResourceAsStream(simpleName + ".cl"); try { if (srcIn == null) srcIn = c.getResourceAsStream(simpleName + ".c"); if (srcIn == null) throw new FileNotFoundException("OpenCL source code not found : '" + simpleName + "'"); return IOUtils.readText(srcIn); } finally { if (srcIn != null) srcIn.close(); } } protected CLAbstractUserProgram(CLProgram program, String rawSource) {
static synchronized String getSource() throws IOException { InputStream in = Platform.getClassLoader(ReductionUtils.class).getResourceAsStream(sourcePath); if (in == null) throw new FileNotFoundException(sourcePath); return source = IOUtils.readText(in); }
static synchronized String getSource() throws IOException { InputStream in = Platform.getClassLoader(ReductionUtils.class).getResourceAsStream(sourcePath); if (in == null) throw new FileNotFoundException(sourcePath); return source = IOUtils.readText(in); }
public String getIncludedSourceContent(String path) throws IOException { URL url = getIncludedSourceURL(path); if (url == null) return null; String src = IOUtils.readText(url); return src; }
private void resolveInclusions(String source, Map<String, URL> ret) throws IOException { List<String> includedPaths = new ArrayList<String>(); Matcher m = includePattern.matcher(source); while (m.find()) { includedPaths.add(m.group(1)); } for (String includedPath : includedPaths) { if (ret.containsKey(includedPath)) continue; URL url = getIncludedSourceURL(includedPath); if (url == null) { assert log(Level.SEVERE, "Failed to resolve include '" + includedPath + "'"); } else { String s = IOUtils.readText(url); ret.put(includedPath, url); resolveInclusions(s, ret); } } }
private void resolveInclusions(String source, Map<String, URL> ret) throws IOException { List<String> includedPaths = new ArrayList<String>(); Matcher m = includePattern.matcher(source); while (m.find()) { includedPaths.add(m.group(1)); } for (String includedPath : includedPaths) { if (ret.containsKey(includedPath)) continue; URL url = getIncludedSourceURL(includedPath); if (url == null) { assert log(Level.SEVERE, "Failed to resolve include '" + includedPath + "'"); } else { String s = IOUtils.readText(url); ret.put(includedPath, url); resolveInclusions(s, ret); } } }
public DFT(CLQueue queue) throws IOException, CLBuildException { this.queue = queue; this.context = queue.getContext(); String source = IOUtils.readText(DFT.class.getResource("DiscreteFourierTransformProgram.cl")); program = context.createProgram(source); kernel = program.createKernel("dft"); }
private void compileProgram() throws Exception{ String sources = IOUtils.readText(BufferReadTest.class.getResourceAsStream("BufferReadTest.c")); program = context.createProgram(sources).build(); } private synchronized void initializeCLContextAndQueueOrNothing(int platformNumber, int deviceNumber) {