Scanner C++ API
kernel_factory.h
1 /* Copyright 2016 Carnegie Mellon University
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 
16 #pragma once
17 
18 #include "scanner/api/kernel.h"
19 #include "scanner/api/op.h"
20 #include "scanner/util/common.h"
21 
22 #include <vector>
23 
24 namespace scanner {
25 
26 namespace internal {
27 
39  public:
40  KernelFactory(const std::string& op_name, DeviceType type, i32 max_devices,
41  const std::map<std::string, DeviceType>& input_devices,
42  const std::map<std::string, DeviceType>& output_devices,
43  bool can_batch, i32 batch_size, KernelConstructor constructor)
44  : op_name_(op_name),
45  type_(type),
46  max_devices_(max_devices),
47  input_devices_(input_devices),
48  output_devices_(output_devices),
49  can_batch_(can_batch),
50  preferred_batch_size_(batch_size),
51  constructor_(constructor) {}
52 
53  const std::string& get_op_name() const { return op_name_; }
54 
56  DeviceType get_device_type() const { return type_; }
57 
58  i32 get_max_devices() const { return max_devices_; }
59 
60  const std::map<std::string, DeviceType>& get_input_devices() const {
61  return input_devices_;
62  }
63 
64  const std::map<std::string, DeviceType>& get_output_devices() const {
65  return output_devices_;
66  }
67 
68  bool can_batch() const { return can_batch_; }
69 
70  i32 preferred_batch_size() const { return preferred_batch_size_; }
71 
72  /* @brief Constructs a kernel to be used for processing elements of data.
73  */
74  BaseKernel* new_instance(const KernelConfig& config) {
75  return constructor_(config);
76  }
77 
78  private:
79  std::string op_name_;
80  DeviceType type_;
81  i32 max_devices_;
82  std::map<std::string, DeviceType> input_devices_;
83  std::map<std::string, DeviceType> output_devices_;
84  bool can_batch_;
85  i32 preferred_batch_size_;
86  KernelConstructor constructor_;
87 };
88 }
89 }
Kernel parameters provided at instantiation.
Definition: kernel.h:118
Interface for constructing ops at runtime.
Definition: kernel_factory.h:38
DeviceType get_device_type() const
Definition: kernel_factory.h:56
Definition: database.cpp:36
Interface for a unit of computation in a pipeline.
Definition: kernel.h:145