vinx13 commented on a change in pull request #5101: [CodeGen][CUDA]
Vectorization for intrinsics
URL: https://github.com/apache/incubator-tvm/pull/5101#discussion_r395768184
##########
File path: src/target/source/codegen_cuda.cc
##########
@@ -418,6 +419,54 @@ void CodeGenCUDA::VisitExpr_(const CallNode *op,
std::ostream& os) {
this->PrintExpr(op->args[i * 2 + 1], os);
os << "]" << ((i < 3) ? ", ": ")");
}
+ } else if (op->call_type == CallNode::PureExtern && op->dtype.is_vector()) {
+ //
+ // Emit an unsupported vector call
+ //
+ // v = intrin_f((float4*)A[0], (float4*)B[0])
+ //
+ // as
+ //
+ // float4 __ret;
+ // {
+ // float4 __arg0 = ((float4*)A)[0];
+ // float4 __arg1 = ((float4*)B)[0];
+ // __ret.x = intrin_f(__arg0.x, __arg1.x);
+ // __ret.y = intrin_f(__arg0.y, __arg1.y);
+ // __ret.z = intrin_f(__arg0.z, __arg1.z);
+ // __ret.w = intrin_f(__arg0.w, __arg1.w);
+ // }
+ // v = __ret;
+ //
+ // Declare the result vector.
+ std::string sret = GetUniqueName("_");
+ this->PrintIndent();
+ this->PrintType(op->dtype, stream);
+ stream << ' ' << sret << ";\n";
+ {
+ EnterScopeRAII scope(this);
+
+ // Load arguments.
+ std::vector<std::string> sargs;
+ for (size_t i = 0; i < op->args.size(); ++i) {
+ std::string val = SSAGetID(PrintExpr(op->args[i]),
op->args[i].dtype());
+ sargs.push_back(std::move(val));
+ }
+
+ // Emit a scalar call for each lane.
+ for (int i = 0; i < op->dtype.lanes(); ++i) {
+ std::ostringstream scall;
+ scall << op->name << "(";
+ for (size_t j = 0; j < op->args.size(); ++j) {
+ if (j > 0)
+ scall << ',';
Review comment:
```suggestion
scall << ", ";
```
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services