C++ Run-time Library
Loading...
Searching...
No Matches
context.h
Go to the documentation of this file.
1// Copyright 2018 Delft University of Technology
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15#pragma once
16
17#include <arrow/api.h>
18#include <fletcher/common.h>
19#include <utility>
20#include <vector>
21#include <memory>
22#include <iostream>
23
24#include "fletcher/platform.h"
25#include "fletcher/status.h"
26
27namespace fletcher {
28
29using fletcher::Mode;
30
32enum class MemType {
40 ANY,
41
52 CACHE
53};
54
58 const uint8_t *host_address = nullptr;
60 da_t device_address = D_NULLPTR;
62 int64_t size = 0;
63
67 Mode mode = Mode::READ;
68
70 bool available_to_device = false;
72 bool was_alloced = false;
73
75 DeviceBuffer() = default;
76
78 DeviceBuffer(const uint8_t *host_address, int64_t size, MemType type, Mode access_mode)
79 : host_address(host_address), size(size), memory(type), mode(access_mode) {}
80};
81
83class Context {
84 public:
89 explicit Context(std::shared_ptr<Platform> platform) : platform_(std::move(platform)) {}
90
93
100 static Status Make(std::shared_ptr<Context> *context, const std::shared_ptr<Platform> &platform);
101
112 Status QueueRecordBatch(const std::shared_ptr<arrow::RecordBatch> &record_batch,
113 MemType mem_type = MemType::ANY);
114
116 size_t GetQueueSize() const;
117
120
122 std::shared_ptr<Platform> platform() const { return platform_; }
123
125 uint64_t num_buffers() const;
126
132 DeviceBuffer device_buffer(size_t i) const { return device_buffers_[i]; }
133
135 uint64_t num_recordbatches() const { return host_batches_.size(); }
136
142 std::shared_ptr<arrow::RecordBatch> recordbatch(size_t i) const { return host_batches_[i]; }
143
144 protected:
146 std::shared_ptr<Platform> platform_;
148 std::vector<std::shared_ptr<arrow::RecordBatch>> host_batches_;
150 std::vector<RecordBatchDescription> host_batch_desc_;
152 std::vector<MemType> host_batch_memtype_;
154 std::vector<DeviceBuffer> device_buffers_;
155};
156
157} // namespace fletcher
A Context for a platform where a RecordBatches can be prepared for processing by the Kernel.
Definition context.h:83
uint64_t num_recordbatches() const
Return the number of RecordBatches in this context.
Definition context.h:135
std::vector< DeviceBuffer > device_buffers_
Prepared/cached buffers on the device.
Definition context.h:154
std::shared_ptr< arrow::RecordBatch > recordbatch(size_t i) const
Return the i-th arrow::RecordBatch of this context.
Definition context.h:142
size_t GetQueueSize() const
Obtain the size (in bytes) of all buffers currently enqueued.
uint64_t num_buffers() const
Return the number of device buffers in this context.
std::shared_ptr< Platform > platform_
The platform this context is running on.
Definition context.h:146
std::vector< std::shared_ptr< arrow::RecordBatch > > host_batches_
The RecordBatches on the host side.
Definition context.h:148
std::vector< MemType > host_batch_memtype_
Whether the RecordBatch must be prepared or cached for the device.
Definition context.h:152
Context(std::shared_ptr< Platform > platform)
Context constructor.
Definition context.h:89
std::vector< RecordBatchDescription > host_batch_desc_
The descriptions of the RecordBatches on the host side.
Definition context.h:150
Status Enable()
Enable the usage of the enqueued buffers by the device.
~Context()
Deconstruct the context object, freeing all allocated device buffers.
DeviceBuffer device_buffer(size_t i) const
Return the i-th DeviceBuffer of this context.
Definition context.h:132
std::shared_ptr< Platform > platform() const
Return the platform this context is active on.
Definition context.h:122
Status QueueRecordBatch(const std::shared_ptr< arrow::RecordBatch > &record_batch, MemType mem_type=MemType::ANY)
Enqueue an arrow::RecordBatch for usage on the device.
static Status Make(std::shared_ptr< Context > *context, const std::shared_ptr< Platform > &platform)
Create a new context on a specific platform.
Contains all Fletcher classes and functions for use in run-time applications.
Definition api.h:34
MemType
Enumeration for different types of memory management.
Definition context.h:32
@ CACHE
Cache the data to on-board memory of the device.
@ ANY
Apply the least effort to make the data available to the device.
A buffer on the device.
Definition context.h:56
bool available_to_device
Whether this buffer has been made available to the device.
Definition context.h:70
DeviceBuffer()=default
Construct a default DeviceBuffer.
Mode mode
The access mode as seen by the accelerator kernel.
Definition context.h:67
DeviceBuffer(const uint8_t *host_address, int64_t size, MemType type, Mode access_mode)
Construct a new DeviceBuffer.
Definition context.h:78
da_t device_address
The device-side address of this buffer.
Definition context.h:60
MemType memory
The memory type of this buffer.
Definition context.h:65
bool was_alloced
Whether this buffer was allocated on the device using Platform malloc.
Definition context.h:72
const uint8_t * host_address
The host-side mirror address of this buffer.
Definition context.h:58
int64_t size
The size of this buffer in bytes.
Definition context.h:62
Status return value of all Fletcher run-time functions.
Definition status.h:25