This article discusses the use of the Java platform for development 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, the development of software for mass-produced computing devices with a high degree of parallelism is gaining popularity. These are modern multi-core processors with SIMD commands and video accelerators with support for GPGPU (General-purpose computations on GPU), devices combining a central and graphics co-processor on a single AMD Fusion crystal, as well as specialized coprocessors. Almost every type of device has its own command system, architectural features, and application development previously required the developer to know several programming languages and APIs (application programming interfaces). All this made programming much more complicated, and also made it impossible or economically inexpedient to change the platform (vendor lock-in). The Alliance of hardware and software manufacturers has developed and standardized the OpenCL language, which solves these problems. This is an open standard and there are several implementations from different manufacturers of hardware from AMD, Intel, Nvidia, IBM, etc. under Windows, Linux and MacOS operating systems.
Under Windows for VisualStudio, there are NVIDIA plug-ins - Parallel Nsight and gDEBugger from AMD. And if with OpenCL compiler and runtime runtime for the operating systems listed earlier there are no problems, then AMD / Nvidia is much more complicated with the Linux development environment.
')
When host code is part of OpenCL code that prepares data and coordinates the work of OpenCL cores, is written in Java, debugging problems occur in Linux / Windows OS. If you recall the success of the Java platform in the cross-platform server software development market, it is unclear why hardware vendors still do not develop OpenCL development tools - debugging and profiling built into Eclipse IDE, Netbeans IDE, IntelliJ Idea. In the meantime, these development environments do not include ready-made tools that simplify working with the technology in question, we will try to solve the development problems with the means available today. This will allow us to get a competitive industrial solution optimized for work on modern computing devices.
Advantages and disadvantages of sharing Java and OpenCL
So why use the Java platform to develop host code for OpenCL? I will give several reasons for this choice:
- Cross-platform - Java Virtual Machine (JVM) exists for a variety of platforms - Windows, Linux, MacOS, Unix. "Write once, run anywhere." There are also implementations from various JVM vendors, open source implementations;
- A huge number of developers / architects who know this platform. Simplicity and convenience of team development, testing, ease of debugging and profiling, software release and delivery of system modules in production;
- A large number of open source libraries available for use in development. An incalculable number of sources and consumers of data available in java applications (http, soap, rest, smtp, scp, jms, CORBA, databases - relational / NoSQL, etc.), for example, from Apache Camel components;
- Platform for cloud applications: the availability of frameworks for the development of distributed and flexible applications, processing of huge amounts of data, for example using Apache Hadoop;
- Recognized corporate (enterprise) standard in banks, financial institutions, telecommunications sphere: a large staff of system administrators who are able to support the work of the JVM;
- Many programming languages that can be executed in JVM: jruby, PHP (Caucho quercus), jython, javascript (Mozilla Rhino), Scala, etc. The existence of a large number of languages allows both optimizing existing applications and developing new ones more productively. As a result, in-process calls from these languages to java classes using OpenCL. Sometimes it is better to use OpenCL API binding specifically for the language used. Sometimes the frameworks used in DSL are written in java by some developers and are used by other developers in the programming languages inside the JVM for rapid application development;
- JavaCL is a compact and object-oriented API for OpenCL host code.
When not to use Java to write OpenCL host code:
- The undetectedness of the garbage collector. Your application may require low latency when processing data and issuing a response (for example, a trading system or control program for medical equipment);
- High overhead for copying data between JVM and native code, incl. OpenCL implementations. This also includes the lack of code for jvm that can read and write the data you need;
- The algorithm cannot be effectively implemented within the framework of the OpenCL architecture. Not all algorithms are well parallelized ( Amdahl-Ware law ), the data transfer time on the bus can be many times longer than the computing time on the device, etc. This problem is related to the algorithm and the approach in general, and not to java in particular. No host code for OpenCL API calls can be useful in this case.
So, we decided that our task is suitable for OpenCL and cannot be implemented as effectively using only the Java language. At the same time, we want to take advantage of the JVM. Let's move from idea to implementation.
Technology
I recommend for the development of
OpenCL in the implementation of AMD , if in the future it is planned to switch to using the server processor APU Opteron instead of a desktop solution based on AMD + Radeon HD 5000/6000 CPU or AMD Fusion CPU.
JavaCL as an API for working with OpenCL. Using bridJ to call the native code of the OpenCL API dynamic library, we get a performance boost over JNA.
Debug Toolkit: gdb with text user interface or ddd as gdb frontend
For code profiling, I recommend using the AMD APP Profiler from the AMD Accelerated Parallel Processing (APP) SDK, Ubuntu 11.04 OS with the AMD proprietary FGLRX graphics driver installed for development. Development can be carried out in any Java IDE supporting maven projects. But support for syntax highlighting and compilation of OpenCL functions while writing code currently only supports the
plugin for netbeans . The work of this plug-in was extremely unstable.
Creating an infrastructure for development and the development process is no different from working with other java technologies.
The debugging tools are more complicated, but there is a solution to this problem. AMD's OpenCL runtime allows you to debug kernels when running on a CPU: set breakpoints and display the values of variables, including float4, int4 vector types, etc. In this case, the GPU functions are emulated on the central processor, for example, for working with textures. For those interested in debugging details, there is an article
on debugging JavaCL and OpenCL under linux . Also, the project author has
created a wiki page about debugging kernel code from Java. Details of supported
gdb extensions
for OpenCL
You can use the
AMD APP Profiler to profile an application. When launched in Linux, it allows you to collect statistics on the operation of OpenCL functions in the application and save it to a CSV file for later analysis of data in a table processor LibreOffice Calc. To understand how optimally your code works, you need to interpret the values 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 prospects for the development of computing devices along the path of increasing parallelism, this approach in software development claims to be one of the main in the development of high-performance enterprise and cloud presentations on the JVM.