Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support using THRUST_WRAPPED_NAMESPACE #1077

34 changes: 34 additions & 0 deletions include/rmm/detail/thrust_namespace.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Copyright (c) 2022, NVIDIA CORPORATION.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#pragma once

#include <thrust/detail/config.h> // namespace macros

#ifdef THRUST_WRAPPED_NAMESPACE

// Ensure the namespace exist before we import it
// so that this include can occur before thrust includes
namespace THRUST_WRAPPED_NAMESPACE {
namespace thrust {
}
} // namespace THRUST_WRAPPED_NAMESPACE

namespace rmm {
using namespace THRUST_WRAPPED_NAMESPACE;
}

#endif
1 change: 1 addition & 0 deletions include/rmm/device_vector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

#include <rmm/mr/device/thrust_allocator_adaptor.hpp>

#include <rmm/detail/thrust_namespace.h>
robertmaynard marked this conversation as resolved.
Show resolved Hide resolved
#include <thrust/device_vector.h>

namespace rmm {
Expand Down
1 change: 1 addition & 0 deletions include/rmm/exec_policy.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <rmm/cuda_stream_view.hpp>
#include <rmm/mr/device/thrust_allocator_adaptor.hpp>

#include <rmm/detail/thrust_namespace.h>
#include <thrust/system/cuda/execution_policy.h>
#include <thrust/version.h>

Expand Down
1 change: 1 addition & 0 deletions include/rmm/mr/device/cuda_async_memory_resource.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include <rmm/mr/device/cuda_async_view_memory_resource.hpp>
#include <rmm/mr/device/device_memory_resource.hpp>

#include <rmm/detail/thrust_namespace.h>
#include <thrust/optional.h>

#include <cuda_runtime_api.h>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include <rmm/detail/error.hpp>
#include <rmm/mr/device/device_memory_resource.hpp>

#include <rmm/detail/thrust_namespace.h>
#include <thrust/optional.h>

#include <cuda_runtime_api.h>
Expand Down
1 change: 1 addition & 0 deletions include/rmm/mr/device/fixed_size_memory_resource.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <rmm/mr/device/detail/fixed_size_free_list.hpp>
#include <rmm/mr/device/detail/stream_ordered_memory_resource.hpp>

#include <rmm/detail/thrust_namespace.h>
#include <thrust/iterator/counting_iterator.h>
#include <thrust/iterator/transform_iterator.h>

Expand Down
1 change: 1 addition & 0 deletions include/rmm/mr/device/pool_memory_resource.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <rmm/mr/device/detail/stream_ordered_memory_resource.hpp>
#include <rmm/mr/device/device_memory_resource.hpp>

#include <rmm/detail/thrust_namespace.h>
#include <thrust/iterator/counting_iterator.h>
#include <thrust/iterator/transform_iterator.h>
#include <thrust/optional.h>
Expand Down
1 change: 1 addition & 0 deletions include/rmm/mr/device/thrust_allocator_adaptor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <rmm/mr/device/device_memory_resource.hpp>
#include <rmm/mr/device/per_device_resource.hpp>

#include <rmm/detail/thrust_namespace.h>
#include <thrust/device_malloc_allocator.h>
#include <thrust/device_ptr.h>
#include <thrust/memory.h>
Expand Down
1 change: 1 addition & 0 deletions include/rmm/thrust_rmm_allocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include <rmm/device_vector.hpp>
#include <rmm/mr/device/thrust_allocator_adaptor.hpp>

#include <rmm/detail/thrust_namespace.h>
#include <thrust/execution_policy.h>

namespace rmm {
Expand Down
5 changes: 5 additions & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,11 @@ function(ConfigureTest TEST_NAME)
string(REGEX REPLACE "_TEST$" "_PTDS_TEST" PTDS_TEST_NAME "${TEST_NAME}")
ConfigureTestInternal("${PTDS_TEST_NAME}" ${ARGN})
target_compile_definitions("${PTDS_TEST_NAME}" PUBLIC CUDA_API_PER_THREAD_DEFAULT_STREAM)

# Test with custom thrust namespace
string(REGEX REPLACE "_TEST$" "_NAMESPACE_TEST" NS_TEST_NAME "${TEST_NAME}")
ConfigureTestInternal("${NS_TEST_NAME}" ${ARGN})
target_compile_definitions("${NS_TEST_NAME}" PUBLIC THRUST_WRAPPED_NAMESPACE=rmm_thrust)
endfunction()

# test sources
Expand Down
4 changes: 4 additions & 0 deletions tests/device_buffer_tests.cu
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@

#include <thrust/equal.h>
#include <thrust/sequence.h>
namespace testing {
namespace thrust = THRUST_NS_QUALIFIER;
}
using namespace testing;

#include <cuda_runtime_api.h>

Expand Down