Skip to content

Commit 59ee2dd

Browse files
committed
fixed python tests
1 parent cc10325 commit 59ee2dd

File tree

2 files changed

+0
-157
lines changed

2 files changed

+0
-157
lines changed

mlir/test/python/dialects/linalg/ops.py

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -49,42 +49,6 @@ def fill_buffer(out):
4949
print(module)
5050

5151

52-
# CHECK-LABEL: TEST: testNamedStructuredOpCustomForm
53-
@run
54-
def testNamedStructuredOpCustomForm():
55-
with Context() as ctx, Location.unknown():
56-
module = Module.create()
57-
f32 = F32Type.get()
58-
with InsertionPoint(module.body):
59-
60-
@func.FuncOp.from_py_func(
61-
RankedTensorType.get((4, 8), f32), RankedTensorType.get((4, 8), f32)
62-
)
63-
def named_form(lhs, rhs):
64-
init_result = tensor.EmptyOp([4, 8], f32)
65-
# Check for the named form with custom format
66-
# CHECK: linalg.elemwise_unary
67-
# CHECK-SAME: cast = #linalg.type_fn<cast_signed>
68-
# CHECK-SAME: fun = #linalg.unary_fn<exp>
69-
# CHECK-SAME: ins(%{{.*}} : tensor<4x8xf32>) outs(%{{.*}} : tensor<4x8xf32>)
70-
unary_result = linalg.elemwise_unary(lhs, outs=[init_result.result])
71-
# CHECK: linalg.elemwise_binary
72-
# CHECK-SAME: cast = #linalg.type_fn<cast_unsigned>
73-
# CHECK-SAME: fun = #linalg.binary_fn<mul>
74-
# CHECK-SAME: ins(%{{.*}}, %{{.*}} : tensor<4x8xf32>, tensor<4x8xf32>) outs(%{{.*}} : tensor<4x8xf32>)
75-
# CHECK: return
76-
binary_result = linalg.elemwise_binary(
77-
lhs,
78-
rhs,
79-
outs=[init_result.result],
80-
fun=BinaryFn.mul,
81-
cast=TypeFn.cast_unsigned,
82-
)
83-
return unary_result, binary_result
84-
85-
print(module)
86-
87-
8852
# CHECK-LABEL: TEST: testIdentityRegionOps
8953
@run
9054
def testIdentityRegionOps():

mlir/test/python/integration/dialects/linalg/opsrun.py

Lines changed: 0 additions & 121 deletions
Original file line numberDiff line numberDiff line change
@@ -19,37 +19,6 @@ def log(*args):
1919
sys.stderr.flush()
2020

2121

