Loading [MathJax]/extensions/tex2jax.js
cuML C++ API  23.12
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
ml_cuda_utils.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2019-2022, 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 <cuda_runtime.h>
20 #include <raft/util/cudart_utils.hpp>
21 
22 namespace ML {
23 
24 inline int get_device(const void* ptr)
25 {
26  cudaPointerAttributes att;
27  cudaPointerGetAttributes(&att, ptr);
28  return att.device;
29 }
30 
31 inline cudaMemoryType memory_type(const void* p)
32 {
33  cudaPointerAttributes att;
34  cudaError_t err = cudaPointerGetAttributes(&att, p);
35  ASSERT(err == cudaSuccess || err == cudaErrorInvalidValue, "%s", cudaGetErrorString(err));
36 
37  if (err == cudaErrorInvalidValue) {
38  // Make sure the current thread error status has been reset
39  err = cudaGetLastError();
40  ASSERT(err == cudaErrorInvalidValue, "%s", cudaGetErrorString(err));
41  }
42  return att.type;
43 }
44 
45 inline bool is_device_or_managed_type(const void* p)
46 {
47  cudaMemoryType p_memory_type = memory_type(p);
48  return p_memory_type == cudaMemoryTypeDevice || p_memory_type == cudaMemoryTypeManaged;
49 }
50 
51 } // namespace ML
Definition: dbscan.hpp:27
bool is_device_or_managed_type(const void *p)
Definition: ml_cuda_utils.h:45
cudaMemoryType memory_type(const void *p)
Definition: ml_cuda_utils.h:31
int get_device(const void *ptr)
Definition: ml_cuda_utils.h:24