Skip to content

Commit

Permalink
[CODEGEN][METAL] Fix ramp codegen (#14330)
Browse files Browse the repository at this point in the history
Fix ramp node codegen for the metal backend.
The default C codegen can cause problem in
vector indices assignment.

Confirmed on apple M2.
  • Loading branch information
tqchen authored Mar 19, 2023
1 parent 2ff41c6 commit a5ed21d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/target/source/codegen_metal.cc
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,17 @@ void CodeGenMetal::VisitExpr_(const BroadcastNode* op, std::ostream& os) { // N
os << ')';
}

void CodeGenMetal::VisitExpr_(const RampNode* op, std::ostream& os) { // NOLINT(*)
PrintType(op->dtype, os);
os << "(";
for (int i = 0; i < op->lanes; ++i) {
if (i != 0) os << ", ";
os << "(" << PrintExpr(op->base) << ")"
<< "+(" << PrintExpr(op->stride) << "*" << i << ")";
}
os << ')';
}

void CodeGenMetal::VisitExpr_(const CallNode* op, std::ostream& os) { // NOLINT(*)
if (op->op.same_as(builtin::reinterpret())) {
// generate as_type<TYPE>(ARG)
Expand Down
1 change: 1 addition & 0 deletions src/target/source/codegen_metal.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class CodeGenMetal final : public CodeGenC {
void PrintVecElemStore(const std::string& vec, DataType t, int i, const std::string& value) final;
// overload visitor
void VisitExpr_(const BroadcastNode* op, std::ostream& os) final; // NOLINT(*)
void VisitExpr_(const RampNode* op, std::ostream& os) final; // NOLINT(*)
void VisitExpr_(const CallNode* op, std::ostream& os) final; // NOLINT(*)
void VisitExpr_(const FloatImmNode* op, std::ostream& os) final;
// reuse parent's function.
Expand Down

0 comments on commit a5ed21d

Please sign in to comment.