def testConstants(self): with self.module.function_context("constants", [], []) as fun: E.constant_float(1.23, self.module.make_scalar_type("bf16")) E.constant_float(1.23, self.module.make_scalar_type("f16")) E.constant_float(1.23, self.module.make_scalar_type("f32")) E.constant_float(1.23, self.module.make_scalar_type("f64")) E.constant_int(1, 1) E.constant_int(123, 8) E.constant_int(123, 16) E.constant_int(123, 32) E.constant_int(123, 64) E.constant_index(123) E.constant_function(fun) code = str(fun) self.assertIn("constant 1.230000e+00 : bf16", code) self.assertIn("constant 1.230470e+00 : f16", code) self.assertIn("constant 1.230000e+00 : f32", code) self.assertIn("constant 1.230000e+00 : f64", code) self.assertIn("constant 1 : i1", code) self.assertIn("constant 123 : i8", code) self.assertIn("constant 123 : i16", code) self.assertIn("constant 123 : i32", code) self.assertIn("constant 123 : index", code) self.assertIn("constant @constants : () -> ()", code)
def testIndexedValue(self): memrefType = self.module.make_memref_type(self.f32Type, [10, 42]) with self.module.function_context("indexed", [memrefType], [memrefType]) as fun: A = E.IndexedValue(fun.arg(0)) cst = E.constant_float(1., self.f32Type) with E.LoopNestContext( [E.constant_index(0), E.constant_index(0)], [E.constant_index(10), E.constant_index(42)], [1, 1]) as (i, j): A.store([i, j], A.load([i, j]) + cst) E.ret([fun.arg(0)]) code = str(fun) self.assertIn('"affine.for"()', code) self.assertIn( "{lower_bound: () -> (0), step: 1 : index, upper_bound: () -> (10)}", code) self.assertIn('"affine.for"()', code) self.assertIn( "{lower_bound: () -> (0), step: 1 : index, upper_bound: () -> (42)}", code) self.assertIn("%0 = load %arg0[%i0, %i1] : memref<10x42xf32>", code) self.assertIn("%1 = addf %0, %cst : f32", code) self.assertIn("store %1, %arg0[%i0, %i1] : memref<10x42xf32>", code)
def testCallOp(self): self.setUp() callee = self.module.declare_function("sqrtf", [self.f32Type], [self.f32Type]) with self.module.function_context("call", [self.f32Type], []) as fun: funCst = E.constant_function(callee) funCst([fun.arg(0)]) + E.constant_float(42., self.f32Type) printWithCurrentFunctionName(str(self.module))
def testCallOp(self): callee = self.module.declare_function("sqrtf", [self.f32Type], [self.f32Type]) with self.module.function_context("call", [self.f32Type], []) as fun: funCst = E.constant_function(callee) funCst([fun.arg(0)]) + E.constant_float(42., self.f32Type) code = str(self.module) self.assertIn("func @sqrtf(f32) -> f32", code) self.assertIn("%f = constant @sqrtf : (f32) -> f32", code) self.assertIn("%0 = call_indirect %f(%arg0) : (f32) -> f32", code)
def testIndexedValue(self): self.setUp() memrefType = self.module.make_memref_type(self.f32Type, [10, 42]) with self.module.function_context("indexed", [memrefType], [memrefType]) as fun: A = E.IndexedValue(fun.arg(0)) cst = E.constant_float(1., self.f32Type) with E.LoopNestContext( [E.constant_index(0), E.constant_index(0)], [E.constant_index(10), E.constant_index(42)], [1, 1]) as (i, j): A.store([i, j], A.load([i, j]) + cst) E.ret([fun.arg(0)]) printWithCurrentFunctionName(str(fun))
def testConstants(self): self.setUp() with self.module.function_context("constants", [], []) as fun: E.constant_float(1.23, self.module.make_scalar_type("bf16")) E.constant_float(1.23, self.module.make_scalar_type("f16")) E.constant_float(1.23, self.module.make_scalar_type("f32")) E.constant_float(1.23, self.module.make_scalar_type("f64")) E.constant_int(1, 1) E.constant_int(123, 8) E.constant_int(123, 16) E.constant_int(123, 32) E.constant_int(123, 64) E.constant_index(123) E.constant_function(fun) printWithCurrentFunctionName(str(fun))