Column accessor#

The column_accessor class provides a read-only access to the column values of the table as contiguous homogeneous array.

Usage example#

#include <CL/sycl.hpp>
#include <iostream>

#include "oneapi/dal/table/homogen.hpp"
#include "oneapi/dal/table/column_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, data, row_count, column_count, { event });

   // Accessing whole elements in a first column
   dal::column_accessor<const float> acc { t };

   auto block = acc.pull(queue, 0);
   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 shall be declared in the oneapi::dal namespace and be available via inclusion of the oneapi/dal/table/column_accessor.hpp header file.

template <typename Data>
class column_accessor {
public:
    using data_t = std::remove_const_t<Data>;

public:
    column_accessor(const table& obj);

    array<data_t> pull(sycl::queue& queue,
                       std::int64_t column_index,
                       const range& rows             = { 0, -1 },
                       const sycl::usm::alloc& alloc = sycl::usm::alloc::shared) const;

    Data* pull(sycl::queue& queue,
            array<data_t>& block,
            std::int64_t column_index,
            const range& rows             = { 0, -1 },
            const sycl::usm::alloc& alloc = sycl::usm::alloc::shared) const;
};
template<typename Data>
class column_accessor#
Template Parameters:

Data – The type of data values in blocks returned by the accessor. Shall be const-qualified for read-only access. An accessor shall support at least float, double, and std::int32_t types of \(Data\).

Constructors

column_accessor(const table &obj)#

Creates a new read-only accessor object from the table. The check that the accessor supports the table kind of \(obj\) shall be performed. The reference to the \(obj\) table shall be stored within the accessor to obtain data from the table.

Public Methods

array<data_t> pull(sycl::queue &queue, std::int64_t column_index, const range &rows = {0, -1}, const sycl::usm::alloc &alloc = sycl::usm::alloc::shared) const#

Provides access to the column values of the table. The method shall return an array that directly points to the memory within the table if it is possible. In that case, the array shall refer to the memory as to immutable data. Otherwise, the new memory block shall be allocated, the data from the table rows shall be converted and copied into this block. The array shall refer to the block as to mutable data.

Parameters:
  • queue – The SYCL* queue object.

  • column_index – The index of the column from which the data shall be returned by the accessor.

  • rows – The range of rows that should be read in the \(column_index\) block.

  • alloc – The requested kind of USM in the returned block.

Preconditions
rows are within the range of [0, obj.row_count).
column_index is within the range of [0, obj.column_count).
Data *pull(sycl::queue &queue, array<data_t> &block, std::int64_t column_index, const range &rows = {0, -1}, const sycl::usm::alloc &alloc = sycl::usm::alloc::shared) const#

Provides access to the column values of the table. The method shall return the block.data pointer.

Parameters:
  • queue – The SYCL* queue object.

  • block – The block which memory is reused (if it is possible) to obtain the data from the table. The block memory shall be 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 shall refer to this pointer as to immutable memory block.

  • column_index – The index of the column from which the data shall be returned by the accessor.

  • rows – The range of rows that should be read in the \(column_index\) block.

  • alloc – The requested kind of USM in the returned block.

Preconditions
rows are within the range of [0, obj.row_count).
column_index is within the range of [0, obj.column_count).