From c3075acf207b33325ae6eb04dccd56721f14ded7 Mon Sep 17 00:00:00 2001 From: "Yuhsiang M. Tsai" Date: Wed, 13 Nov 2019 10:45:27 +0100 Subject: [PATCH] fix strategy only with hip --- include/ginkgo/core/matrix/csr.hpp | 102 +++++++++++++++++++---------- 1 file changed, 68 insertions(+), 34 deletions(-) diff --git a/include/ginkgo/core/matrix/csr.hpp b/include/ginkgo/core/matrix/csr.hpp index d6529d1d702..a1f815ffb3e 100644 --- a/include/ginkgo/core/matrix/csr.hpp +++ b/include/ginkgo/core/matrix/csr.hpp @@ -228,26 +228,31 @@ class Csr : public EnableLinOp>, int64_t clac_size(const int64_t nnz) { - int multiple = 8; - if (nnz >= 2000000) { - multiple = 128; - } else if (nnz >= 200000) { - multiple = 32; - } + if (warp_size_ > 0) { + int multiple = 8; + if (nnz >= 2000000) { + multiple = 128; + } else if (nnz >= 200000) { + multiple = 32; + } #if GINKGO_HIP_PLATFORM_HCC - if (!cuda_strategy_) { - multiple = 8; - if (nnz >= 10000000) { - multiple = 64; - } else if (nnz >= 1000000) { - multiple = 16; + if (!cuda_strategy_) { + multiple = 8; + if (nnz >= 10000000) { + multiple = 64; + } else if (nnz >= 1000000) { + multiple = 16; + } } - } #endif // GINKGO_HIP_PLATFORM_HCC - auto nwarps = nwarps_ * multiple; - return min(ceildiv(nnz, warp_size_), static_cast(nwarps)); + auto nwarps = nwarps_ * multiple; + return min(ceildiv(nnz, warp_size_), + static_cast(nwarps)); + } else { + return 0; + } } private: @@ -328,33 +333,62 @@ class Csr : public EnableLinOp>, void convert_to(Csr *result) const override { + auto executor = result->get_executor(); + bool same_executor = this->get_executor() == executor; + auto strategy = this->get_strategy(); EnableLinOp::convert_to(result); - if (this->get_executor() != result->get_executor() && - result->get_strategy()->get_name() == "load_balance") { - if (auto exec = std::dynamic_pointer_cast( - result->get_executor())) { - result->set_strategy(std::make_shared(exec)); - } else if (auto exec = - std::dynamic_pointer_cast( - result->get_executor())) { - result->set_strategy(std::make_shared(exec)); + if (!same_executor) { + // When strategy is load_balance or automatical, rebuild the + // strategy according to executor's property. + if (std::dynamic_pointer_cast(strategy)) { + if (auto exec = std::dynamic_pointer_cast( + executor)) { + result->set_strategy(std::make_shared(exec)); + } else if (auto exec = + std::dynamic_pointer_cast( + executor)) { + result->set_strategy(std::make_shared(exec)); + } + } else if (std::dynamic_pointer_cast(strategy)) { + if (auto exec = std::dynamic_pointer_cast( + executor)) { + result->set_strategy(std::make_shared(exec)); + } else if (auto exec = + std::dynamic_pointer_cast( + executor)) { + result->set_strategy(std::make_shared(exec)); + } } } } void move_to(Csr *result) override { - bool same_executor = this->get_executor() == result->get_executor(); + auto executor = result->get_executor(); + bool same_executor = this->get_executor() == executor; + auto strategy = this->get_strategy(); EnableLinOp::move_to(result); - if (!same_executor && - result->get_strategy()->get_name() == "load_balance") { - if (auto exec = std::dynamic_pointer_cast( - result->get_executor())) { - result->set_strategy(std::make_shared(exec)); - } else if (auto exec = - std::dynamic_pointer_cast( - result->get_executor())) { - result->set_strategy(std::make_shared(exec)); + if (!same_executor) { + // When strategy is load_balance or automatical, rebuild the + // strategy according to executor's property. + if (std::dynamic_pointer_cast(strategy)) { + if (auto exec = std::dynamic_pointer_cast( + executor)) { + result->set_strategy(std::make_shared(exec)); + } else if (auto exec = + std::dynamic_pointer_cast( + executor)) { + result->set_strategy(std::make_shared(exec)); + } + } else if (std::dynamic_pointer_cast(strategy)) { + if (auto exec = std::dynamic_pointer_cast( + executor)) { + result->set_strategy(std::make_shared(exec)); + } else if (auto exec = + std::dynamic_pointer_cast( + executor)) { + result->set_strategy(std::make_shared(exec)); + } } } }