Changeset 7501


Ignore:
Timestamp:
01/11/11 12:40:00 (9 years ago)
Author:
rlentz
Message:

Added a readme

This code was developed to show how to use JOCL to leverage OpenCL within ImageJ both on the machine
ImageJ is running from as well as remotely, using binary web services.

src - Java and OpenCL source files
sourcedata - PSF and 3D data used as a very small sample data set for the FHT3D Example.
lib - libraries needed for classes using JOCL, ImageJ, and Hessian 4.0.7

There are several components available in this project to demonstrate various capabilities for use within ImageJ.

Please ensure you have installed OpenCL and successfully run at least one included GUI based example

Setup: Install OpenCL for your host machine.

To OpenCL files from Java we use JOCL which enables development of OpenCL plugins for ImageJ.

Look in the source (src) directory and note the location of fht.cl and sobel.cl. These files are referenced at runtime and
compiled for execution by an OpenCL enabled device.
Start with SobelFilterExample.java and run as Java Application with VM Arguments -Xmx1024m.
The program will load an image from a web server, process it locally using OpenCL, and display the results. This action
acts as a test/control gate to ensure configuration of JOCL and OpenCL native libraries. Modify this example
to suite your needs, but be sure JOCL and OpenCL are working correctly before proceeding.


Working with ImageJ: If developing an ImageJ plugin using OpenCL realize that the runtime logic can be placed in the run(String) method.
JOCL jars and native libraries for the target platform will need to be available for JOCL to make calls into the OpenCL libraries installed on the runtime host.

Now that you have called OpenCL from Java on your platform. You might have a compute intensive portion of
a processing pipeline that you may wish to port to OpenCL. The FHT3D_3D_Deconvolution.java class demonstrates calling OpenCL to perform
a portion of the processing required from within a complex implementation.

Finally, the need may arise where the GPU compute capabilities you wish to leverage are not on the same computer that ImageJ is running on. The FHTEJBService and
Iterative_Deconvolve_3D_WS classes demonstrate how to remotely serve up the functionality leveraging standard, open source J2EE technologies.


Location:
branches/maven/projects/opencl-decon
Files:
3 added
3 edited

Legend:

