owned this note changed 6 years ago
Linked with GitHub

Julia 語言設計與 JIT 編譯器 - 杜岳華

由於場地問題,第二天我們移動到另一棟大樓啦!議程教室變動請見網站上的議程表

歡迎來到 https://hackmd.io/@coscup/2019 共筆 :mega:
點擊本頁上方的 開始用 Markdown 一起寫筆記!
手機版請點選上方 按鈕展開議程列表。

請從這裡開始

簡報

Multiple dispatch

呼叫函數時比較參數類型,考慮參數類型而呼叫不同函式(類似 C function overloading )

Generic programming 泛型

與 Templete 意義類似

  • Parametric types and parametric methods
  • Similar to multiple dispatch with parametric polymorphism.
  • All types are first-class: can be dispatched and declared

Metaprogramming

  • Macro
  • Generated function

Macro

In [1]

macro sayhello(name)
    return :( println("Hello, ", $name) )
end

Out[1]

@sayhello (macro with 1 method)

In[2]

@sayhello "Andy"

Hello, Andy

輸入變數,吐出一段 code

Generated function

@generated function foo(x)
    Core.println(x)
    return :(x * x)
end

Compile time

Compiler compile time

Compiler runtime

Compiler details

Julia compile time

Julia IR

  • SSA form
  • 類似 LLVM IR

warn_type

  • dynamic programming 時無法取得詳細的 type 資訊
  • 補充 type 資訊

Static Single Assignment form (SSA)

  • Each variable is assigned exactly once.
  • Every variable is defined before it used.

Simplify and improve the compiler optimization

  • constant propagation
  • value range propagation
  • sparse conditional constant propagation
  • dead code elimination
  • global value numbering
  • partial redundancy elimination
  • strength reduction
  • register allocation

Runtime

Functions

Julia functions are generic functions.
generic functions :

  • 紀錄 function name,再由 function table 查詢 method

Julia

  • function : 只有 function name
  • method : 有實做

A generic function is a single function and consists of many methods.

The methods of a function is stored in a method table.

JIT comiliation

Staged programming

Leverage the type in input of code and generate optimized code

@generated function foo(::Array{T,N}, ...) where {T,N}
    ...
    x = Matrix{T}()
    for i = 1:N
        ...
    end
end

Hackable compiler
Python and Numba

​​​​Ref. Effective Extensible Programming: Unleashing Julia on GPUs 

Hackable compiler

Python and Numba

Ref. Effective Extensible Programming: Unleashing Julia on GPUs

Reflection and introspection

tags: COSCUP2019 Julia language IB501
Select a repo