prefetch.hpp
1 /*
2  * Copyright (c) 2024, 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 
20 
21 #include <rmm/device_uvector.hpp>
22 
23 #include <map>
24 #include <shared_mutex>
25 #include <string>
26 #include <string_view>
27 
28 namespace CUDF_EXPORT cudf {
29 namespace experimental::prefetch {
30 
31 namespace detail {
32 
37  public:
38  prefetch_config& operator=(const prefetch_config&) = delete;
39  prefetch_config(const prefetch_config&) = delete;
40 
47 
56  bool get(std::string_view key);
65  void set(std::string_view key, bool value);
71  bool debug{false};
72 
73  private:
74  prefetch_config() = default; //< Private constructor to enforce singleton pattern
75  std::map<std::string, bool> config_values; //< Map of configuration keys to values
76  std::shared_mutex config_mtx; //< Mutex for thread-safe config access
77 };
78 
88 void prefetch(std::string_view key,
89  void const* ptr,
90  std::size_t size,
91  rmm::cuda_stream_view stream,
93 
109 cudaError_t prefetch_noexcept(
110  std::string_view key,
111  void const* ptr,
112  std::size_t size,
113  rmm::cuda_stream_view stream,
114  rmm::cuda_device_id device_id = rmm::get_current_cuda_device()) noexcept;
115 
127 template <typename T>
128 void prefetch(std::string_view key,
129  rmm::device_uvector<T> const& v,
130  rmm::cuda_stream_view stream,
131  rmm::cuda_device_id device_id = rmm::get_current_cuda_device())
132 {
133  if (v.is_empty()) { return; }
134  prefetch(key, v.data(), v.size(), stream, device_id);
135 }
136 
137 } // namespace detail
138 
144 void enable_prefetching(std::string_view key);
145 
151 void disable_prefetching(std::string_view key);
152 
160 void prefetch_debugging(bool enable);
161 
162 } // namespace experimental::prefetch
163 } // namespace CUDF_EXPORT cudf
A singleton class that manages the prefetching configuration.
Definition: prefetch.hpp:36
bool get(std::string_view key)
Get the value of a configuration key.
static prefetch_config & instance()
Get the singleton instance of the prefetching configuration.
void set(std::string_view key, bool value)
Set the value of a configuration key.
A non-owning, immutable view of device data that is a variable length char array representing a UTF-8...
Definition: string_view.hpp:44
cuda_device_id get_current_cuda_device()
void prefetch(void const *ptr, std::size_t size, rmm::cuda_device_id device, rmm::cuda_stream_view stream)
cuDF interfaces
Definition: host_udf.hpp:39