Unmodified
Added
Removed
  • branches/maven/projects/opencl-decon/.classpath

    r6963 r7501  
    2222        </classpathentry> 
    2323        <classpathentry kind="lib" path="lib/newt.all.jar"/> 
     24        <classpathentry kind="lib" path="lib/JOCL-0.1.4-beta1-bin-apple-x86_64/hessian-4.0.7.jar" sourcepath="lib/JOCL-0.1.4-beta1-bin-apple-x86_64/hessian-4.0.7-src.jar"/> 
    2425        <classpathentry kind="output" path="bin"/> 
    2526</classpath> 
  • branches/maven/projects/opencl-decon/src/demos/Iterative_Deconvolve_3D_WS.java

    r7176 r7501  
    7575        if (fhtejbservice == null) { 
    7676            try { 
    77                 String url = "http://144.92.92.76:8080/EJBHessianFHT/FHTEJBService"; 
     77                String url = "http:microscopy.wisc.edu/EJBHessianFHT/FHTEJBService"; 
    7878                HessianProxyFactory factory = new HessianProxyFactory(); 
    7979                fhtejbservice = (FHTEJBService) factory.create(FHTEJBService.class, url); 
  • branches/maven/projects/opencl-decon/src/publication/SobelFilterExample.java

    r7094 r7501  
    11package publication; 
    2  
    3  
    4  
    5  
    62 
    73import java.awt.Image; 
     
    2521import com.jogamp.opencl.CLProgram; 
    2622 
     23/** 
     24 * This example will fetch an image from the web and use the installed OpenCL libraries on your host machine to process the image.  
     25 * The class will display the processed image. 
     26 * @author rick 
     27 * 
     28 */ 
    2729public class SobelFilterExample { 
    2830        static boolean DEBUG = true; 
     
    4850        } 
    4951 
    50         public SobelFilterExample ( int w, int h ) 
     52        public SobelFilterExample ( int w, int h, boolean printDebugStatements ) 
    5153        { 
    5254                imageHeight = h; 
    5355                imageWidth = w; 
    5456 
    55                 final boolean DEBUG = true; 
     57                final boolean DEBUG = printDebugStatements; 
    5658                try { 
    5759 
     
    111113        private synchronized long run( ) 
    112114        {                
    113                 //if( DEBUG ) { System.out.println("Writing the input data set and the convolveKernel to the device...");} 
     115                if( DEBUG ) { System.out.println("Writing the input data set and the convolveKernel to the device...");} 
    114116                queue.putWriteBuffer( clFloatBufferData, false ); 
    115117 
     
    117119                queue.putCopyBuffer( clFloatBufferData, clFloatBufferDataCopy ); 
    118120 
    119                 //if( DEBUG ) System.out.println("Starting the timer..."); 
     121                if( DEBUG ) System.out.println("Starting the timer..."); 
    120122                long time = System.currentTimeMillis(); 
    121123 
    122                 //if( DEBUG ) { System.out.println("Enqueing the kernel w...");} 
     124                if( DEBUG ) { System.out.println("Enqueing the kernel w...");} 
    123125                queue.put2DRangeKernel(kernel, 0, 0, imageWidth, imageHeight, 0, 0); 
    124126 
    125                 //if( DEBUG ) { System.out.println("Waiting for CLFinish to return...");} 
     127                if( DEBUG ) { System.out.println("Waiting for CLFinish to return...");} 
    126128                queue.finish(); 
    127129 
    128                 //if( DEBUG ) System.out.println("Stopping the java timer..."); 
     130                if( DEBUG ) System.out.println("Stopping the java timer..."); 
    129131                time = System.currentTimeMillis() - time; 
    130132 
    131                 //if( DEBUG )  System.out.println("Reading back data from the device..."); 
     133                if( DEBUG )  System.out.println("Reading back data from the device..."); 
    132134                queue.putReadBuffer( clFloatBufferData, true ); 
    133135 
     
    137139        public static synchronized void main(String[] args) 
    138140        { 
    139                 final int numVariables = 4; 
    140                 final int numIterations = 50; 
    141                 long[] times = new long[numVariables]; 
    142  
    143                 //run test 
    144                 runTest( numIterations, times ); 
    145  
    146                 System.out.println("The average OpenCL set up time is " + times[0]/numIterations); 
    147                 System.out.println("The average OpenCL IO transfer time is " + times[1]/numIterations); 
    148                 System.out.println("The average OpenCL execution time is " + times[2]/numIterations); 
    149                 System.out.println("The average Java execution time is " + times[3]/numIterations); 
    150         } 
    151  
    152  
    153         public static float getAvg( int c ) { 
    154                 int r = (c&0xff0000) >> 16; 
    155                 int g = (c&0xff00) >> 8; 
    156                         int b = c&0xff; 
    157                         return (r + g + b)/3; 
    158         } 
    159  
    160  
    161         public static synchronized void runTest(int numIterations, long[] totalTime) 
    162         { 
     141                // get an image  
    163142                if( DEBUG )  System.out.println("Retrieving test image...  "); 
    164143                Image image = null;  
     
    167146                        image = ImageIO.read(url);  
    168147                } catch (IOException e) { }  
    169  
     148                 
     149                final int numVariables = 4; 
     150                final int numIterations = 50; 
     151                long[] times = new long[numVariables]; 
     152 
     153                //run test 
     154                runTest( image, numIterations, times ); 
     155 
     156                System.out.println("The average OpenCL set up time is " + times[0]/numIterations); 
     157                System.out.println("The average OpenCL IO transfer time is " + times[1]/numIterations); 
     158                System.out.println("The average OpenCL execution time is " + times[2]/numIterations); 
     159                System.out.println("The average Java execution time is " + times[3]/numIterations); 
     160        } 
     161 
     162 
     163        public static float getAvg( int c ) { 
     164                int r = (c&0xff0000) >> 16; 
     165                int g = (c&0xff00) >> 8; 
     166                        int b = c&0xff; 
     167                        return (r + g + b)/3; 
     168        } 
     169 
     170 
     171        public static synchronized void runTest( Image image, int numIterations, long[] totalTime) 
     172        { 
    170173                int testWidth = image.getWidth(null); 
    171174                int testHeight = image.getHeight(null); 
     
    180183                } 
    181184 
    182  
    183  
    184185                for(int iteration = 0; iteration < numIterations; iteration++) 
    185186                { 
     
    200201 
    201202                                //setup OpenCL 
    202                                 SobelFilterExample generateSobelFilterData = new SobelFilterExample( testWidth, testHeight ); 
     203                                SobelFilterExample generateSobelFilterData = new SobelFilterExample( testWidth, testHeight, true ); 
    203204 
    204205                                //Stop the performance timer 
Note: See TracChangeset for help on using the changeset viewer.