Row Accessor¶
The row_accessor
class provides read-only access to the rows of the
table as contiguous homogeneous array.
Usage Example¶
#include <sycl/sycl.hpp>
#include <iostream>
#include "oneapi/dal/table/homogen.hpp"
#include "oneapi/dal/table/row_accessor.hpp"
using namespace oneapi;
int main() {
sycl::queue queue { sycl::default_selector() };
constexpr float host_data[] = {
1.0f, 1.5f, 2.0f,
2.1f, 3.2f, 3.7f,
4.0f, 4.9f, 5.0f,
5.2f, 6.1f, 6.2f
};
constexpr std::int64_t row_count = 4;
constexpr std::int64_t column_count = 3;
auto shared_data = sycl::malloc_shared<float>(row_count * column_count, queue);
auto event = queue.memcpy(shared_data, host_data, sizeof(float) * row_count * column_count);
auto t = dal::homogen_table::wrap(queue, shared_data, row_count, column_count, { event });
// Accessing second and third rows of the table
dal::row_accessor<const float> acc { t };
auto block = acc.pull(queue, {1, 3});
for(std::int64_t i = 0; i < block.get_count(); i++) {
std::cout << block[i] << ", ";
}
std::cout << std::endl;
sycl::free(shared_data, queue);
return 0;
}
Programming Interface¶
All types and functions in this section are declared in the
oneapi::dal
namespace and available via the inclusion of the
oneapi/dal/table/row_accessor.hpp
header file.
-
template<typename T>
class row_accessor¶ - Template Parameters
T – The type of data values in blocks returned by the accessor. Should be const-qualified for read-only access. An accessor supports at least
float
,double
, andstd::int32_t
.
Constructors
-
template<typename U = T, std::enable_if_t<std::is_const_v<U>, int> = 0>
row_accessor(const table &table)¶ Creates a read-only accessor object from the table. Available only for const-qualified
T
.
-
row_accessor(const detail::table_builder &builder)¶
Public Methods
-
dal::array<data_t> pull(const range &row_range = {0, -1}) const¶
Provides access to the rows of the table. The method returns an array that directly points to the memory within the table if it is possible. In that case, the array refers to the memory as to immutable data. Otherwise, the new memory block is allocated, the data from the table rows is converted and copied into this block. In this case, the array refers to the block as to mutable data.
- Parameters
row_range – The range of rows that data is returned from the accessor.
- Preconditions
- row_range are within the range of [0, obj.row_count).
-
T *pull(dal::array<data_t> &block, const range &row_range = {0, -1}) const¶
Provides access to the rows of the table. The method returns an array that directly points to the memory within the table if it is possible. In that case, the array refers to the memory as to immutable data. Otherwise, the new memory block is allocated, the data from the table rows is converted and copied into this block. In this case, the array refers to the block as to mutable data. The method updates the block array.
- Parameters
block – The block which memory is reused (if it is possible) to obtain the data from the table. The block memory is reset either when its size is not big enough, or when it contains immutable data, or when direct memory from the table can be used. If the block is reset to use a direct memory pointer from the object, it refers to this pointer as to immutable memory block.
row_range – The range of rows that data is returned from the accessor.
- Preconditions
- rows are within the range of [0, obj.row_count).