Easy::Jit Just-In-Time compilation for C++ codes Serge Guelton Juan - - PowerPoint PPT Presentation

easy jit
SMART_READER_LITE
LIVE PREVIEW

Easy::Jit Just-In-Time compilation for C++ codes Serge Guelton Juan - - PowerPoint PPT Presentation

Easy::Jit Just-In-Time compilation for C++ codes Serge Guelton Juan Manuel Martinez Caamao (me) from Quarkslab Introduction Compiler-assisted library


slide-1
SLIDE 1

Easy::Jit

Just-In-Time compilation for C++ codes

Serge Guelton Juan Manuel Martinez Caamaño (me) from Quarkslab

slide-2
SLIDE 2

Introduction

✔ Compiler-assisted library for runtime code generation

  • Easy to understand C++ wrapper around the LLVM

✘ An omniscient virtual machine ✘ Read-Eval-Print Loop ✘ Building blocks for a Just-in-Time compiler

slide-3
SLIDE 3

Easy::Jit: by example

static void apply_filter(const char *mask, unsigned mask_size, unsigned mask_area, cv::Mat &image, cv::Mat *&out) { kernel(mask, mask_size, mask_area, image.ptr(0,0), out->ptr(0,0), image.rows, image.cols, image.channels()); }

slide-4
SLIDE 4

Easy::Jit: by example

static void apply_filter(const char *mask, unsigned mask_size, unsigned mask_area, cv::Mat &image, cv::Mat *&out) { kernel(mask, mask_size, mask_area, image.ptr(0,0), out->ptr(0,0), image.rows, image.cols, image.channels()); }

slide-5
SLIDE 5

Easy::Jit: by example

static void apply_filter(const char *mask, unsigned mask_size, unsigned mask_area, cv::Mat &image, cv::Mat *&out) { kernel(mask, mask_size, mask_area, image.ptr(0,0), out->ptr(0,0), image.rows, image.cols, image.channels()); }

slide-6
SLIDE 6

#include <easy/jit.h> static void apply_filter(const char *mask, unsigned mask_size, unsigned mask_area, cv::Mat &image, cv::Mat *&out) { using namespace std::placeholder; auto callme = easy::jit(kernel, mask, mask_size, mask_area, _1, _2, image.rows, image.cols, image.channels()); callme(image.ptr(0,0), out->ptr(0,0)); }

Easy::Jit: by example

slide-7
SLIDE 7

#include <easy/code_cache.h> static void apply_filter(const char *mask, unsigned mask_size, unsigned mask_area, cv::Mat &image, cv::Mat *&out) { using namespace std::placeholder; static easy::Cache<> cache; auto const& callme = cache.jit(kernel, mask, mask_size, mask_area, _1, _2, image.rows, image.cols, image.channels()); callme(image.ptr(0,0), out->ptr(0,0)); }

Easy::Jit: by example

slide-8
SLIDE 8

How?

slide-9
SLIDE 9

Easy::Jit: Internals

  • 1. Parse calls to easy::jit and embed bitcode
slide-10
SLIDE 10

Easy::Jit: Internals

  • 2. Associate function pointers with bitcode
slide-11
SLIDE 11

Easy::Jit: Internals

  • 3. Recover the bitcode using the function pointer,

specialize, apply classical optimizations

slide-12
SLIDE 12

Easy::Jit: Internals

  • 4. Generate code
slide-13
SLIDE 13

Easy::Jit: Internals

  • 5. Wrap in an opaque object
slide-14
SLIDE 14

Easy::Jit: The numbers

slide-15
SLIDE 15

Final words

slide-16
SLIDE 16

Easy::Jit: Stuff not mentioned

  • Serialization / Deserialization on standard streams
  • Inlining of function
  • Composition of generated code
  • Devirtualization of virtual method calls
slide-17
SLIDE 17

Easy::Jit: Contribute!

  • C API (work started)
  • Cache: Threading + Persistency
  • Member functions and function objects
  • Partial Evaluation

void eval(AST* ast, int variables[]); ... auto program = easy::jit(eval, my_ast, _1); program(var_values)

slide-18
SLIDE 18

Contribute!

github.com/jmmartinez/easy-just-in-time

Merci Quarkslab :)