Skip to content

Commit a7a3221

Browse files
committed
Reduce large allocation tests to 80% on WSL
1 parent 06f7ff3 commit a7a3221

3 files changed

Lines changed: 33 additions & 12 deletions

File tree

cpp/tests/mr/arena_mr_tests.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
*/
55

66
#include "../byte_literals.hpp"
7+
#include "test_utils.hpp"
78

89
#include <rmm/aligned.hpp>
910
#include <rmm/cuda_device.hpp>
@@ -483,11 +484,12 @@ TEST_F(ArenaTest, SizeSmallerThanSuperblockSize) // NOLINT
483484
EXPECT_THROW(construct_small(), rmm::logic_error);
484485
}
485486

486-
TEST_F(ArenaTest, AllocateNinetyPercent) // NOLINT
487+
TEST_F(ArenaTest, AllocateMostOfFreeMemory) // NOLINT
487488
{
488-
EXPECT_NO_THROW([]() { // NOLINT(cppcoreguidelines-avoid-goto)
489-
auto const ninety_percent = rmm::percent_of_free_device_memory(90);
490-
arena_mr mr(rmm::mr::get_current_device_resource_ref(), ninety_percent);
489+
auto const percent = is_wsl() ? 80 : 90;
490+
EXPECT_NO_THROW([percent]() { // NOLINT(cppcoreguidelines-avoid-goto)
491+
auto const pool_size = rmm::percent_of_free_device_memory(percent);
492+
arena_mr mr(rmm::mr::get_current_device_resource_ref(), pool_size);
491493
}());
492494
}
493495

cpp/tests/mr/pool_mr_tests.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
* SPDX-License-Identifier: Apache-2.0
44
*/
55

6+
#include "test_utils.hpp"
7+
68
#include <rmm/cuda_device.hpp>
79
#include <rmm/detail/error.hpp>
810
#include <rmm/device_buffer.hpp>
@@ -45,15 +47,14 @@ TEST(PoolTest, ThrowMaxLessThanInitial)
4547
EXPECT_THROW(max_less_than_initial(), rmm::logic_error);
4648
}
4749

48-
TEST(PoolTest, AllocateNinetyPercent)
50+
TEST(PoolTest, AllocateMostOfFreeMemory)
4951
{
50-
auto allocate_ninety = []() {
51-
auto const [free, total] = rmm::available_device_memory();
52-
(void)total;
53-
auto const ninety_percent_pool = rmm::percent_of_free_device_memory(90);
54-
pool_mr mr{rmm::mr::get_current_device_resource_ref(), ninety_percent_pool};
52+
auto const percent = is_wsl() ? 80 : 90;
53+
auto allocate = [percent]() {
54+
auto const pool_size = rmm::percent_of_free_device_memory(percent);
55+
pool_mr mr{rmm::mr::get_current_device_resource_ref(), pool_size};
5556
};
56-
EXPECT_NO_THROW(allocate_ninety());
57+
EXPECT_NO_THROW(allocate());
5758
}
5859

5960
TEST(PoolTest, TwoLargeBuffers)

cpp/tests/mr/test_utils.hpp

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* SPDX-FileCopyrightText: Copyright (c) 2024-2025, NVIDIA CORPORATION.
2+
* SPDX-FileCopyrightText: Copyright (c) 2024-2026, NVIDIA CORPORATION.
33
* SPDX-License-Identifier: Apache-2.0
44
*/
55

@@ -10,8 +10,26 @@
1010

1111
#include <cuda_runtime_api.h>
1212

13+
#include <fstream>
14+
#include <string>
15+
1316
namespace rmm::test {
1417

18+
/**
19+
* @brief Returns true if running under Windows Subsystem for Linux (WSL).
20+
*/
21+
inline bool is_wsl()
22+
{
23+
std::ifstream proc_version("/proc/version");
24+
if (proc_version.is_open()) {
25+
std::string line;
26+
std::getline(proc_version, line);
27+
return line.find("microsoft") != std::string::npos ||
28+
line.find("Microsoft") != std::string::npos;
29+
}
30+
return false;
31+
}
32+
1533
/**
1634
* @brief Returns if a pointer points to a device memory or managed memory
1735
* allocation.

0 commit comments

Comments
 (0)