tiny_dnn 1.0.0
A header only, dependency-free deep learning framework in C++11
Loading...
Searching...
No Matches
program.h
1/*
2 COPYRIGHT
3
4 All contributions by Taiga Nomi
5 Copyright (c) 2013, Taiga Nomi
6 All rights reserved.
7
8 All other contributions:
9 Copyright (c) 2013-2016, the respective contributors.
10 All rights reserved.
11
12 Each contributor holds copyright over their respective contributions.
13 The project versioning (Git) records all such contribution source information.
14
15 LICENSE
16
17 The BSD 3-Clause License
18
19
20 Redistribution and use in source and binary forms, with or without
21 modification, are permitted provided that the following conditions are met:
22
23 * Redistributions of source code must retain the above copyright notice, this
24 list of conditions and the following disclaimer.
25
26 * Redistributions in binary form must reproduce the above copyright notice,
27 this list of conditions and the following disclaimer in the documentation
28 and/or other materials provided with the distribution.
29
30 * Neither the name of tiny-dnn nor the names of its
31 contributors may be used to endorse or promote products derived from
32 this software without specific prior written permission.
33
34 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
35 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
36 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
37 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
38 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
39 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
40 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
41 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
42 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
43 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
44*/
45#pragma once
46
47#include "tiny_dnn/layers/layer.h"
48#include "tiny_dnn/core/framework/device.fwd.h"
49
50#if defined(USE_OPENCL) || defined(USE_CUDA)
51#ifdef USE_OPENCL
52#include "third_party/CLCudaAPI/clpp11.h"
53#else
54#include "third_party/CLCudaAPI/cupp11.h"
55#endif
56#endif
57
58namespace tiny_dnn {
59
60/* The class models a program to be stored in the register.
61 * Each instance of this class will be used as key in the register.
62 */
63class Program {
64 public:
65 explicit Program(const Device* device, const layer* op)
66 : device_(device), op_(op) {}
67
68 // Returns the device associated to the program
69 const Device* device() const { return device_; }
70
71 // Return the layer pointer
72 const layer* op() const { return op_; }
73
74 bool operator==(const Program& p) const {
75 if (p.device() == this->device() &&
76 p.op()->layer_type() == this->op()->layer_type()) {
77 return true;
78 }
79 return false;
80 }
81
82 private:
83 const Device* device_;
84 const layer* op_;
85};
86
87/* Hash function to store Programs in the register.
88 */
90 public:
91 size_t operator()(const Program& p) const {
92 // check there is a device and an op assigned
93 // to the input program.
94 if (p.device() == nullptr || p.op() == nullptr) {
95 throw nn_error("No Op or Device in Program.");
96 }
97
98 // Compute individual hash values for data members and combine
99 // them using XOR and bit shifting.
100 return (std::hash<int>()(static_cast<int>(p.device()->type())) ^
101 std::hash<bool>()(p.device()->hasCLCudaAPI()) ^
102 std::hash<int>()(p.device()->platformId()) ^
103 std::hash<int>()(p.device()->deviceId()) ^
104 std::hash<std::string>()(p.op()->layer_type()));
105 }
106};
107
108} // namespace tiny_dnn
Definition device.fwd.h:73
Definition program.h:89
Definition program.h:63
Simple image utility class.
Definition image.h:94
base class of all kind of NN layers
Definition layer.h:62
error exception class for tiny-dnn
Definition nn_error.h:37