Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vectorize Ramp in OpenGLCompute backend #6372

Merged
merged 1 commit into from
Nov 3, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions src/CodeGen_OpenGLCompute_Dev.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -550,20 +550,24 @@ void CodeGen_OpenGLCompute_C::visit(const For *loop) {
}

void CodeGen_OpenGLCompute_C::visit(const Ramp *op) {
ostringstream rhs;
rhs << print_type(op->type) << "(";

if (op->lanes > 4) {
internal_error << "GLSL: ramp lanes " << op->lanes << " is not supported\n";
}

rhs << print_expr(op->base);

for (int i = 1; i < op->lanes; ++i) {
rhs << ", " << print_expr(Add::make(op->base, Mul::make(i, op->stride)));
ostringstream rhs;
// Print the sequence vec(0, 1, 2, ...).
rhs << print_type(op->type) << "(";
for (int i = 0; i < op->type.lanes(); i++) {
rhs << i;
if (i != op->type.lanes() - 1) {
rhs << ", ";
}
}

rhs << ")";

// Multiply by the stride and add the base.
rhs << " * " << print_expr(op->stride) << " + " << print_expr(op->base);

print_assignment(op->type, rhs.str());
}

Expand Down