22-
elemwise_boiler = """
23-
func.func @main() -> f32 attributes {llvm.emit_c_interface} {
24-
%v0 = arith.constant 0.0 : f32
25-
%v1 = arith.constant 1.0 : f32
26-
%v2 = arith.constant 2.0 : f32
27-
28-
%lhs = memref.alloc() : memref<f32>
29-
%rhs = memref.alloc() : memref<4x8xf32>
30-
%O0 = memref.alloc() : memref<4x8xf32>
31-
%O1 = memref.alloc() : memref<4x8xf32>
32-
linalg.fill ins(%v1 : f32) outs(%lhs : memref<f32>)
33-
linalg.fill ins(%v2 : f32) outs(%rhs : memref<4x8xf32>)
34-
linalg.fill ins(%v0 : f32) outs(%O0 : memref<4x8xf32>)
35-
linalg.fill ins(%v0 : f32) outs(%O1 : memref<4x8xf32>)
36-
37-
call @elemwise_exp_add_on_buffers(%lhs, %rhs, %O0) :
38-
(memref<f32>, memref<4x8xf32>, memref<4x8xf32>) -> ()
39-
call @elemwise_log_mul_on_buffers(%lhs, %rhs, %O1) :
40-
(memref<f32>, memref<4x8xf32>, memref<4x8xf32>) -> ()
41-
42-
%c0 = arith.constant 0 : index
43-
%res0 = memref.load %O0[%c0, %c0] : memref<4x8xf32>
44-
%res1 = memref.load %O1[%c0, %c0] : memref<4x8xf32>
45-
46-
%0 = arith.addf %res0, %res1 : f32
47-
48-
// TODO: FFI-based solution to allow testing and printing with python code.
49-
return %0 : f32
50-
}
51-
"""
52-
5322
fill_boiler = """
5423
func.func @main() -> i32 attributes {llvm.emit_c_interface} {
5524
%O0 = memref.alloc() : memref<i32>
@@ -177,96 +146,6 @@ def transform(module, boilerplate):
177146
return mod
178147

179148

180-
def test_elemwise_builtin():
181-
with Context() as ctx, Location.unknown():
182-
module = Module.create()
183-
f32 = F32Type.get()
184-
i8 = IntegerType.get_signless(8)
185-
with InsertionPoint(module.body):
186-
187-
@func.FuncOp.from_py_func(
188-
MemRefType.get((), f32),
189-
MemRefType.get((4, 8), f32),
190-
MemRefType.get((4, 8), f32),
191-
)
192-
def elemwise_exp_add_on_buffers(lhs, rhs, out):
193-
linalg.elemwise_unary(lhs, outs=[out])
194-
linalg.elemwise_binary(out, rhs, outs=[out])
195-
196-
@func.FuncOp.from_py_func(
197-
MemRefType.get((), f32),
198-
MemRefType.get((4, 8), f32),
199-
MemRefType.get((4, 8), f32),
200-
)
201-
def elemwise_log_mul_on_buffers(lhs, rhs, out):
202-
linalg.elemwise_unary(lhs, outs=[out], fun=UnaryFn.log)
203-
linalg.elemwise_binary(out, rhs, outs=[out], fun=BinaryFn.mul)
204-
205-
execution_engine = ExecutionEngine(transform(module, elemwise_boiler))
206-
207-
# TODO: FFI-based solution to allow testing and printing with python code.
208-
# Prepare arguments: one result f32.
209-
# Arguments must be passed as pointers.
210-
c_float_p = ctypes.c_float * 1
211-
res = c_float_p(-1.0)
212-
execution_engine.invoke("main", res)
213-
214-
log("RESULT: ", res[0])
215-
# elemwise_exp_add_on_buffers: exp(1.0) + 2.0 = 4.71828182846
216-
# elemwise_log_mul_on_buffers: log(1.0) * 2.0 = 0.0
217-
# CHECK: RESULT: 4.71828
218-
219-
220-
test_elemwise_builtin()
221-
222-
223-
def test_elemwise_generic():
224-
with Context() as ctx, Location.unknown():
225-
module = Module.create()
226-
f32 = F32Type.get()
227-
i8 = IntegerType.get_signless(8)
228-
with InsertionPoint(module.body):
229-
230-
@func.FuncOp.from_py_func(
231-
MemRefType.get((), f32),
232-
MemRefType.get((4, 8), f32),
233-
MemRefType.get((4, 8), f32),
234-
)
235-
def elemwise_exp_add_on_buffers(lhs, rhs, out):
236-
linalg.elemwise_unary(lhs, outs=[out], emit_generic=True)
237-
linalg.elemwise_binary(out, rhs, outs=[out], emit_generic=True)
238-
239-
@func.FuncOp.from_py_func(
240-
MemRefType.get((), f32),
241-
MemRefType.get((4, 8), f32),
242-
MemRefType.get((4, 8), f32),
243-
)
244-
def elemwise_log_mul_on_buffers(lhs, rhs, out):
245-
linalg.elemwise_unary(
246-
lhs, outs=[out], fun=UnaryFn.log, emit_generic=True
247-
)
248-
linalg.elemwise_binary(
249-
out, rhs, outs=[out], fun=BinaryFn.mul, emit_generic=True
250-
)
251-
252-
execution_engine = ExecutionEngine(transform(module, elemwise_boiler))
253-
254-
# TODO: FFI-based solution to allow testing and printing with python code.
255-
# Prepare arguments: one result f32.
256-
# Arguments must be passed as pointers.
257-
c_float_p = ctypes.c_float * 1
258-
res = c_float_p(-1.0)
259-
execution_engine.invoke("main", res)
260-
261-
log("RESULT: ", res[0])
262-
# elemwise_exp_add_on_buffers: exp(1.0) + 2.0 = 4.71828182846
263-
# elemwise_log_mul_on_buffers: log(1.0) * 2.0 = 0.0
264-
# CHECK: RESULT: 4.71828
265-
266-
267-
test_elemwise_generic()
268-
269-
270149
def test_fill_builtin():
271150
with Context() as ctx, Location.unknown():
272151
module = Module.create()

0 commit comments

Comments
 (0)