Scanner C++ API
runtime.h
1 /* Copyright 2016 Carnegie Mellon University, NVIDIA Corporation
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/database.h"
19 #include "scanner/api/kernel.h"
20 #include "scanner/api/op.h"
21 #include "scanner/engine/kernel_registry.h"
22 #include "scanner/engine/metadata.h"
23 #include "scanner/engine/op_registry.h"
24 #include "scanner/engine/rpc.grpc.pb.h"
25 #include "scanner/util/queue.h"
26 
27 #include "storehouse/storage_backend.h"
28 
29 #include <grpc++/create_channel.h>
30 #include <grpc++/security/credentials.h>
31 #include <grpc++/server.h>
32 #include <grpc++/server_builder.h>
33 
34 #include <dlfcn.h>
35 #include <string>
36 #include <thread>
37 
38 namespace scanner {
39 namespace internal {
40 
44 struct EvalWorkEntry {
45  i64 table_id;
46  i64 job_index;
47  i64 task_index;
48  std::vector<std::vector<i64>> row_ids;
49  BatchedElements columns;
50  std::vector<DeviceHandle> column_handles;
51  // Below only for pre/evaluate/post workers
52  std::vector<bool> inplace_video;
53  std::vector<ColumnType> column_types;
54  bool needs_configure;
55  bool needs_reset;
56  bool last_in_io_packet;
57  // Only for pre worker
58  std::vector<proto::VideoDescriptor::VideoCodecType> video_encoding_type;
59  bool first;
60  bool last_in_task;
61  // For save and pre worker
62  std::vector<FrameInfo> frame_sizes;
63  std::vector<bool> compressed;
64 };
65 
66 // Contains the row indices that a Op will see for the given task
67 struct TaskStream {
68  i64 slice_group;
69  // This is the set of input rows that the Op needs to keep.
70  std::vector<i64> valid_input_rows;
71  // This is the set of input rows it should process and produce
72  // outputs for.
73  std::vector<i64> compute_input_rows;
74  // This is the set of outputs that it should pass along (those
75  // not in this set should be immediately discarded). Needed
76  // to support bounded state operations which must produce output
77  // for elements, but that are not necessary for downstream operations
78  std::vector<i64> valid_output_rows;
79 };
80 
81 using LoadInputQueue =
83 using EvalQueue =
85 using OutputEvalQueue =
87 using SaveInputQueue =
89 using SaveOutputQueue =
91 
93  storehouse::StorageConfig* storage_config;
94  std::string db_path;
95  i32 num_cpus;
96  i32 num_load_workers;
97  i32 num_save_workers;
98  std::vector<i32> gpu_ids;
99  i64 no_workers_timeout; // in seconds
100  std::string python_dir;
101  i32 new_job_retries_limit;
102 };
103 
104 class MasterServerImpl;
105 class WorkerImpl;
106 
107 MasterServerImpl* get_master_service(DatabaseParameters& param, const std::string& port);
108 
109 WorkerImpl* get_worker_service(DatabaseParameters& params,
110  const std::string& master_address,
111  const std::string& worker_port);
112 
113 // Utilities
114 void move_if_different_address_space(Profiler& profiler,
115  DeviceHandle current_handle,
116  DeviceHandle target_handle,
117  Elements& column);
118 
119 void move_if_different_address_space(Profiler& profiler,
120  DeviceHandle current_handle,
121  DeviceHandle target_handle,
122  BatchedElements& columns);
123 
124 Elements copy_elements(Profiler& profiler, DeviceHandle current_handle,
125  DeviceHandle target_handle, Elements& column);
126 
127 Elements copy_or_ref_elements(Profiler& profiler,
128  DeviceHandle current_handle,
129  DeviceHandle target_handle,
130  Elements& column);
131 }
132 }
Definition: runtime.h:67
Definition: profiler.h:40
Definition: worker.h:30
Definition: common.h:53
Definition: database.cpp:36
Definition: runtime.h:44
Definition: queue.h:30