18 #include "scanner/api/frame.h" 19 #include "scanner/util/common.h" 20 #include "scanner/util/memory.h" 21 #include "scanner/util/profiler.h" 34 Element(u8* buffer,
size_t size);
37 inline Frame* as_frame() {
return reinterpret_cast<Frame*
>(buffer); }
38 inline const Frame* as_const_frame()
const {
39 return reinterpret_cast<Frame*
>(buffer);
42 return reinterpret_cast<FrameInfo*
>(buffer);
44 inline const FrameInfo* as_const_frame_info()
const {
45 return reinterpret_cast<FrameInfo*
>(buffer);
48 inline bool is_null()
const {
49 return buffer ==
nullptr;
59 using Elements = std::vector<Element>;
61 using BatchedElements = std::vector<Elements>;
63 using StenciledElements = std::vector<Elements>;
66 using StenciledBatchedElements = std::vector<std::vector<Elements>>;
68 inline size_t num_rows(
const Elements& column) {
return column.size(); }
70 inline void insert_element(Elements& column, u8* buffer,
size_t size) {
74 inline void insert_frame(Elements& column,
Frame* frame) {
78 inline void insert_element(
Element& element, u8* buffer,
size_t size) {
82 inline void insert_frame(
Element& element,
Frame* frame) {
87 if (element.is_null()) {
91 if (element.is_frame) {
92 Frame* frame = element.as_frame();
93 add_buffer_ref(device, frame->data);
97 add_buffer_ref(device, element.buffer);
100 ele.index = element.index;
105 if (element.is_null()) {
108 if (element.is_frame) {
109 Frame* frame = element.as_frame();
110 delete_buffer(device, frame->data);
113 delete_buffer(device, element.buffer);
119 std::vector<DeviceHandle> devices;
120 std::vector<std::string> input_columns;
122 std::vector<proto::ColumnType> input_column_types;
123 std::vector<std::string> output_columns;
124 std::vector<proto::ColumnType> output_column_types;
125 std::vector<u8> args;
130 config.devices.push_back(CPU_DEVICE);
147 static const i32 UnlimitedDevices = 0;
157 virtual void validate(proto::Result* result) { result->set_success(
true); }
196 virtual void execute_kernel(
const StenciledBatchedElements& input_columns,
197 BatchedElements& output_columns) = 0;
224 static const i32 UnlimitedDevices = 0;
232 virtual void execute_kernel(
const StenciledBatchedElements& input_columns,
233 BatchedElements& output_columns)
override;
255 virtual void execute(
const StenciledBatchedElements& input_columns,
256 BatchedElements& output_columns) = 0;
284 virtual void execute_kernel(
const StenciledBatchedElements& input_columns,
285 BatchedElements& output_columns);
306 virtual void execute(
const BatchedElements& input_columns,
307 BatchedElements& output_columns) = 0;
319 virtual void execute_kernel(
const StenciledBatchedElements& input_columns,
320 BatchedElements& output_columns);
341 virtual void execute(
const StenciledElements& input_columns,
342 Elements& output_columns) = 0;
354 virtual void execute_kernel(
const StenciledBatchedElements& input_columns,
355 BatchedElements& output_columns);
374 virtual void execute(
const Elements& input_columns,
375 Elements& output_columns) = 0;
404 using KernelConstructor =
405 std::function<BaseKernel*(const KernelConfig& config)>;
416 KernelBuilder(
const std::string& name, KernelConstructor constructor)
418 constructor_(constructor),
419 device_type_(DeviceType::CPU),
422 preferred_batch_size_(1) {}
425 device_type_ = device_type;
430 num_devices_ = devices;
435 DeviceType device_type) {
436 input_devices_[input_name] = device_type;
441 DeviceType device_type) {
442 output_devices_[output_name] = device_type;
448 preferred_batch_size_ = preferred_batch_size;
454 KernelConstructor constructor_;
455 DeviceType device_type_;
457 std::map<std::string, DeviceType> input_devices_;
458 std::map<std::string, DeviceType> output_devices_;
460 i32 preferred_batch_size_;
464 #define REGISTER_KERNEL(name__, kernel__) \ 465 REGISTER_KERNEL_HELPER(__COUNTER__, name__, kernel__) 467 #define REGISTER_KERNEL_HELPER(uid__, name__, kernel__) \ 468 REGISTER_KERNEL_UID(uid__, name__, kernel__) 470 #define REGISTER_KERNEL_UID(uid__, name__, kernel__) \ 471 static ::scanner::internal::KernelRegistration kernel_registration_##uid__ \ 472 __attribute__((unused)) = ::scanner::internal::KernelBuilder( \ 473 #name__, [](const ::scanner::KernelConfig& config) { \ 474 return new kernel__(config); \ virtual void reset()
Requests that kernel resets its logical state.
Definition: kernel.h:191
Kernel parameters provided at instantiation.
Definition: kernel.h:118
virtual void new_stream(const std::vector< u8 > &args)
Called when the Kernel is about to process a new stream.
Definition: kernel.h:180
Kernel with support for frame and frame_info columns.
Definition: kernel.h:379
Interface for a unit of computation in a pipeline.
Definition: kernel.h:222
virtual void fetch_resources(proto::Result *result)
Downloads any resources necessary for the kernel to run.
Definition: kernel.h:164
virtual void validate(proto::Result *result)
Checks if kernel arguments are valid.
Definition: kernel.h:157
Interface for a unit of computation in a pipeline.
Definition: kernel.h:275
Frame.
Definition: frame.h:62
virtual void new_frame_info()
Callback for if frame info changes.
Definition: kernel.h:393
Element in a Scanner table, byte buffer of arbitrary size.
Definition: kernel.h:28
Definition: profiler.h:40
virtual void setup_with_resources(proto::Result *result)
Runs any setup code that relies on fetched resources.
Definition: kernel.h:171
Definition: database.cpp:36
i32 node_id
Byte-string of proto args if given.
Definition: kernel.h:126
FrameInfo.
Definition: frame.h:34
virtual void set_profiler(Profiler *profiler)
For internal use.
Definition: kernel.h:202
Interface for a unit of computation in a pipeline.
Definition: kernel.h:145