Skip to content

Commit de91e89

Browse files
committed
Forgot to add new bitmask.hpp and bitmask/bitmask_ops.hpp files.
1 parent d0284a3 commit de91e89

File tree

2 files changed

+145
-0
lines changed

2 files changed

+145
-0
lines changed

cpp/include/bitmask.hpp

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/*
2+
* Copyright (c) 2019, 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+
#ifndef BITMASK_HPP
18+
#define BITMASK_HPP
19+
20+
#include <cudf.h>
21+
#include <types.hpp>
22+
23+
/**
24+
* @brief Counts the number of valid bits for the specified number of rows
25+
* in a validity bitmask.
26+
*
27+
* If the bitmask is null, returns a count equal to the number of rows.
28+
*
29+
* @param[in] masks The validity bitmask buffer in device memory
30+
* @param[in] num_rows The number of bits to count
31+
* @param[out] count The number of valid bits in the buffer from [0, num_rows)
32+
*
33+
* @returns GDF_SUCCESS upon successful completion
34+
*
35+
*/
36+
gdf_error gdf_count_nonzero_mask(gdf_valid_type const* masks,
37+
gdf_size_type num_rows, gdf_size_type* count);
38+
39+
/** ---------------------------------------------------------------------------*
40+
* @brief Concatenate the validity bitmasks of multiple columns
41+
*
42+
* Accounts for the differences between lengths of columns and their bitmasks
43+
* (e.g. because gdf_valid_type is larger than one bit).
44+
*
45+
* @param[out] output_mask The concatenated mask
46+
* @param[in] output_column_length The total length (in data elements) of the
47+
* concatenated column
48+
* @param[in] masks_to_concat The array of device pointers to validity bitmasks
49+
* for the columns to concatenate
50+
* @param[in] column_lengths An array of lengths of the columns to concatenate
51+
* @param[in] num_columns The number of columns to concatenate
52+
* @return gdf_error GDF_SUCCESS or GDF_CUDA_ERROR if there is a runtime CUDA
53+
error
54+
*
55+
---------------------------------------------------------------------------**/
56+
gdf_error gdf_mask_concat(gdf_valid_type* output_mask,
57+
gdf_size_type output_column_length,
58+
gdf_valid_type* masks_to_concat[],
59+
gdf_size_type* column_lengths,
60+
gdf_size_type num_columns);
61+
62+
63+
#endif

cpp/src/bitmask/bitmask_ops.hpp

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
/*
2+
* Copyright (c) 2019, 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+
#ifndef BITMASK_OPS_HPP
18+
#define BITMASK_OPS_HPP
19+
20+
#include <types.hpp>
21+
#include <cuda_runtime.h>
22+
23+
#include <rmm/thrust_rmm_allocator.h>
24+
25+
/**---------------------------------------------------------------------------*
26+
* @file bitmask_ops.hpp
27+
* @brief Internal functions for bitmask operations.
28+
*---------------------------------------------------------------------------**/
29+
30+
/**---------------------------------------------------------------------------*
31+
* @brief Sets all bits in input valid mask to 1
32+
*
33+
* @param valid_out preallocated output valid mask
34+
* @param out_null_count number of nulls (0 bits) in valid mask. Always set to 0
35+
* @param num_values number of values in column associated with output mask
36+
* @param stream cuda stream to run in
37+
* @return gdf_error
38+
*---------------------------------------------------------------------------**/
39+
gdf_error all_bitmask_on(gdf_valid_type* valid_out,
40+
gdf_size_type& out_null_count,
41+
gdf_size_type num_values, cudaStream_t stream);
42+
43+
/**---------------------------------------------------------------------------*
44+
* @brief Computes bitwise AND on two valid masks and sets it in output
45+
*
46+
* @param out_null_count number of nulls (0 bits) in output valid mask
47+
* @param valid_out preallocated mask to set the result values in
48+
* @param valid_left input valid mask 1
49+
* @param valid_right input valid mask 2
50+
* @param stream cuda stream to run in
51+
* @param num_values number of values in each input mask valid_left and
52+
* valid_right
53+
* @return gdf_error
54+
*---------------------------------------------------------------------------**/
55+
gdf_error apply_bitmask_to_bitmask(gdf_size_type& out_null_count,
56+
gdf_valid_type* valid_out,
57+
gdf_valid_type* valid_left,
58+
gdf_valid_type* valid_right,
59+
cudaStream_t stream,
60+
gdf_size_type num_values);
61+
62+
63+
namespace cudf {
64+
65+
/**---------------------------------------------------------------------------*
66+
* @brief Computes a bitmask indicating the presence of NULL values in rows of a
67+
* table.
68+
*
69+
* If a row `i` in `table` contains one or more NULL values, then bit `i` in the
70+
* returned bitmask will be 0.
71+
*
72+
* Otherwise, bit `i` will be 1.
73+
*
74+
* @param table The table to compute the row bitmask of.
75+
* @return bit_mask::bit_mask_t* The bitmask indicating the presence of NULLs in
76+
* a row
77+
*---------------------------------------------------------------------------**/
78+
rmm::device_vector<bit_mask::bit_mask_t> row_bitmask(cudf::table const& table,
79+
cudaStream_t stream = 0);
80+
} // namespace cudf
81+
82+
#endif

0 commit comments

Comments
 (0)