ember.cpp 0.1.0
C++ inference engine for Llama-family and paperkiln models (CPU, CUDA, WebAssembly)
Loading...
Searching...
No Matches
ember_ir::expr Namespace Reference

Classes

class  Expr
 
struct  Instr
 
struct  Node
 
struct  Stage
 

Enumerations

enum class  Kind {
  NUMBER , INPUT , NEG , ADD ,
  SUB , MUL , DIV , POW ,
  EXP , LOG , SQRT , TANH ,
  SIGMOID , ERF , ABS , RELU ,
  MAX , MIN , WHERE , ROWSUM ,
  ROWMEAN , ROWMAX
}
 
enum class  Op : int {
  CONST , INPUT , COL , WIDTH ,
  NEG , EXP , LOG , SQRT ,
  TANH , SIGMOID , ERF , ABS ,
  RELU , ADD , SUB , MUL ,
  DIV , POW , MAX , MIN ,
  WHERE
}
 

Functions

std::vector< Stage > lower (const Expr &e)
 
void eval (const Expr &e, const std::vector< const float * > &ins, int T, int w, float *out)
 
const Expr & cached (const std::string &text, size_t n_inputs)
 

Variables

constexpr size_t kMaxCode = 96
 
constexpr size_t kMaxStack = 16
 
constexpr size_t kMaxColumns = 8
 

Enumeration Type Documentation

◆ Kind

Enumerator
NUMBER 
INPUT 
NEG 
ADD 
SUB 
MUL 
DIV 
POW 
EXP 
LOG 
SQRT 
TANH 
SIGMOID 
ERF 
ABS 
RELU 
MAX 
MIN 
WHERE 
ROWSUM 
ROWMEAN 
ROWMAX 

Definition at line 22 of file graph_ir_expr.h.

◆ Op

Enumerator
CONST 
INPUT 
COL 
WIDTH 
NEG 
EXP 
LOG 
SQRT 
TANH 
SIGMOID 
ERF 
ABS 
RELU 
ADD 
SUB 
MUL 
DIV 
POW 
MAX 
MIN 
WHERE 

Definition at line 70 of file graph_ir_expr.h.

70 : int {
71 CONST, INPUT, COL, WIDTH, // push c, input idx at (t, j), column idx at t, (float) w
72 NEG, EXP, LOG, SQRT, TANH, SIGMOID, ERF, ABS, RELU, // pop a, push f(a)
73 ADD, SUB, MUL, DIV, POW, MAX, MIN, // pop b, pop a, push f(a, b)
74 WHERE, // pop b, a, c; push c > 0 ? a : b
75};

Function Documentation

◆ cached()

const Expr & ember_ir::expr::cached ( const std::string &  text,
size_t  n_inputs 
)

Definition at line 530 of file graph_ir_expr.cpp.

530 {
531 static std::mutex mu;
532 static std::map<std::pair<std::string, size_t>, Expr> cache;
533 std::lock_guard<std::mutex> lock(mu);
534 auto key = std::make_pair(text, n_inputs);
535 auto it = cache.find(key);
536 if (it == cache.end()) it = cache.emplace(key, Expr::parse(text, n_inputs)).first;
537 return it->second;
538}
std::string text
size_t j

References j, ember_ir::expr::Expr::parse(), and text.

Referenced by ember_ir::device_supported(), and ember_ir::Interpreter::init().

◆ eval()

void ember_ir::expr::eval ( const Expr &  e,
const std::vector< const float * > &  ins,
int  T,
int  w,
float *  out 
)

Definition at line 522 of file graph_ir_expr.cpp.

522 {
523 if (ins.size() != e.n_inputs())
524 throw std::invalid_argument("expr: " + std::to_string(ins.size()) + " inputs given, \"" + e.text() +
525 "\" was parsed for " + std::to_string(e.n_inputs()));
526 if (T <= 0 || w <= 0) throw std::invalid_argument("expr: inputs must be [T, w] with T, w > 0");
527 Evaluator(ins, T, w).result(e.root(), out);
528}
node out

References j, and out.

◆ lower()

std::vector< Stage > ember_ir::expr::lower ( const Expr &  e)

Definition at line 509 of file graph_ir_expr.cpp.

509{ return Lowering(e).run(); }

References j.

Referenced by ember_ir::device_supported().

Variable Documentation

◆ kMaxCode

constexpr size_t ember_ir::expr::kMaxCode = 96
constexpr

Definition at line 85 of file graph_ir_expr.h.

Referenced by ember_ir::ir_expr_cuda().

◆ kMaxColumns

constexpr size_t ember_ir::expr::kMaxColumns = 8
constexpr

Definition at line 87 of file graph_ir_expr.h.

Referenced by ember_ir::ir_expr_cuda().

◆ kMaxStack

constexpr size_t ember_ir::expr::kMaxStack = 16
constexpr

Definition at line 86 of file graph_ir_expr.h.