HetCompute Image Processing Tutorial(二)

版权声明:本文为博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/weixin_38498942/article/details/97147460

一、并行平铺

1),粗化任务粒度的一个简单方法是平铺图像并为每个平铺生成任务。这可以通过直接平铺循环来完成。

    

2),或者通过重新构造代码,保留与串行实现相同的去噪内核,并将其调用并行化。

   

二、使并行处理模式化

1),平铺优化负责处理局部性,因为每个任务将以更大的粒度进行计算。但是,您可能会注意到,每个磁贴都会启动一个任务,然后等待所有磁贴完成。虽然HetCompute在启动许多任务方面很有效,但它还有一个模式API,可以提供更好的负载平衡和资源管理。特别是,对于这个例子,使用了hetcompute::pfor_each构造。

2),内核保持不变,但驱动程序功能被重写:

   

3),分析代码:

a,hetcompute::range <2>定义了一个二维范围,从[0,宽度] x [0,高度]开始,每个维度的步长为TILE_SIZE。每个维度可以有不同的步幅。 该范围用作并行循环的迭代空间。

b.hetcompute::pfor_each()构造表示这是一个并行循环,即所有迭代都可以并发执行。传递一个lambda表达式来封装内核(就像Qualcomm HetCompute在上一节中启动任务一样)。在这种情况下,lambda接受一个参数,即范围内的线性索引。hetcompute::pfor_each模式允许HetCompute聚合任务,因为它适合于平台。

c,hetcompute::index <2>定义了一个二维索引。HetCompute范围知道如何迭代到适当的点。linear_to_index调用返回一个对象,该对象在范围的每个维度中具有适当的坐标。可以使用对象上的[]运算符直接访问它们

d,请注意,循环结束时没有hetcompute::wait_for()。hetcompute::pfor_each是一个同步操作,将在内部等待迭代中的所有任务完成。HetCompute还提供了pfor_each的异步版本,即hetcompute::pfor_each_async(),它应该在计算可以继续时使用,因为它不需要循环中产生的数据,例如,重叠几个图像的去噪。有关hetcompute::pfor_each_async()规范,请参阅HetCompute参考手册。

展开阅读全文

java image processing question

04-01

