Skip to content

Commit

Permalink
ensure ops affected by Reset after increase_exec
Browse files Browse the repository at this point in the history
  • Loading branch information
yhmtsai committed Jul 9, 2021
1 parent f707dc9 commit ad7746d
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 34 deletions.
2 changes: 1 addition & 1 deletion cuda/test/base/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
ginkgo_create_cuda_test(array)
ginkgo_create_cuda_test(cuda_executor)
ginkgo_create_cuda_test(cuda_executor_reset)
ginkgo_create_test(cuda_executor_reset)
if(GINKGO_HAVE_HWLOC)
find_package(NUMA REQUIRED)
ginkgo_create_cuda_test(cuda_executor_topology NUMA::NUMA)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ namespace {
#define GTEST_ASSERT_NO_EXIT(statement) \
ASSERT_EXIT({ {statement} exit(0); }, ::testing::ExitedWithCode(0), "")


TEST(DeviceReset, HipCuda)
{
GTEST_ASSERT_NO_EXIT({
Expand All @@ -65,30 +66,18 @@ TEST(DeviceReset, CudaHip)
}


template <typename Executor>
void func()
{
auto ref = gko::ReferenceExecutor::create();
auto exec = Executor::create(0, ref, true);
auto exec = gko::CudaExecutor::create(0, ref, true);
}


TEST(DeviceReset, CudaCuda)
{
GTEST_ASSERT_NO_EXIT({
std::thread t1(func<gko::CudaExecutor>);
std::thread t2(func<gko::CudaExecutor>);
t1.join();
t2.join();
});
}


TEST(DeviceReset, HipHip)
{
GTEST_ASSERT_NO_EXIT({
std::thread t1(func<gko::CudaExecutor>);
std::thread t2(func<gko::CudaExecutor>);
std::thread t1(func);
std::thread t2(func);
t1.join();
t2.join();
});
Expand Down
2 changes: 1 addition & 1 deletion hip/test/base/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
ginkgo_create_hip_test(hip_executor)
ginkgo_create_hip_test(hip_executor_reset)
ginkgo_create_test(hip_executor_reset)
if(GINKGO_HAVE_HWLOC)
find_package(NUMA REQUIRED)
ginkgo_create_hip_test(hip_executor_topology NUMA::NUMA)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ namespace {
#define GTEST_ASSERT_NO_EXIT(statement) \
ASSERT_EXIT({ {statement} exit(0); }, ::testing::ExitedWithCode(0), "")


TEST(DeviceReset, HipCuda)
{
GTEST_ASSERT_NO_EXIT({
Expand All @@ -65,30 +66,18 @@ TEST(DeviceReset, CudaHip)
}


template <typename Executor>
void func()
{
auto ref = gko::ReferenceExecutor::create();
auto exec = Executor::create(0, ref, true);
}


TEST(DeviceReset, CudaCuda)
{
GTEST_ASSERT_NO_EXIT({
std::thread t1(func<gko::CudaExecutor>);
std::thread t2(func<gko::CudaExecutor>);
t1.join();
t2.join();
});
auto exec = gko::HipExecutor::create(0, ref, true);
}


TEST(DeviceReset, HipHip)
{
GTEST_ASSERT_NO_EXIT({
std::thread t1(func<gko::CudaExecutor>);
std::thread t2(func<gko::CudaExecutor>);
std::thread t1(func);
std::thread t2(func);
t1.join();
t2.join();
});
Expand Down
12 changes: 10 additions & 2 deletions include/ginkgo/core/base/executor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1424,9 +1424,13 @@ class CudaExecutor : public detail::ExecutorBase<CudaExecutor>,
MachineTopology::get_instance()->bind_to_pus(
this->get_closest_pus());
}
// it only gets attribute from device, so it should not be affected by
// DeviceReset.
this->set_gpu_property();
this->init_handles();
// increase the number of executor before any operations may be affected
// by DeviceReset.
increase_num_execs(this->get_exec_info().device_id);
this->init_handles();
}

void *raw_alloc(size_type size) const override;
Expand Down Expand Up @@ -1647,9 +1651,13 @@ class HipExecutor : public detail::ExecutorBase<HipExecutor>,
MachineTopology::get_instance()->bind_to_pus(
this->get_closest_pus());
}
// it only gets attribute from device, so it should not be affected by
// DeviceReset.
this->set_gpu_property();
this->init_handles();
// increase the number of executor before any operations may be affected
// by DeviceReset.
increase_num_execs(this->get_exec_info().device_id);
this->init_handles();
}

void *raw_alloc(size_type size) const override;
Expand Down

0 comments on commit ad7746d

Please sign in to comment.