RMM  23.12
RAPIDS Memory Manager
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>
22 
23 #include <rmm/detail/thrust_namespace.h>
24 #include <thrust/execution_policy.h>
25 
26 namespace rmm {
27 
28 using par_t = decltype(thrust::cuda::par(*(new rmm::mr::thrust_allocator<char>())));
29 using deleter_t = std::function<void(par_t*)>;
30 using exec_policy_t = std::unique_ptr<par_t, deleter_t>;
31 
41 [[deprecated("Use new exec_policy in rmm/exec_policy.hpp")]] inline exec_policy_t exec_policy(
42  cudaStream_t stream = nullptr)
43 {
44  // NOLINTNEXTLINE(cppcoreguidelines-owning-memory)
45  auto* alloc = new rmm::mr::thrust_allocator<char>(cuda_stream_view{stream});
46  auto deleter = [alloc](par_t* pointer) {
47  delete alloc; // NOLINT(cppcoreguidelines-owning-memory)
48  delete pointer; // NOLINT(cppcoreguidelines-owning-memory)
49  };
50 
51  exec_policy_t policy{new par_t(*alloc), deleter};
52  return policy;
53 }
54 
55 } // namespace rmm
An allocator compatible with Thrust containers and algorithms using a device_memory_resource for memo...
Definition: thrust_allocator_adaptor.hpp:46