我有一个图像库,自己写了一个编译器,其中有一个问题:private static sun.tools.javac.Main javac;这一行代码编译后出现“package sun.tools.javac donot exist”请问在jdk1.4.2中能否找到这样的包。如果想修改怎样修改。source code:package ij.plugin;rnimport java.awt.*;rnimport java.io.*;rnimport ij.*;rnimport ij.gui.*;rnimport ij.io.*;rnimport ij.util.*;rnimport ij.plugin.frame.Editor;rnimport ij.text.TextWindow;rn//import sun.tools.java.Constants ;rn/** Compiles and runs plugins using the javac compiler. */rnpublic class Compiler implements PlugIn, FilenameFilter rnrn private static sun.tools.javac.Main javac;rn private static ByteArrayOutputStream output;rn private static String dir,name;rn private static Editor errors;rnrn public void run(String arg) rn IJ.register(Compiler.class);rn if (arg.equals("edit"))rn edit();rn elsern compileAndRun(arg);rn rnrn void edit() rn if (open("", "Edit, Compile and Run Plugin...")) rn Editor ed = (Editor)IJ.runPlugIn("ij.plugin.frame.Editor", "");rn if (ed!=null) ed.open(dir, name);rn rn rnrn void compileAndRun(String path) rn if (!isJavac())rn return;rn if (!open(path, "Compile and Run Plugin..."))rn return;rn if (compile(dir+name))rn runPlugin(name);rn rnrn boolean isJavac() rn try rn if (javac==null) rn output = new ByteArrayOutputStream(4096);rn javac = new sun.tools.javac.Main(output, "javac");rn rn catch (NoClassDefFoundError e) rn IJ.error("This JVM appears not to include the javac compiler. Javac\n"rn +"is included with the JRE 1.1.8 bundled with the Windows and\n"rn +"Linux versions of ImageJ. Mac OS 9 users must install Apple's\n"rn +"Java SDK. When using JDK 1.2 and later, the tools.jar file\n"rn +"must be added to the command line that runs ImageJ.");rn return false;rn rn return true;rn rnrn boolean compile(String path) rn IJ.showStatus("compiling: "+path);rn String classpath = System.getProperty("java.class.path");rn IJ.write("classpath: " + classpath);rn output.reset();rn boolean compiled = javac.compile(new String[] "-deprecation","-classpath",classpath,path);rn String s = output.toString();rn boolean errors = (!compiled || (s!=null && s.length()>0));rn if (errors)rn showErrors(s);rn elsern IJ.showStatus("done");rn return compiled;rn rnrn void showErrors(String s) rn if (errors==null || !errors.isVisible())rn errors = (Editor)IJ.runPlugIn("ij.plugin.frame.Editor", "");rn if (errors!=null)rn errors.display("Errors", s);rn IJ.showStatus("done (errors)");rn rnrn // open the .java source filern boolean open(String path, String msg) rn boolean okay;rn String name, dir;rn if (path.equals("")) rn FileDialog fd = new FileDialog(IJ.getInstance(), msg);rn if (this.dir!=null)rn fd.setDirectory(this.dir);rn else rn String pluginsDir = Menus.getPlugInsPath();rn if (path!=null)rn fd.setDirectory(pluginsDir);rn rn if (this.name!=null)rn fd.setFile(this.name);rn GUI.center(fd);rn fd.setFilenameFilter(this);rn fd.setVisible(true);rn name = fd.getFile();rn okay = name!=null;rn dir = fd.getDirectory();rn fd.dispose();rn if (okay && !(name.endsWith(".java")||name.endsWith(".txt"))) rn IJ.error("File name must end with \".java\".");rn okay = false;rn rn else rn int i = path.lastIndexOf('/');rn if (i==-1)rn i = path.lastIndexOf('\\');rn if (i>0) rn dir = path.substring(0, i+1);rn name = path.substring(i+1);rn else rn dir = "";rn name = path;rn rn okay = true;rn rn if (okay) rn this.name = name;rn this.dir = dir;rn rn return okay;rn rnrn // only show files with names ending in ".java"rn // doesn't work with Windowsrn public boolean accept(File dir, String name) rn return name.endsWith(".java");rn rnrn // run the plugin using a new class loaderrn void runPlugin(String name) rn name = name.substring(0,name.length()-5); // remove ".java"rn new PlugInExecuter(name);rn rnrnrnrnrnclass PlugInExecuter implements Runnable rnrn private String plugin;rn private Thread thread;rnrn /** Create a new object that runs the specified pluginrn in a separate thread. */rn PlugInExecuter(String plugin) rn this.plugin = plugin;rn thread = new Thread(this, plugin);rn thread.setPriority(Math.max(thread.getPriority()-2, Thread.MIN_PRIORITY));rn thread.start();rn rnrn public void run() rn try rn IJ.getInstance().runUserPlugIn(plugin, plugin, "", true);rn catch(Throwable e) rn IJ.showStatus("");rn IJ.showProgress(1.0);rn ImagePlus imp = WindowManager.getCurrentImage();rn if (imp!=null) imp.unlock();rn String msg = e.getMessage();rn if (e instanceof RuntimeException && msg!=null && e.getMessage().equals("Macro canceled"))rn return;rn CharArrayWriter caw = new CharArrayWriter();rn PrintWriter pw = new PrintWriter(caw);rn e.printStackTrace(pw);rn String s = caw.toString();rn if (IJ.isMacintosh())rn s = Tools.fixNewLines(s);rn new TextWindow("Exception", s, 350, 250);rn rn rnrnrn并请详细解释这些代码啊--谢谢 论坛

没有更多推荐了,返回首页