Skip to content

Commit

Permalink
Enable testing for the other half of the heterogeneous managed memory…
Browse files Browse the repository at this point in the history
… tests on MSVC. (#1729)

* Make tests work when full path is specified to lit.

* Remove unused alias and simplify managed memory launcher path.

* Make rest of managed memory tests work in MSVC.

* [pre-commit.ci] auto code formatting

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
wmaxey and pre-commit-ci[bot] committed May 13, 2024
1 parent d1a0401 commit e9fe09b
Showing 1 changed file with 39 additions and 51 deletions.
90 changes: 39 additions & 51 deletions libcudacxx/test/libcudacxx/heterogeneous/helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -313,9 +313,6 @@ void host_validate(T& object)
}
}

template <typename T, typename... Args>
using creator = T& (*) (Args...);

template <typename T>
using performer = void (*)(T&);

Expand Down Expand Up @@ -430,7 +427,7 @@ void validate_device_dynamic(tester_list<Testers...> testers, Args... args)
permute_tests(test_harness, initial_launcher_list{});
}

#if __cplusplus >= 201402L
#if _CCCL_STD_VER >= 2014
template <typename T>
struct manual_object
{
Expand Down Expand Up @@ -474,16 +471,15 @@ template <typename T>
__managed__ manual_object<T> managed_variable{};
#endif

template <typename T, std::size_t N, typename... Args>
void validate_in_managed_memory_helper(
creator<T, Args...> creator_, performer<T> destroyer, initializer_validator<T> (&performers)[N], Args... args)
template <typename Creator, typename Destroyer, typename Validator, std::size_t N>
void validate_in_managed_memory_helper(const Creator& creator, const Destroyer& destroyer, Validator (&performers)[N])
{
T& object = creator_(args...);
auto object = creator();

for (auto&& performer : performers)
{
performer.initializer(object);
performer.validator(object);
performer.initializer(*object);
performer.validator(*object);
}

HETEROGENEOUS_SAFE_CALL(cudaGetLastError());
Expand All @@ -501,74 +497,66 @@ void validate_managed(tester_list<Testers...>, Args... args)

initializer_validator<T> device_init_host_check[] = {{device_initialize<Testers>, host_validate<Testers>}...};

creator<T, Args...> host_constructor = [](Args... args) -> T& {
auto host_constructor = [args...]() -> T* {
void* pointer;
HETEROGENEOUS_SAFE_CALL(cudaMallocManaged(&pointer, sizeof(T)));
return *new (pointer) T(args...);
return new (pointer) T(args...);
};

creator<T, Args...> device_constructor = [](Args... args) -> T& {
auto device_constructor = [args...]() -> T* {
void* pointer;
HETEROGENEOUS_SAFE_CALL(cudaMallocManaged(&pointer, sizeof(T)));
return *device_construct<T>(pointer, args...);
return device_construct<T>(pointer, args...);
};

performer<T> host_destructor = [](T& object) {
object.~T();
HETEROGENEOUS_SAFE_CALL(cudaFree(&object));
auto host_destructor = [](T* object) {
object->~T();
HETEROGENEOUS_SAFE_CALL(cudaFree(object));
};

performer<T> device_destructor = [](T& object) {
device_destroy(&object);
HETEROGENEOUS_SAFE_CALL(cudaFree(&object));
auto device_destructor = [](T* object) {
device_destroy(object);
HETEROGENEOUS_SAFE_CALL(cudaFree(object));
};

validate_in_managed_memory_helper<T>(host_constructor, host_destructor, host_init_device_check, args...);
validate_in_managed_memory_helper<T>(host_constructor, host_destructor, device_init_host_check, args...);
validate_in_managed_memory_helper<T>(host_constructor, device_destructor, host_init_device_check, args...);
validate_in_managed_memory_helper<T>(host_constructor, device_destructor, device_init_host_check, args...);
validate_in_managed_memory_helper<T>(device_constructor, host_destructor, host_init_device_check, args...);
validate_in_managed_memory_helper<T>(device_constructor, host_destructor, device_init_host_check, args...);
validate_in_managed_memory_helper<T>(device_constructor, device_destructor, host_init_device_check, args...);
validate_in_managed_memory_helper<T>(device_constructor, device_destructor, device_init_host_check, args...);
validate_in_managed_memory_helper(host_constructor, host_destructor, host_init_device_check);
validate_in_managed_memory_helper(host_constructor, host_destructor, device_init_host_check);
validate_in_managed_memory_helper(host_constructor, device_destructor, host_init_device_check);
validate_in_managed_memory_helper(host_constructor, device_destructor, device_init_host_check);
validate_in_managed_memory_helper(device_constructor, host_destructor, host_init_device_check);
validate_in_managed_memory_helper(device_constructor, host_destructor, device_init_host_check);
validate_in_managed_memory_helper(device_constructor, device_destructor, host_init_device_check);
validate_in_managed_memory_helper(device_constructor, device_destructor, device_init_host_check);

#if __cplusplus >= 201402L && !defined(__clang__)
#if _CCCL_STD_VER >= 2014 && !defined(__clang__)
// The managed variable template part of this test is disabled under clang, pending nvbug 2790305 being fixed.

creator<T, Args...> host_variable_constructor = [](Args... args) -> T& {
auto host_variable_constructor = [args...]() -> T* {
managed_variable<T>.construct(args...);
return managed_variable<T>.get();
return &managed_variable<T>.get();
};

creator<T, Args...> device_variable_constructor = [](Args... args) -> T& {
auto device_variable_constructor = [args...]() -> T* {
managed_variable<T>.device_construct(args...);
return managed_variable<T>.get();
return &managed_variable<T>.get();
};

performer<T> host_variable_destructor = [](T&) {
auto host_variable_destructor = [](T*) {
managed_variable<T>.destroy();
};

performer<T> device_variable_destructor = [](T&) {
auto device_variable_destructor = [](T*) {
managed_variable<T>.device_destroy();
};

validate_in_managed_memory_helper<T>(
host_variable_constructor, host_variable_destructor, host_init_device_check, args...);
validate_in_managed_memory_helper<T>(
host_variable_constructor, host_variable_destructor, device_init_host_check, args...);
validate_in_managed_memory_helper<T>(
host_variable_constructor, device_variable_destructor, host_init_device_check, args...);
validate_in_managed_memory_helper<T>(
host_variable_constructor, device_variable_destructor, device_init_host_check, args...);
validate_in_managed_memory_helper<T>(
device_variable_constructor, host_variable_destructor, host_init_device_check, args...);
validate_in_managed_memory_helper<T>(
device_variable_constructor, host_variable_destructor, device_init_host_check, args...);
validate_in_managed_memory_helper<T>(
device_variable_constructor, device_variable_destructor, host_init_device_check, args...);
validate_in_managed_memory_helper<T>(
device_variable_constructor, device_variable_destructor, device_init_host_check, args...);
validate_in_managed_memory_helper(host_variable_constructor, host_variable_destructor, host_init_device_check);
validate_in_managed_memory_helper(host_variable_constructor, host_variable_destructor, device_init_host_check);
validate_in_managed_memory_helper(host_variable_constructor, device_variable_destructor, host_init_device_check);
validate_in_managed_memory_helper(host_variable_constructor, device_variable_destructor, device_init_host_check);
validate_in_managed_memory_helper(device_variable_constructor, host_variable_destructor, host_init_device_check);
validate_in_managed_memory_helper(device_variable_constructor, host_variable_destructor, device_init_host_check);
validate_in_managed_memory_helper(device_variable_constructor, device_variable_destructor, host_init_device_check);
validate_in_managed_memory_helper(device_variable_constructor, device_variable_destructor, device_init_host_check);
#endif
}

Expand Down

0 comments on commit e9fe09b

Please sign in to comment.