11/*
2- * Copyright (c) 2021, NVIDIA CORPORATION.
2+ * Copyright (c) 2021-2022 , NVIDIA CORPORATION.
33 *
44 * Licensed under the Apache License, Version 2.0 (the "License");
55 * you may not use this file except in compliance with the License.
@@ -173,6 +173,18 @@ class minor_properties_device_view_t {
173173 {
174174 }
175175
176+ std::optional<vertex_t const *> key_data () const
177+ {
178+ return key_first_ ? std::optional<vertex_t const *>{*key_first_} : std::nullopt ;
179+ }
180+
181+ std::optional<vertex_t > number_of_keys () const
182+ {
183+ return key_first_ ? std::optional<vertex_t >{static_cast <vertex_t >(
184+ thrust::distance (*key_first_, *key_last_))}
185+ : std::nullopt ;
186+ }
187+
176188 ValueIterator value_data () const { return value_first_; }
177189
178190 __device__ ValueIterator get_iter (vertex_t offset) const
@@ -199,7 +211,10 @@ class minor_properties_device_view_t {
199211template <typename vertex_t , typename T>
200212class major_properties_t {
201213 public:
202- major_properties_t () : buffer_(allocate_dataframe_buffer<T>(0 , rmm::cuda_stream_view{})) {}
214+ major_properties_t (raft::handle_t const & handle)
215+ : buffer_(allocate_dataframe_buffer<T>(size_t {0 }, handle.get_stream()))
216+ {
217+ }
203218
204219 major_properties_t (raft::handle_t const & handle, vertex_t buffer_size)
205220 : buffer_(allocate_dataframe_buffer<T>(buffer_size, handle.get_stream()))
@@ -227,6 +242,19 @@ class major_properties_t {
227242 {
228243 }
229244
245+ void clear (raft::handle_t const & handle)
246+ {
247+ key_first_ = std::nullopt ;
248+
249+ resize_dataframe_buffer (buffer_, size_t {0 }, handle.get_stream ());
250+ shrink_to_fit_dataframe_buffer (buffer_, handle.get_stream ());
251+
252+ matrix_partition_key_offsets_ = std::nullopt ;
253+ matrix_partition_major_firsts_ = std::nullopt ;
254+
255+ matrix_partition_major_value_start_offsets_ = std::nullopt ;
256+ }
257+
230258 void fill (T value, rmm::cuda_stream_view stream)
231259 {
232260 thrust::fill (
@@ -279,7 +307,7 @@ class major_properties_t {
279307 private:
280308 std::optional<vertex_t const *> key_first_{std::nullopt };
281309
282- decltype (allocate_dataframe_buffer<T>(0 , rmm::cuda_stream_view{})) buffer_;
310+ decltype (allocate_dataframe_buffer<T>(size_t { 0 } , rmm::cuda_stream_view{})) buffer_;
283311
284312 std::optional<std::vector<vertex_t >> matrix_partition_key_offsets_{std::nullopt };
285313 std::optional<std::vector<vertex_t >> matrix_partition_major_firsts_{std::nullopt };
@@ -290,7 +318,10 @@ class major_properties_t {
290318template <typename vertex_t , typename T>
291319class minor_properties_t {
292320 public:
293- minor_properties_t () : buffer_(allocate_dataframe_buffer<T>(0 , rmm::cuda_stream_view{})) {}
321+ minor_properties_t (raft::handle_t const & handle)
322+ : buffer_(allocate_dataframe_buffer<T>(size_t {0 }, handle.get_stream()))
323+ {
324+ }
294325
295326 minor_properties_t (raft::handle_t const & handle, vertex_t buffer_size)
296327 : buffer_(allocate_dataframe_buffer<T>(buffer_size, handle.get_stream()))
@@ -309,6 +340,16 @@ class minor_properties_t {
309340 {
310341 }
311342
343+ void clear (raft::handle_t const & handle)
344+ {
345+ key_first_ = std::nullopt ;
346+ key_last_ = std::nullopt ;
347+ minor_first_ = std::nullopt ;
348+
349+ resize_dataframe_buffer (buffer_, size_t {0 }, handle.get_stream ());
350+ shrink_to_fit_dataframe_buffer (buffer_, handle.get_stream ());
351+ }
352+
312353 void fill (T value, rmm::cuda_stream_view stream)
313354 {
314355 thrust::fill (
@@ -346,7 +387,7 @@ class minor_properties_t {
346387 std::optional<vertex_t const *> key_last_{std::nullopt };
347388 std::optional<vertex_t > minor_first_{std::nullopt };
348389
349- decltype (allocate_dataframe_buffer<T>(0 , rmm::cuda_stream_view{})) buffer_;
390+ decltype (allocate_dataframe_buffer<T>(size_t { 0 } , rmm::cuda_stream_view{})) buffer_;
350391};
351392
352393template <typename Iterator,
@@ -380,9 +421,10 @@ class row_properties_t {
380421
381422 static_assert (is_arithmetic_or_thrust_tuple_of_arithmetic<T>::value);
382423
383- row_properties_t () = default ;
424+ row_properties_t (raft:: handle_t const & handle) : properties_(handle) {}
384425
385426 row_properties_t (raft::handle_t const & handle, GraphViewType const & graph_view)
427+ : properties_(handle)
386428 {
387429 using vertex_t = typename GraphViewType::vertex_type;
388430
@@ -433,6 +475,8 @@ class row_properties_t {
433475 }
434476 }
435477
478+ void clear (raft::handle_t const & handle) { properties_.clear (handle); }
479+
436480 void fill (T value, rmm::cuda_stream_view stream) { properties_.fill (value, stream); }
437481
438482 auto key_first () { return properties_.key_first (); }
@@ -447,7 +491,7 @@ class row_properties_t {
447491 std::conditional_t <GraphViewType::is_adj_matrix_transposed,
448492 detail::minor_properties_t <typename GraphViewType::vertex_type, T>,
449493 detail::major_properties_t <typename GraphViewType::vertex_type, T>>
450- properties_{} ;
494+ properties_;
451495};
452496
453497template <typename GraphViewType, typename T>
@@ -457,9 +501,10 @@ class col_properties_t {
457501
458502 static_assert (is_arithmetic_or_thrust_tuple_of_arithmetic<T>::value);
459503
460- col_properties_t () = default ;
504+ col_properties_t (raft:: handle_t const & handle) : properties_(handle) {}
461505
462506 col_properties_t (raft::handle_t const & handle, GraphViewType const & graph_view)
507+ : properties_(handle)
463508 {
464509 using vertex_t = typename GraphViewType::vertex_type;
465510
@@ -510,6 +555,8 @@ class col_properties_t {
510555 }
511556 }
512557
558+ void clear (raft::handle_t const & handle) { properties_.clear (handle); }
559+
513560 void fill (T value, rmm::cuda_stream_view stream) { properties_.fill (value, stream); }
514561
515562 auto key_first () { return properties_.key_first (); }
@@ -524,7 +571,7 @@ class col_properties_t {
524571 std::conditional_t <GraphViewType::is_adj_matrix_transposed,
525572 detail::major_properties_t <typename GraphViewType::vertex_type, T>,
526573 detail::minor_properties_t <typename GraphViewType::vertex_type, T>>
527- properties_{} ;
574+ properties_;
528575};
529576
530577template <typename vertex_t >
0 commit comments