2 * Copyright (c) 2019 Samsung Electronics Co., Ltd. All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
21 uint64_t num_elems(const nnfw_tensorinfo *ti)
24 for (uint32_t i = 0; i < ti->rank; ++i)
31 int main(const int argc, char **argv)
33 nnfw_session *session = nullptr;
34 nnfw_create_session(&session);
37 nnfw_load_model_from_file(session, argv[1]);
39 // Use acl_neon backend for CONV_2D and acl_cl for otherwise.
40 // Note that defalut backend is acl_cl
41 nnfw_set_op_backend(session, "CONV_2D", "acl_neon");
44 nnfw_prepare(session);
46 // Prepare input. Here we just allocate dummy input arrays.
47 std::vector<float> input;
49 nnfw_input_tensorinfo(session, 0, &ti); // get first input's info
50 uint32_t input_elements = num_elems(&ti);
51 input.resize(input_elements);
52 // TODO: Please add initialization for your input.
53 nnfw_set_input(session, 0, ti.dtype, input.data(), sizeof(float) * input_elements);
56 std::vector<float> output;
57 nnfw_output_tensorinfo(session, 0, &ti); // get first output's info
58 uint32_t output_elements = num_elems(&ti);
59 output.resize(output_elements);
60 nnfw_set_output(session, 0, ti.dtype, output.data(), sizeof(float) * output_elements);
65 // TODO: Please print or compare the output value in your way.
67 nnfw_close_session(session);
69 std::cout << "nnpackage " << argv[1] << " runs successfully." << std::endl;