comaniac commented on a change in pull request #8678:
URL: https://github.com/apache/tvm/pull/8678#discussion_r684513225
##########
File path: src/target/source/codegen_cuda.cc
##########
@@ -46,6 +48,39 @@ void CodeGenCUDA::Init(bool output_ssa) {
void CodeGenCUDA::PrintFuncPrefix() { stream << "extern \"C\" __global__
void"; }
+class ThreadIdxExtractor : public tir::StmtVisitor {
+ private:
+ void VisitStmt_(const AttrStmtNode* op) final {
+ if (op->attr_key == tir::attr::thread_extent) {
+ IterVar iv = Downcast<IterVar>(op->node);
+ if (iv->var->name_hint == "threadIdx.x") {
+ threadIdx_x_ext = op->value;
+ }
+ if (iv->var->name_hint == "threadIdx.y") {
+ threadIdx_y_ext = op->value;
+ }
+ if (iv->var->name_hint == "threadIdx.z") {
+ threadIdx_z_ext = op->value;
+ }
+ }
+ StmtVisitor::VisitStmt_(op);
+ }
+
+ public:
+ PrimExpr threadIdx_x_ext = Integer(1), threadIdx_y_ext = Integer(1),
threadIdx_z_ext = Integer(1);
+};
+
+void CodeGenCUDA::PrintExtraAttrs(const PrimFunc& f) {
+ ThreadIdxExtractor extractor;
+ extractor(f->body);
+ arith::Analyzer analyzer;
+ PrimExpr threadIdx_ext = analyzer.Simplify(extractor.threadIdx_x_ext *
extractor.threadIdx_y_ext *
+ extractor.threadIdx_z_ext);
+ if (const IntImmNode* const threadIdx_ext_int =
threadIdx_ext.as<IntImmNode>()) {
+ stream << " __launch_bounds__(" << threadIdx_ext_int->value << ")";
Review comment:
Oh I see. Then we don't need a new line here.
--
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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]