ONE - On-device Neural Engine
Loading...
Searching...
No Matches
Backend.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved
3 *
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
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
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.
15 */
16
17#ifndef __NNKIT_SUPPORT_CAFFE_BACKEND_H__
18#define __NNKIT_SUPPORT_CAFFE_BACKEND_H__
19
23
24#include <nnkit/Backend.h>
25
26#include <caffe/net.hpp>
27
28#include <memory>
29#include <functional>
30
31namespace nnkit
32{
33namespace support
34{
35namespace caffe
36{
37
38template <typename DType> class Backend final : public nnkit::Backend
39{
40public:
41 Backend(std::unique_ptr<::caffe::Net<DType>> &&net) : _net{std::move(net)}
42 {
43 // DO NOTHING
44 }
45
46public:
47 void prepare(const std::function<void(nnkit::TensorContext &)> &f) override
48 {
49 InputBlobContext<DType> blobs(*_net);
50 TensorContext<DType> tensors(blobs);
51 f(tensors);
52 }
53
54public:
55 void run(void) override { _net->Forward(); }
56
57public:
58 void teardown(const std::function<void(nnkit::TensorContext &)> &f) override
59 {
60 OutputBlobContext<DType> blobs(*_net);
61 TensorContext<DType> tensors(blobs);
62 f(tensors);
63 }
64
65private:
66 std::unique_ptr<::caffe::Net<DType>> _net;
67};
68
69} // namespace caffe
70} // namespace support
71} // namespace nnkit
72
73#endif // __NNKIT_SUPPORT_CAFFE_BACKEND_H__
void teardown(const std::function< void(nnkit::TensorContext &)> &f) override
Definition Backend.h:58
void run(void) override
Definition Backend.h:55
void prepare(const std::function< void(nnkit::TensorContext &)> &f) override
Definition Backend.h:47
Backend(std::unique_ptr<::caffe::Net< DType > > &&net)
Definition Backend.h:41