masahi commented on code in PR #11658: URL: https://github.com/apache/tvm/pull/11658#discussion_r894043800
########## src/tir/transforms/inject_ptx_async_copy.cc: ########## @@ -0,0 +1,144 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +/*! + * \brief Replace copy from global to shared with async copy + * \file inject_ptx_async_copy.cc + */ +#include <tvm/tir/analysis.h> +#include <tvm/tir/builtin.h> +#include <tvm/tir/expr.h> +#include <tvm/tir/stmt_functor.h> +#include <tvm/tir/transform.h> + +#include "../ir/buffer_common.h" +#include "storage_access.h" +#include "tvm/tir/stmt.h" + +namespace tvm { +namespace tir { + +class PTXAsyncCopyInjector : public StmtMutator { + public: + Stmt VisitStmt_(const AttrStmtNode* attr) { + if (attr->attr_key == tir::attr::async_scope) { + in_async = true; + auto body = this->VisitStmt(attr->body); + in_async = false; + return body; + } + return StmtMutator::VisitStmt_(attr); + } + + Stmt VisitStmt_(const BufferStoreNode* store) { + if (in_async && (store->buffer.scope() == "shared" || store->buffer.scope() == "shared.dyn")) { + if (auto* load = store->value.as<BufferLoadNode>()) { Review Comment: Interesting. Indeed, currently it only supports the fixed pattern `shared[...] = global[...]`. But I think we can add more patterns as they come up, as long as we can extract the src pointer and the offset. -- 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]
