Call interface as well, which involves passing pointers to GNU R internal SEXPREC structures. Renjin has supported this interface for some time, but starting with version 0.8.x released at the end of last year, we now support the. Fortran interfaces, simply pass the R vectors as double-precision or integer arrays to C or Fortran functions, which might look like this: void kmeans_Lloyd(double *x, int *pn, int *pp, The simplest of these methods, the so-called. GNU R provides several methods for interfacing with native code from R. Like Scala or Clojure, we're targeting the Java Virtual Machine, the virtual machine original designed for Java but that has its own standard instruction set. Note that we're not compiling to the Java language. GCC-Bridge consists of a small plugin for GCC itself, which dumps the optimized gimple out to a JSON file, one per source file, and a compiler, a Java program which compiles the json-encoded Gimple files to Java class files, using the ASM bytecode library. This is terrific, because I really, really, didn't want to have to learn Fortran! Consider a simple C function which sums an array of double-precision floating point:Īll the complexities of C and Fortran are reduced to a simple list of statements, with a small number of operations. GCC performs most of its optimizations on Gimple, before lowering it even further to another intermediate language called the Register Transfer Language (RTL), which is then handed over to the backends to generate actual machine instructions.įor us, Gimple is also a terrific starting point for a compiler targeting the JVM. GCC achieves this small miracle by reducing all input languages into a common, simple intermediate language called Gimple. GCC-Bridge, as its name implies, builds on the GNU Compiler Collection (GCC), which has a modular structure designed to support multiple input languages, including C, C++, and Fortran, and multiple backends targeting, for example, x86, ARM, MIPs, etc. More troubling, the widespread use of global variables in package native code would severely complicate Renjin's auto parallization strategies, and prevent users from running multiple, concurrent Renjin sessions in the same JVM process.įor these reasons, we set out to build GCC-Bridge, a toolchain that could compile C, C++, and Fortran sources to pure Java bytecode. If we were to try to use JNI to load platform-specific native libraries, then we would inherit all of the deployment headaches that we set to solve in building Renjin on the JVM, and loose the ability to run on Google AppEngine and other sandboxed environments. Within the latest available package version.īut we also wanted a solution that preserved Renjin's advantages over GNU R. Millions of lines of code (MLOC), excluding blank lines, And so while our ultimate goal is to allow users to write fast R code without falling back to another language, if we're to be serious about running existing R packages, then we need a solution for the existing native code base. Supporting R packages with native code is a big deal: 48% of CRAN's 33 MLOC of code is native code. In this post, I wanted to finally give a proper introduction to GCC-Bridge, a C/Fortran compiler targeting the Java Virtual Machine (JVM) that makes it possible for Renjin to run R packages that include "native" C and Fortran code without sacrificing platform independence. Introducing GCC-Bridge: A C/Fortran compiler targeting the JVM
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |