-
Notifications
You must be signed in to change notification settings - Fork 32
Expand file tree
/
Copy pathsum.cpp
More file actions
128 lines (100 loc) · 3.59 KB
/
Copy pathsum.cpp
File metadata and controls
128 lines (100 loc) · 3.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
// Copyright 2018 Delft University of Technology
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include <arrow/api.h>
#include <fletcher/api.h>
#include <memory>
#include <iostream>
/**
* Main function for the Sum example.
*/
int main(int argc, char **argv) {
// Check number of arguments.
if (argc != 2) {
std::cerr << "Incorrect number of arguments. Usage: sum path/to/recordbatch.rb" << std::endl;
return -1;
}
std::vector<std::shared_ptr<arrow::RecordBatch>> batches;
std::shared_ptr<arrow::RecordBatch> number_batch;
// Attempt to read the RecordBatch from the supplied argument.
fletcher::ReadRecordBatchesFromFile(argv[1], &batches);
// RecordBatch should contain exactly one batch.
if (batches.size() != 1) {
std::cerr << "File did not contain any Arrow RecordBatches." << std::endl;
return -1;
}
// The only RecordBatch in the file is our RecordBatch with the numbers.
number_batch = batches[0];
fletcher::Status status;
std::shared_ptr<fletcher::Platform> platform;
std::shared_ptr<fletcher::Context> context;
// Create a Fletcher platform object, attempting to autodetect the platform.
status = fletcher::Platform::Make(&platform);
if (!status.ok()) {
std::cerr << "Could not create Fletcher platform." << std::endl;
return -1;
}
// Initialize the platform.
status = platform->Init();
if (!status.ok()) {
std::cerr << "Could not initialize Fletcher platform." << std::endl;
return -1;
}
// Create a context for our application on the platform.
status = fletcher::Context::Make(&context, platform);
if (!status.ok()) {
std::cerr << "Could not create Fletcher context." << std::endl;
return -1;
}
// Queue the recordbatch to our context.
status = context->QueueRecordBatch(number_batch);
if (!status.ok()) {
std::cerr << "Could not queue the RecordBatch to the context." << std::endl;
return -1;
}
// "Enable" the context, potentially copying the recordbatch to the device. This depends on your platform.
// AWS EC2 F1 requires a copy, but OpenPOWER SNAP doesn't.
status = context->Enable();
if (!status.ok()) {
std::cerr << "Could not enable the context." << std::endl;
return -1;
}
// Create a kernel based on the context.
fletcher::Kernel kernel(context);
// Start the kernel.
status = kernel.Start();
if (!status.ok()) {
std::cerr << "Could not start the kernel." << std::endl;
return -1;
}
// Wait for the kernel to finish.
status = kernel.PollUntilDone();
if (!status.ok()) {
std::cerr << "Something went wrong waiting for the kernel to finish." << std::endl;
return -1;
}
// Obtain the return value.
uint32_t return_value_0;
uint32_t return_value_1;
status = kernel.GetReturn(&return_value_0, &return_value_1);
if (!status.ok()) {
std::cerr << "Could not obtain the return value." << std::endl;
return -1;
}
// combine the 2 32-bit values into the 64-bit endresult
int64_t result = return_value_0;
result |= static_cast<int64_t>(return_value_1) << 32;
// Print the return value.
std::cout << result << std::endl;
return 0;
}