I’ve modified some topi to used vectorized. And met a weird problem.
When compile the generated cuda code, there is a compilation error:
RuntimeError: Compilation error:
/tmp/tmpa6yn_fvk/my_kernel.cu(502): error: expected a ";"
The related cuda code is as following:
int _125 = (0x000000ff << 0) & (((signed char*)placeholder1)[_62.x] << 0))|((0x000000ff << 8) & (((signed char*)placeholder1)[_62.y] << 8))|((0x000000ff << 16) & (((signed char*)placeholder1)[_62.z] << 16))|((0x000000ff << 24) & (((signed char*)placeholder1)[_62.w] << 24);
You can see bracket mismatch from the code, but the TVM code that generate this cuda code is in codegen_cuda.cc:
void CodeGenCUDA::PrintVecElemLoadExpr(
... ...
os << "((0x000000ff << " << i * 8 << ") & (" << value << " << " << i * 8 << "))";
... ...
It seems correct, and the function that call above function is
void CodeGenC::VisitExpr_(const LoadNode* op, std::ostream& os) { // NOLINT(*)
... ...
PrintVecElemLoadExpr(op->dtype, i, value_temp.str(), svalue_expr);
std::cout << svalue_expr << std::endl; // Output string is correct
I print svalue_expr, it is correct , the bracket are correct.
But when output the cuda code, the first bracket and latest bracket are missing. More strange thing is, when I add a blank character before the first bracker like:
os << " ((0x000000ff << " << i * 8 << ") & (" << value << " << " << i * 8 << "))";
The cuda code is correct, and the new inserted blank character is also generated in the cuda code.
Anyone can help to explain it ? Thanks in advance.