2023-01-02 14:28:25 +00:00
|
|
|
const std = @import("std");
|
|
|
|
|
const mlir = @import("mlir");
|
|
|
|
|
|
|
|
|
|
const namespace = "math";
|
|
|
|
|
|
|
|
|
|
fn unary_fn(comptime op_name: [:0]const u8) type {
|
|
|
|
|
return struct {
|
|
|
|
|
pub fn call(ctx: mlir.Context, value: mlir.Value, location: mlir.Location) mlir.Operation {
|
|
|
|
|
return mlir.Operation.make(ctx, namespace ++ "." ++ op_name, .{
|
|
|
|
|
.operands = &.{value},
|
2024-08-26 14:19:00 +00:00
|
|
|
.results = &.{value.getType()},
|
2023-01-02 14:28:25 +00:00
|
|
|
.location = location,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn binary_fn(comptime op_name: [:0]const u8) type {
|
|
|
|
|
return struct {
|
|
|
|
|
pub fn call(ctx: mlir.Context, lhs: mlir.Value, rhs: mlir.Value, location: mlir.Location) mlir.Operation {
|
|
|
|
|
return mlir.Operation.make(ctx, namespace ++ "." ++ op_name, .{
|
|
|
|
|
.operands = &.{ lhs, rhs },
|
|
|
|
|
.results = &.{},
|
|
|
|
|
.location = location,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub const ipowi = binary_fn("ipowi").call;
|
|
|
|
|
pub const fpowi = binary_fn("fpowi").call;
|
|
|
|
|
pub const tanh = unary_fn("tanh").call;
|
|
|
|
|
pub const sqrt = unary_fn("sqrt").call;
|
|
|
|
|
pub const exp = unary_fn("exp").call;
|
2024-08-26 14:19:00 +00:00
|
|
|
pub const exp2 = unary_fn("exp2").call;
|
2023-01-02 14:28:25 +00:00
|
|
|
pub const log = unary_fn("log").call;
|