<div dir="ltr"><div>Hi all, </div><div><br></div><div>I want to share our experience and some benchmark results using FFM API and jextract in Deep Netts.</div><div><br></div><div>We've used jextract to generate bindings for CUDA libraries to create a replacement for JCUDA  that was previously used, and here are some observations (note that we didn't generate entire API just a subset that we needed)</div><div><br></div><div>What we liked:</div><div>1. Generating bindings using jextract is pretty straightforward.  It requires a bit of experimentation and practice to figure out 
available options  and the best configuration.</div><div>2. We actually didn't have to write any binding code, everything was generated, and it will be easy to regenerate for a new version when required.</div><div><br></div><div>
<div>Performance and benchmarking<br>We benchmarked 100 iterations of image classification using VGGNet convolutional neural network:</div><div>1. We got the same performance as with JNI (used by JCuda).</div><div>2. Nearly same performance as PyTorch (Python and C)</div><div>3. Java 25 performed significantly better 

and more stable

than 
Java 22, while running the benchmark. </div><div>Java 25, required only 
one warmup iteration after which results were stable, and had 
significantly lower variation overall, while Java 22 required up to 40 
warmup iterations to stabilize, and had large variations  (up to 8x). <br></div><div>So difference in stability between Java 22 and 25 is huge (at least for our use case)</div></div><div><br></div><div>Few observations</div><div>
1. Enums are mapped to functions. It would make more sense if they could be Java enums.</div><div>2. Code for dependent libraries was duplicated  for each library if it was in a different package. The solution for us was to put all generated bindings/classes in a single package.</div><div>3. Binding for C types are duplicated for each .h file/generated class. Would be cleaner if these are generated on only one shared place</div><div>4. Generated API will always require a layer on top of it. It strictly corresponds to native API style, for C with pointers/MemorySegments and status code returns.</div><div>5. Jextract is available only in version 22 (and based on JDK22), which can add confusion which version to use for which version of Java <a href="https://jdk.java.net/jextract/">https://jdk.java.net/jextract/</a></div><div>It would be great if it follows the releases of JDK</div><div></div><br><div><div>I hope this helps and keep doing great work.</div><div><br></div><div>Best regards</div><div>Zoran Sevarac</div>

<br></div><div>.</div></div>