text
stringlengths
0
2.2M
}
/******************************************************************************
The MIT License(MIT)
Embedded Template Library.
https://github.com/ETLCPP/etl
ERROR: type should be string, got "https://www.etlcpp.com\n"
Copyright(c) 2021 Bo Rydberg
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files(the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions :
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
******************************************************************************/
#include <etl/debug_count.h>
#include <torch/csrc/jit/codegen/cuda/ir_utils.h>
#include <torch/csrc/jit/codegen/cuda/iter_visitor.h>
#include <torch/csrc/jit/codegen/cuda/lower2device.h>
#include <torch/csrc/jit/codegen/cuda/root_domain_map.h>
#include <torch/csrc/jit/codegen/cuda/lower_trivial_broadcast.h>
namespace torch {
namespace jit {
namespace fuser {
namespace cuda {
void ConcretizedBroadcastDomains::build(Fusion* fusion) {
// Initialize the origin map with input broadcast domains
for (const auto fusion_input_tv :
ir_utils::filterByType<TensorView>(fusion->inputs())) {
for (auto root_id : fusion_input_tv->getRootDomain()) {
if (root_id->isBroadcast()) {
broadcast_origin_map_.emplace(
root_id, std::unordered_set<IterDomain*>({root_id}));
}
}
}
traverse(fusion);
}
bool ConcretizedBroadcastDomains::isConcretized(IterDomain* id) const {
auto it = concretized_domains_.find(id);
return it != concretized_domains_.end();
}
void ConcretizedBroadcastDomains::handle(BroadcastOp* bop) {
// Create a new entry for each of new broadcast domains
auto out = bop->out()->as<TensorView>();
for (const auto i : c10::irange(out->getRootDomain().size())) {
if (bop->getBroadcastDimFlags().at(i)) {
auto new_bcast_id = out->getRootDomain().at(i);
broadcast_origin_map_.emplace(
new_bcast_id, std::unordered_set<IterDomain*>({new_bcast_id}));
}
}
}
void ConcretizedBroadcastDomains::handle(Expr* expr) {
IterVisitor::handle(expr);
// Propagate broadcast origin info from producers to consumers
for (auto producer : ir_utils::filterByType<TensorView>(expr->inputs())) {
std::unordered_set<IterDomain*> producer_broadcasts;
// This assumes there's no merged broadcast axes between root and rfactor
// domains which is not possible at the moment. If this assumption is ever
// invalidated we would need to manaually propagate root IDs to rfactor IDs.
for (auto producer_id : producer->getMaybeRFactorDomain()) {
if (producer_id->isBroadcast()) {
producer_broadcasts.insert(producer_id);
}
}
if (producer_broadcasts.empty()) {
continue;
}
for (auto consumer : ir_utils::filterByType<TensorView>(expr->outputs())) {
auto p2c_map =
PairwiseRootDomainMap(producer, consumer)
.mapProducerToConsumer(
producer->domain(), consumer->domain(), producer_broadcasts);