@@ -50,37 +50,6 @@ def log(*args):
50
50
}
51
51
"""
52
52
53
- matmul_boiler = """
54
- func.func @main() -> f32 attributes {llvm.emit_c_interface} {
55
- %v0 = arith.constant 0.0 : f32
56
- %v1 = arith.constant -1 : i8
57
- %v2 = arith.constant 2.0 : f32
58
-
59
- %A = memref.alloc() : memref<4x16xi8>
60
- %B = memref.alloc() : memref<16x8xf32>
61
- %C0 = memref.alloc() : memref<4x8xf32>
62
- %C1 = memref.alloc() : memref<4x8xf32>
63
- linalg.fill ins(%v1 : i8) outs(%A : memref<4x16xi8>)
64
- linalg.fill ins(%v2 : f32) outs(%B : memref<16x8xf32>)
65
- linalg.fill ins(%v0 : f32) outs(%C0 : memref<4x8xf32>)
66
- linalg.fill ins(%v0 : f32) outs(%C1 : memref<4x8xf32>)
67
-
68
- call @matmul_signed_on_buffers(%A, %B, %C0) :
69
- (memref<4x16xi8>, memref<16x8xf32>, memref<4x8xf32>) -> ()
70
- call @matmul_unsigned_on_buffers(%A, %B, %C1) :
71
- (memref<4x16xi8>, memref<16x8xf32>, memref<4x8xf32>) -> ()
72
-
73
- %c0 = arith.constant 0 : index
74
- %res0 = memref.load %C0[%c0, %c0] : memref<4x8xf32>
75
- %res1 = memref.load %C1[%c0, %c0] : memref<4x8xf32>
76
-
77
- %0 = arith.addf %res0, %res1 : f32
78
-
79
- // TODO: FFI-based solution to allow testing and printing with python code.
80
- return %0 : f32
81
- }
82
- """
83
-
84
53
fill_boiler = """
85
54
func.func @main() -> i32 attributes {llvm.emit_c_interface} {
86
55
%O0 = memref.alloc() : memref<i32>
@@ -296,90 +265,6 @@ def elemwise_log_mul_on_buffers(lhs, rhs, out):
296
265
test_elemwise_generic ()
297
266
298
267
299
- def test_matmul_builtin ():
300
- with Context () as ctx , Location .unknown ():
301
- module = Module .create ()
302
- f32 = F32Type .get ()
303
- i8 = IntegerType .get_signless (8 )
304
- with InsertionPoint (module .body ):
305
-
306
- @func .FuncOp .from_py_func (
307
- MemRefType .get ((4 , 16 ), i8 ),
308
- MemRefType .get ((16 , 8 ), f32 ),
309
- MemRefType .get ((4 , 8 ), f32 ),
310
- )
311
- def matmul_signed_on_buffers (lhs , rhs , out ):
312
- linalg .matmul (lhs , rhs , outs = [out ])
313
-
314
- @func .FuncOp .from_py_func (
315
- MemRefType .get ((4 , 16 ), i8 ),
316
- MemRefType .get ((16 , 8 ), f32 ),
317
- MemRefType .get ((4 , 8 ), f32 ),
318
- )
319
- def matmul_unsigned_on_buffers (lhs , rhs , out ):
320
- linalg .matmul (lhs , rhs , outs = [out ], cast = TypeFn .cast_unsigned )
321
-
322
- execution_engine = ExecutionEngine (transform (module , matmul_boiler ))
323
-
324
- # TODO: FFI-based solution to allow testing and printing with python code.
325
- # Prepare arguments: one result f32.
326
- # Arguments must be passed as pointers.
327
- c_float_p = ctypes .c_float * 1
328
- res = c_float_p (- 1.0 )
329
- execution_engine .invoke ("main" , res )
330
-
331
- log ("RESULT: " , res [0 ])
332
- # matmul_signed_on_buffers: -1 * 2.0 * 16 = -32
333
- # matmul_unsigned_on_buffers: (2^8-1) * 2.0 * 16 = 8160
334
- # CHECK: RESULT: 8128
335
-
336
-
337
- test_matmul_builtin ()
338
-
339
-
340
- def test_matmul_generic ():
341
- with Context () as ctx , Location .unknown ():
342
- module = Module .create ()
343
- f32 = F32Type .get ()
344
- i8 = IntegerType .get_signless (8 )
345
- with InsertionPoint (module .body ):
346
-
347
- @func .FuncOp .from_py_func (
348
- MemRefType .get ((4 , 16 ), i8 ),
349
- MemRefType .get ((16 , 8 ), f32 ),
350
- MemRefType .get ((4 , 8 ), f32 ),
351
- )
352
- def matmul_signed_on_buffers (lhs , rhs , out ):
353
- linalg .matmul (lhs , rhs , outs = [out ], emit_generic = True )
354
-
355
- @func .FuncOp .from_py_func (
356
- MemRefType .get ((4 , 16 ), i8 ),
357
- MemRefType .get ((16 , 8 ), f32 ),
358
- MemRefType .get ((4 , 8 ), f32 ),
359
- )
360
- def matmul_unsigned_on_buffers (lhs , rhs , out ):
361
- linalg .matmul (
362
- lhs , rhs , outs = [out ], cast = TypeFn .cast_unsigned , emit_generic = True
363
- )
364
-
365
- execution_engine = ExecutionEngine (transform (module , matmul_boiler ))
366
-
367
- # TODO: FFI-based solution to allow testing and printing with python code.
368
- # Prepare arguments: one result f32.
369
- # Arguments must be passed as pointers.
370
- c_float_p = ctypes .c_float * 1
371
- res = c_float_p (- 1.0 )
372
- execution_engine .invoke ("main" , res )
373
-
374
- log ("RESULT: " , res [0 ])
375
- # matmul_signed_on_buffers = -1 * 2.0 * 16 = -32
376
- # matmul_unsigned_on_buffers = (2^8-1) * 2.0 * 16 = 8160
377
- # CHECK: RESULT: 8128
378
-
379
-
380
- test_matmul_generic ()
381
-
382
-
383
268
def test_fill_builtin ():
384
269
with Context () as ctx , Location .unknown ():
385
270
module = Module .create ()
0 commit comments