Skip to content

Commit

Permalink
Implement dot
Browse files Browse the repository at this point in the history
  • Loading branch information
wpmed92 committed Sep 19, 2024
1 parent 38534f6 commit 4afa5f8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/CodeGen/MLIRCodeGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ void MLIRCodeGen::initBuiltinFuncMap() {
{"cosh", [](mlir::MLIRContext &context, mlir::OpBuilder &builder, mlir::ValueRange operands) {
return builder.create<spirv::GLCoshOp>(builder.getUnknownLoc(), operands[0]);
}},
{"dot", [](mlir::MLIRContext &context, mlir::OpBuilder &builder, mlir::ValueRange operands) {
auto op0ElementType = operands[0].getType().dyn_cast<mlir::VectorType>().getElementType();
return builder.create<spirv::DotOp>(builder.getUnknownLoc(), op0ElementType, operands[0], operands[1]);
}},
{"exp", [](mlir::MLIRContext &context, mlir::OpBuilder &builder, mlir::ValueRange operands) {
return builder.create<spirv::GLExpOp>(builder.getUnknownLoc(), operands[0]);
}},
Expand Down
9 changes: 9 additions & 0 deletions test/CodeGen/functions_builtin.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,13 @@ void main() {

// CHECK: %34 = spirv.GL.SSign %33 : si32
b = sign(-1);

vec3 dotTestA = vec3(1.0, 0.0, 1.2);
dvec3 dotTestB = dvec3(0.1lf, 0.2lf, 0.3lf);

// CHECK: %41 = spirv.Dot %39, %40 : vector<3xf32> -> f32
float floatDotRes = dot(dotTestA, dotTestA);

// CHECK: %45 = spirv.Dot %43, %44 : vector<3xf64> -> f64
double doubleDotRes = dot(dotTestB, dotTestB);
}

0 comments on commit 4afa5f8

Please sign in to comment.