thrust_rmm_allocator.h
1 /*
2  * Copyright (c) 2018-2021, NVIDIA CORPORATION.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #pragma once
18 
19 #include <rmm/cuda_stream_view.hpp>
20 #include <rmm/device_vector.hpp>
21 #include <rmm/mr/device/thrust_allocator_adaptor.hpp>
22 
23 #include <thrust/execution_policy.h>
24 
25 namespace rmm {
26 
27 using par_t = decltype(thrust::cuda::par(*(new rmm::mr::thrust_allocator<char>())));
28 using deleter_t = std::function<void(par_t*)>;
29 using exec_policy_t = std::unique_ptr<par_t, deleter_t>;
30 
40 [[deprecated("Use new exec_policy in rmm/exec_policy.hpp")]] inline exec_policy_t exec_policy(
41  cudaStream_t stream = nullptr)
42 {
43  // NOLINTNEXTLINE(cppcoreguidelines-owning-memory)
44  auto* alloc = new rmm::mr::thrust_allocator<char>(cuda_stream_view{stream});
45  auto deleter = [alloc](par_t* pointer) {
46  delete alloc; // NOLINT(cppcoreguidelines-owning-memory)
47  delete pointer; // NOLINT(cppcoreguidelines-owning-memory)
48  };
49 
50  exec_policy_t policy{new par_t(*alloc), deleter};
51  return policy;
52 }
53 
54 } // namespace rmm
rmm::mr::thrust_allocator
An allocator compatible with Thrust containers and algorithms using a device_memory_resource for memo...
Definition: thrust_allocator_adaptor.hpp:37