Skip to content

Commit

Permalink
fix strategy only with hip
Browse files Browse the repository at this point in the history
  • Loading branch information
yhmtsai committed Nov 13, 2019
1 parent 867e8ff commit c3075ac
Showing 1 changed file with 68 additions and 34 deletions.
102 changes: 68 additions & 34 deletions include/ginkgo/core/matrix/csr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,26 +228,31 @@ class Csr : public EnableLinOp<Csr<ValueType, IndexType>>,

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<int64_t>(nwarps));
auto nwarps = nwarps_ * multiple;
return min(ceildiv(nnz, warp_size_),
static_cast<int64_t>(nwarps));
} else {
return 0;
}
}

private:
Expand Down Expand Up @@ -328,33 +333,62 @@ class Csr : public EnableLinOp<Csr<ValueType, IndexType>>,

void convert_to(Csr<ValueType, IndexType> *result) const override
{
auto executor = result->get_executor();
bool same_executor = this->get_executor() == executor;
auto strategy = this->get_strategy();
EnableLinOp<Csr>::convert_to(result);
if (this->get_executor() != result->get_executor() &&
result->get_strategy()->get_name() == "load_balance") {
if (auto exec = std::dynamic_pointer_cast<const HipExecutor>(
result->get_executor())) {
result->set_strategy(std::make_shared<load_balance>(exec));
} else if (auto exec =
std::dynamic_pointer_cast<const CudaExecutor>(
result->get_executor())) {
result->set_strategy(std::make_shared<load_balance>(exec));
if (!same_executor) {
// When strategy is load_balance or automatical, rebuild the
// strategy according to executor's property.
if (std::dynamic_pointer_cast<load_balance>(strategy)) {
if (auto exec = std::dynamic_pointer_cast<const HipExecutor>(
executor)) {
result->set_strategy(std::make_shared<load_balance>(exec));
} else if (auto exec =
std::dynamic_pointer_cast<const CudaExecutor>(
executor)) {
result->set_strategy(std::make_shared<load_balance>(exec));
}
} else if (std::dynamic_pointer_cast<automatical>(strategy)) {
if (auto exec = std::dynamic_pointer_cast<const HipExecutor>(
executor)) {
result->set_strategy(std::make_shared<automatical>(exec));
} else if (auto exec =
std::dynamic_pointer_cast<const CudaExecutor>(
executor)) {
result->set_strategy(std::make_shared<automatical>(exec));
}
}
}
}

void move_to(Csr<ValueType, IndexType> *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<Csr>::move_to(result);
if (!same_executor &&
result->get_strategy()->get_name() == "load_balance") {
if (auto exec = std::dynamic_pointer_cast<const HipExecutor>(
result->get_executor())) {
result->set_strategy(std::make_shared<load_balance>(exec));
} else if (auto exec =
std::dynamic_pointer_cast<const CudaExecutor>(
result->get_executor())) {
result->set_strategy(std::make_shared<load_balance>(exec));
if (!same_executor) {
// When strategy is load_balance or automatical, rebuild the
// strategy according to executor's property.
if (std::dynamic_pointer_cast<load_balance>(strategy)) {
if (auto exec = std::dynamic_pointer_cast<const HipExecutor>(
executor)) {
result->set_strategy(std::make_shared<load_balance>(exec));
} else if (auto exec =
std::dynamic_pointer_cast<const CudaExecutor>(
executor)) {
result->set_strategy(std::make_shared<load_balance>(exec));
}
} else if (std::dynamic_pointer_cast<automatical>(strategy)) {
if (auto exec = std::dynamic_pointer_cast<const HipExecutor>(
executor)) {
result->set_strategy(std::make_shared<automatical>(exec));
} else if (auto exec =
std::dynamic_pointer_cast<const CudaExecutor>(
executor)) {
result->set_strategy(std::make_shared<automatical>(exec));
}
}
}
}
Expand Down

0 comments on commit c3075ac

Please sign in to comment.