cumlHandle.hpp
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: Copyright (c) 2019-2023, NVIDIA CORPORATION.
3  * SPDX-License-Identifier: Apache-2.0
4  */
5 
6 #pragma once
7 
8 #include <cuml/cuml_api.h>
9 
10 #include <raft/core/handle.hpp>
11 
12 namespace ML {
13 
18 class HandleMap {
19  public:
27  std::pair<cumlHandle_t, cumlError_t> createAndInsertHandle(cudaStream_t stream);
28 
36  std::pair<raft::handle_t*, cumlError_t> lookupHandlePointer(cumlHandle_t handle) const;
37 
46 
47  static const cumlHandle_t INVALID_HANDLE = -1;
48 
49  private:
50  std::unordered_map<cumlHandle_t, raft::handle_t*> _handleMap;
51  mutable std::mutex _mapMutex;
52  cumlHandle_t _nextHandle;
53 };
54 
56 extern HandleMap handleMap;
57 
58 } // end namespace ML
Definition: cumlHandle.hpp:18
static const cumlHandle_t INVALID_HANDLE
sentinel value for invalid ID
Definition: cumlHandle.hpp:47
std::pair< raft::handle_t *, cumlError_t > lookupHandlePointer(cumlHandle_t handle) const
Lookup pointer to handle object for handle ID in map.
Definition: cumlHandle.cpp:56
std::pair< cumlHandle_t, cumlError_t > createAndInsertHandle(cudaStream_t stream)
Creates new handle object with associated handle ID and insert into map.
Definition: cumlHandle.cpp:20
cumlError_t removeAndDestroyHandle(cumlHandle_t handle)
Remove handle from map and destroy associated handle object.
Definition: cumlHandle.cpp:67
int cumlHandle_t
Definition: cuml_api.h:26
cumlError_t
Definition: cuml_api.h:28
Definition: dbscan.hpp:18
HandleMap handleMap
Static handle map instance (see cumlHandle.cpp)
Definition: cumlHandle.cpp:18