Skip to content

Commit

Permalink
Remove duplicated memory_resource_tests (#1451)
Browse files Browse the repository at this point in the history
During the initial introduction of `async_resource_ref` we duplicated all tests that take a `device_memory_resource*`.

Now that we have already some experience with running it in production and are moving more of the interfaces to `async resource_ref` remove those duplicated tests.

closes #1450

Authors:
  - Michael Schellenberger Costa (https://github.com/miscco)

Approvers:
  - Mark Harris (https://github.com/harrism)
  - Bradley Dice (https://github.com/bdice)

URL: #1451
  • Loading branch information
miscco authored Feb 15, 2024
1 parent 32251ec commit ce3af2c
Show file tree
Hide file tree
Showing 9 changed files with 129 additions and 965 deletions.
7 changes: 0 additions & 7 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,6 @@ endfunction()

# test sources

# device mr tests
ConfigureTest(DEVICE_MR_TEST mr/device/mr_tests.cpp mr/device/mr_multithreaded_tests.cpp GPUS 1
PERCENT 90)

# device mr_ref tests
ConfigureTest(DEVICE_MR_REF_TEST mr/device/mr_ref_tests.cpp
mr/device/mr_ref_multithreaded_tests.cpp GPUS 1 PERCENT 100)
Expand Down Expand Up @@ -163,9 +159,6 @@ ConfigureTest(ALIGNED_TEST mr/device/aligned_mr_tests.cpp)
# limiting adaptor tests
ConfigureTest(LIMITING_TEST mr/device/limiting_mr_tests.cpp)

# host mr tests
ConfigureTest(HOST_MR_TEST mr/host/mr_tests.cpp)

# host mr_ref tests
ConfigureTest(HOST_MR_REF_TEST mr/host/mr_ref_tests.cpp)

Expand Down
286 changes: 0 additions & 286 deletions tests/mr/device/mr_multithreaded_tests.cpp

This file was deleted.

70 changes: 70 additions & 0 deletions tests/mr/device/mr_ref_multithreaded_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,76 @@ void spawn(Task task, Arguments&&... args)
spawn_n(4, task, std::forward<Arguments>(args)...);
}

TEST(DefaultTest, UseCurrentDeviceResource_mt) { spawn(test_get_current_device_resource); }

TEST(DefaultTest, CurrentDeviceResourceIsCUDA_mt)
{
spawn([]() {
EXPECT_NE(nullptr, rmm::mr::get_current_device_resource());
EXPECT_TRUE(rmm::mr::get_current_device_resource()->is_equal(rmm::mr::cuda_memory_resource{}));
});
}

TEST(DefaultTest, GetCurrentDeviceResource_mt)
{
spawn([]() {
rmm::mr::device_memory_resource* mr = rmm::mr::get_current_device_resource();
EXPECT_NE(nullptr, mr);
EXPECT_TRUE(mr->is_equal(rmm::mr::cuda_memory_resource{}));
});
}

TEST_P(mr_ref_test_mt, SetCurrentDeviceResource_mt)
{
// single thread changes default resource, then multiple threads use it

rmm::mr::device_memory_resource* old = rmm::mr::set_current_device_resource(this->mr.get());
EXPECT_NE(nullptr, old);

spawn([mr = this->mr.get()]() {
EXPECT_EQ(mr, rmm::mr::get_current_device_resource());
test_get_current_device_resource(); // test allocating with the new default resource
});

// setting default resource w/ nullptr should reset to initial
rmm::mr::set_current_device_resource(nullptr);
EXPECT_TRUE(old->is_equal(*rmm::mr::get_current_device_resource()));
}

TEST_P(mr_ref_test_mt, SetCurrentDeviceResourcePerThread_mt)
{
int num_devices{};
RMM_CUDA_TRY(cudaGetDeviceCount(&num_devices));

std::vector<std::thread> threads;
threads.reserve(num_devices);
for (int i = 0; i < num_devices; ++i) {
threads.emplace_back(std::thread{[mr = this->mr.get()](auto dev_id) {
RMM_CUDA_TRY(cudaSetDevice(dev_id));
rmm::mr::device_memory_resource* old =
rmm::mr::set_current_device_resource(mr);
EXPECT_NE(nullptr, old);
// initial resource for this device should be CUDA mr
EXPECT_TRUE(old->is_equal(rmm::mr::cuda_memory_resource{}));
// get_current_device_resource should equal the resource we
// just set
EXPECT_EQ(mr, rmm::mr::get_current_device_resource());
// Setting current dev resource to nullptr should reset to
// cuda MR and return the MR we previously set
old = rmm::mr::set_current_device_resource(nullptr);
EXPECT_NE(nullptr, old);
EXPECT_EQ(old, mr);
EXPECT_TRUE(rmm::mr::get_current_device_resource()->is_equal(
rmm::mr::cuda_memory_resource{}));
},
i});
}

for (auto& thread : threads) {
thread.join();
}
}

TEST_P(mr_ref_test_mt, Allocate) { spawn(test_various_allocations, this->ref); }

TEST_P(mr_ref_test_mt, AllocateDefaultStream)
Expand Down
Loading

0 comments on commit ce3af2c

Please sign in to comment.