cumlHandle.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2019-2023, 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 <cuml/cuml_api.h>
20 
21 #include <raft/core/handle.hpp>
22 
23 namespace ML {
24 
29 class HandleMap {
30  public:
38  std::pair<cumlHandle_t, cumlError_t> createAndInsertHandle(cudaStream_t stream);
39 
47  std::pair<raft::handle_t*, cumlError_t> lookupHandlePointer(cumlHandle_t handle) const;
48 
57 
58  static const cumlHandle_t INVALID_HANDLE = -1;
59 
60  private:
61  std::unordered_map<cumlHandle_t, raft::handle_t*> _handleMap;
62  mutable std::mutex _mapMutex;
63  cumlHandle_t _nextHandle;
64 };
65 
67 extern HandleMap handleMap;
68 
69 } // end namespace ML
Definition: cumlHandle.hpp:29
static const cumlHandle_t INVALID_HANDLE
sentinel value for invalid ID
Definition: cumlHandle.hpp:58
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:67
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:31
cumlError_t removeAndDestroyHandle(cumlHandle_t handle)
Remove handle from map and destroy associated handle object.
Definition: cumlHandle.cpp:78
int cumlHandle_t
Definition: cuml_api.h:37
cumlError_t
Definition: cuml_api.h:39
Definition: dbscan.hpp:30
HandleMap handleMap
Static handle map instance (see cumlHandle.cpp)
Definition: cumlHandle.cpp:29