Home High Performance Developing with Java and OpenCL: The Road to the Cloud

Developing with Java and OpenCL: The Road to the Cloud

by admin

Developing with Java and OpenCL: The Road to the Cloud
This article discusses the use of the Java platform for development in conjunction with OpenCL, the advantages and disadvantages of this approach.The combination of these technologies in software development in the future will allow to use the full power of cloud computing and OpenCL
Recently software development for mass produced computing devices with high degree of parallelism has been gaining popularity. These are modern multicore processors with SIMD commands and video gas pedals with GPGPU support (General-purpose computations on GPU), devices combining central and graphic coprocessor on one AMD Fusion chip, as well as specialized coprocessors. Almost every type of devices has its own system of commands, architectural features and development of applications previously required from the developer knowledge of multiple programming languages and APIs (Application Programming Interfaces). All this made programming very complicated, as well as impossible or economically unreasonable to change the platform (vendor lock-in). Alliance of hardware and software manufacturers developed and standardized OpenCL language that solves these problems. It is an open standard and there are several implementations from different hardware manufacturers AMD, Intel, Nvidia, IBM, etc. for Windows, Linux and MacOS operating systems.
For Windows, there are plug-ins by NVIDIA for VisualStudio – Parallel Nsight and gDEBugger by AMD. While there are no problems with the OpenCL compiler and runtime environment for the operating systems listed above, the development environment for Linux is much more complicated for AMD/Nvidia.
When the host code, the part of OpenCL code that prepares data and coordinates the OpenCL kernels, is written in Java, Linux/Windows OS experiences debugging problems. Remembering the success of Java platform at the cross-platform server software development market, it is not clear why the hardware vendors have not yet started developing OpenCL development tools – debugging and profiling tools embedded in Eclipse IDE, Netbeans IDE and IntelliJ Idea. Until these development environments provide a ready toolkit simplifying the work with the technology in question, let us try to solve the development tasks with the tools available today. This will allow us to get a competitive industrial solution, optimized to work on modern computing devices.

Advantages and disadvantages of using Java and OpenCL together

So why use the Java platform to develop host code for OpenCL? Here are a few reasons why I think it’s a good choice :

  • Cross-platform – Java Virtual Machine (JVM) exists for multiple platforms – Windows, Linux, MacOS, Unix. "Write once, run anywhere." There are also implementations from various JVM vendors, open source implementations;
  • Huge number of developers/architects who know this platform. Easy and convenient collaborative development, testing, easy debugging and profiling, software release and delivery of system modules in production;
  • Large number of open source libraries available for use in development. Countless data sources and consumers available for java applications (http, soap, rest, smtp, scp, jms, CORBA, databases – relational/NoSQL, etc.), e.g. from Apache Camel ;
  • Platform for cloud applications : availability of frameworks for developing distributed and elastic applications, processing huge amounts of data, e.g. with Apache Hadoop;
  • Recognized enterprise standard in banks, financial institutions, telecom industry: a large staff of system administrators who can support JVM;
  • Many programming languages capable of running in the JVM: jruby, PHP(Caucho quercus), jython, javascript (Mozilla Rhino), Scala, etc. The existence of a large number of languages allows both the optimization of existing applications and the more productive development of new ones. As a consequence, in-process calls from these languages are made to java classes using OpenCL. Sometimes it is better to use OpenCL API binding specifically for the language you are using. Sometimes the frameworks used in DSL are written in java by some developers and used by other developers in programming languages within JVM for quicker application development;
  • JavaCLis a compact and object-oriented API for OpenCL host code.

When not to use Java to write OpenCL host code :

  • Non-deterministic operation of the garbage collector. Your application may require low latency for data processing and response (e.g., a trading system or a control program for medical equipment);
  • There is a big overhead in copying data between JVM and native code, including OpenCL implementations. This also includes the lack of code for jvm that can read and write the data you need;
  • The algorithm cannot be implemented efficiently within the OpenCL architecture. Not all algorithms parallelize well( Amdahl-Wehr’s law ), the bus transfer time can be many times the computation time of the device, etc. This problem has to do with the algorithm and approach in general, not java in particular. No host code for OpenCL API calls can be useful in this case.

So, we have decided that our task is suitable for OpenCL and it is not possible to implement it as efficiently using only Java language. At the same time we want to take advantage of JVM. Let’s go from idea to implementation.

Technology

Recommended for development OpenCL in AMD implementation if you plan to move to an APU Opteron server processor instead of an AMD CPU + Radeon HD 5000/6000 or AMD Fusion based desktop solution in the future. JavaCL as an API to work with OpenCL. Using bridJ to call the native code of the dynamic OpenCL API library, we get a performance boost compared to JNA.
Debugging tools : gdb with text user interface or ddd as frontend gdb
For code profiling I recommend using AMD APP Profilerfrom AMD Accelerated Parallel Processing (APP) SDK, Ubuntu 11.04 OS with AMD proprietary FGLRX graphics driver installed for development. Development could be done in any Java IDE that supports maven projects. But the only one supporting syntax highlighting and compiling OpenCL functions while writing code at the moment is plugin for netbeans This plugin turned out to be very unstable.
Creating the infrastructure for development and the development process is not different from working with other java technologies.
The debugging tools are more complicated, but there is a solution to this problem too. AMD OpenCL runtime environment allows to debug the kernels when running on CPU: to set breakpoints and display values of variables, including vector types float4, int4, etc. At the same time, GPU functions are emulated on the CPU, e.g. to work with textures. For those interested in the details of debugging there is an article on debugging JavaCL and OpenCL on linux Also the author of the project created a wiki page debugging kernel code from Java. More information about supported extensions gdb for OpenCL
To profile the application, you can use AMD APP Profiler When run on Linux, it allows you to collect statistics about the performance of OpenCL functions in the application and save them to a CSV file for later analysis of the data in the LibreOffice Calc spreadsheet processor. To understand how optimally your code works, you need to interpret the values of of the parameters measured by the profiler

Conclusion

The article examined the advantages and disadvantages of software development using the Java platform and OpenCL technology. Due to the perspective of computing devices on the way of parallelism increase, this approach in software development pretends to become one of the major ones in developing high-performance enterprise and cloud applications on JVM.

You may also like