11 #include <raft/core/handle.hpp>
13 #include <rmm/device_scalar.hpp>
14 #include <rmm/device_uvector.hpp>
33 template <
typename math_t>
58 available_sorted(0, stream),
59 cub_storage(0, stream),
61 f_idx_sorted(0, stream),
65 ws_idx_sorted(0, stream),
66 ws_idx_selected(0, stream),
67 ws_idx_save(0, stream),
68 ws_priority(0, stream),
69 ws_priority_sorted(0, stream),
70 d_num_selected(stream)
72 n_train = (svmType ==
EPSILON_SVR) ? n_rows * 2 : n_rows;
86 if (n_ws == 0 || n_ws > n_train) { n_ws = n_train; }
87 n_ws = std::min(1024, n_ws);
89 CUML_LOG_DEBUG(
"Creating working set with %d elements", n_ws);
128 math_t* f, math_t* alpha, math_t* y,
const math_t* C,
int n_already_selected = 0);
148 void Select(math_t* f, math_t* alpha, math_t* y,
const math_t* C)
150 if (n_ws >= n_train) {
170 raft::copy(idx.data(), ws_idx_save.data() + 2 * nc, 2 * nc, stream);
178 raft::copy(ws_idx_save.data(), idx.data(), n_ws, stream);
202 const raft::handle_t& handle;
205 bool firstcall =
true;
215 rmm::device_uvector<int> f_idx;
216 rmm::device_uvector<int> f_idx_sorted;
218 rmm::device_uvector<int> idx_tmp;
219 rmm::device_uvector<math_t> f_sorted;
221 rmm::device_uvector<bool> available;
222 rmm::device_uvector<bool> available_sorted;
225 rmm::device_uvector<int> idx;
226 rmm::device_uvector<int> ws_idx_sorted;
227 rmm::device_uvector<int> ws_idx_selected;
228 rmm::device_uvector<int> ws_idx_save;
230 rmm::device_uvector<int> ws_priority;
231 rmm::device_uvector<int> ws_priority_sorted;
233 rmm::device_scalar<int> d_num_selected;
234 std::size_t cub_bytes = 0;
235 rmm::device_uvector<char> cub_storage;
237 void AllocateBuffers();
253 int GatherAvailable(
int n_already_selected,
int n_needed,
bool copy_front);
267 template <
typename select_op>
268 int SelectPrevWs(
int n_needed,
int n_already_selected, select_op op);
Definition: workingset.h:34
int GetSize()
Definition: workingset.h:94
void Select(math_t *f, math_t *alpha, math_t *y, const math_t *C)
Select working set indices.
Definition: workingset.h:148
WorkingSet(const raft::handle_t &handle, cudaStream_t stream, int n_rows=0, int n_ws=0, SvmType svmType=C_SVC)
Manage a working set.
Definition: workingset.h:48
bool FIFO_strategy
Workspace selection strategy, note that only FIFO is tested so far
Definition: workingset.h:37
void SetSize(int n_train, int n_ws=0)
Set the size of the working set and allocate buffers accordingly.
Definition: workingset.h:84
~WorkingSet()
Definition: workingset.h:76
void SimpleSelect(math_t *f, math_t *alpha, math_t *y, const math_t *C, int n_already_selected=0)
Select new elements for a working set.
int * GetIndices()
Return a device pointer to the the working set indices.
Definition: workingset.h:101
int PrioritySelect(math_t *alpha, const math_t *C, int nc)
Select elements from the previous working set based on their priority.
SvmType
Definition: svm_parameter.h:12
@ EPSILON_SVR
Definition: svm_parameter.h:12
@ C_SVC
Definition: svm_parameter.h:12
Definition: dbscan.hpp:18
const_agnostic_same_t< T, U > copy(buffer< T > &dst, buffer< U > const &src, typename buffer< T >::index_type dst_offset, typename buffer< U >::index_type src_offset, typename buffer< T >::index_type size, cuda_stream stream)
Definition: buffer.hpp:316