asgn
 
Loading...
Searching...
No Matches
dcnnelements.hpp
1#ifndef dcnnelements_hpp_
2#define dcnnelements_hpp_
3
4#include "tagged.hpp"
5
6#include <cassert>
7#include <random>
8#include <cmath>
9
11namespace dcnnasgn {
12
13 template<typename ... TL>
14 void sink(TL&&...)
15 {
16 }
17
18 struct permutation_policy_tag {};
19 struct permutation_policy_back_tag {};
20
21 template< typename PP>
22 concept is_policy = std::derived_from<PP, permutation_policy_tag>
23 && (!std::derived_from<PP, permutation_policy_back_tag>);
24
25 template< typename BPP>
26 concept is_policy_back = std::derived_from<BPP, permutation_policy_back_tag>;
27}
28
29namespace dcnnsol {
30
31 using dcnnasgn::is_policy;
32
33 template< typename SP, is_policy PP>
34 class image_data;
35
36 template< typename CSP, is_policy PP>
37 class feature_data;
38
39 template< typename KSP, typename CSPI, typename CSPO, is_policy PP>
40 class conv_weights;
41
42 template< typename CSPI, typename CSPO, is_policy PP>
43 class feature_weights;
44
45 template< typename CSP, is_policy PP>
46 class feature_multiplier;
47
48 template< typename CSP, is_policy PP>
49 class feature_bias;
50
51 template< typename CSPI, typename CSPO, typename KSP, is_policy PP>
52 class complete_cnn_model;
53
54 template< typename SPI, typename SPO, is_policy PP>
55 struct complete_cnn_internal;
56
57 template< typename SPI, typename SPO, typename KSP, is_policy PP>
58 struct complete_cnn_layer;
59
60}
62
63namespace dcnnasgn {
64
68
70 struct input_selector : tagged::tag_base {};
71 struct input_tag : tagged::r_tag<input_selector, tagged::rp_dense> {};
72 using input_range = tagged::range_class< input_tag>;
73 using input_index = tagged::index_class< input_tag>;
75
79 struct batch_selector : tagged::tag_base {};
80 struct batch_tag : tagged::r_tag<batch_selector, tagged::rp_odd> {};
81
83
87
92
94
98
102 struct height_selector : tagged::tag_base {};
106 struct width_selector : tagged::tag_base {};
107
109 template< std::size_t H>
110 struct height_stag : tagged::srr_tag<height_selector, 0, H, tagged::rp_odd> {};
111
112 template< std::size_t W>
113 struct width_stag : tagged::srr_tag<width_selector, 0, W, tagged::rp_odd> {};
115
117
121
127 template< std::size_t H, std::size_t W>
132 using height_tag = height_stag<H>;
136 using width_tag = width_stag<W>;
137
141 inline static constexpr tagged::range_class< height_tag> hr{ H };
145 inline static constexpr tagged::range_class< width_tag> wr{ W };
146 };
147
149
153
157 struct channel_selector : tagged::tag_base {};
158
160 template< std::size_t C>
161 struct channel_stag : tagged::srr_tag<channel_selector, 0, C, tagged::rp_odd> {};
163
170 struct kernel_height_selector : tagged::tag_base {};
177 struct kernel_width_selector : tagged::tag_base {};
178
180
184
187
188 template< typename ISP, typename CP>
189 struct input_data_policy : ISP, CP {
190 using typename ISP::height_tag;
191 using typename ISP::width_tag;
192 using typename CP::channel_tag;
193
194 using ISP::hr;
195 using ISP::wr;
196 using CP::cr;
197
198 using image_carrier = float;
199
200 using images_t = tagged::tensor_class< image_carrier, input_tag, tagged::set_roundup<channel_tag, tagged::rp_dense>, tagged::set_roundup<height_tag, tagged::rp_dense>, tagged::set_roundup<width_tag, tagged::rp_dense>>;
202 };
203
204 template< typename ISP, typename CP, typename SPO, is_policy PP>
205 struct batch_initializer {
206 public:
207 using policy = input_data_policy< ISP, CP>;
208
209 using height_tag = typename policy::height_tag;
210 using width_tag = typename policy::width_tag;
211 using channel_tag = typename policy::channel_tag;
212
213 using output_data = dcnnsol::image_data<SPO, PP>;
214
215 static void init(const typename policy::images_t& ind, const batch_mapping& bmap, output_data& outd)
216 {
217 static constexpr auto hr = policy::hr;
218 static constexpr auto wr = policy::wr;
219 auto cr = policy::cr;
220
221 auto&& images = outd.values;
222
223 assert(ind.range().template get<height_tag>() == hr);
224 assert(ind.range().template get<width_tag>() == wr);
225 assert(ind.range().template get<channel_tag>() == cr);
226
227 assert(images.range().template get<height_tag>() == hr);
228 assert(images.range().template get<width_tag>() == wr);
229 assert(images.range().template get<channel_tag>() == cr);
230
231 assert(images.range().template get<batch_tag>() == bmap.range().get<batch_tag>());
232
233 for (auto b : bmap.range())
234 {
235 auto i = bmap[b];
236 for (auto h : hr)
237 {
238 for (auto w : wr)
239 {
240 for (auto c : cr)
241 {
242 images[b & h & w & c] = ind[i & h & w & c];
243 }
244 }
245 }
246 }
247 }
248 };
249
250 struct gold_labels_policy {
251 using label_carrier = std::uint32_t;
252
253 using labels_t = tagged::tensor_class< label_carrier, input_tag>;
254 using batch_t = tagged::tensor_class< label_carrier, batch_tag>;
255 };
256
257 class gold_labels {
258 public:
259 using policy = gold_labels_policy;
260 gold_labels(const input_range& inr) : labels(inr) {}
261 policy::labels_t labels;
262 };
263
264 class gold_data {
265 public:
266 using policy = gold_labels_policy;
267 gold_data(const batch_range& nr) : labels(nr) {}
268 policy::batch_t labels;
269 void init(const policy::labels_t& ind, const input_range& inr)
270 {
271 assert(labels.range().get<batch_tag>().size() == inr.size());
272
273 auto inrb = (*inr.begin()).value();
274 for (auto i : inr)
275 {
276 tagged::index_class<batch_tag> b(i.value() - inrb);
277 labels[b] = ind[i];
278 }
279 }
280 void init(const policy::labels_t& ind, const batch_mapping& bmap)
281 {
282 assert(labels.range().get<batch_tag>().size() == bmap.range().size());
283
284 for (auto b : bmap.range())
285 {
286 auto i = bmap[b];
287 labels[b] = ind[i];
288 }
289 }
290 };
292
294
298
303 template< std::size_t C>
308 using channel_tag = channel_stag<C>;
309
313 inline static constexpr tagged::range_class< channel_tag> cr{ C };
314 };
315
321 template< typename ISP, typename CSP>
322 struct image_data_size_policy : ISP, CSP {
326 using image_policy = ISP;
330 using channel_policy = CSP;
331 };
332
338 template< typename SP, is_policy PP>
339 struct image_data_policy : SP {
343 using typename SP::height_tag;
347 using typename SP::width_tag;
351 using typename SP::channel_tag;
352
356 inline static constexpr auto hr = SP::hr;
360 inline static constexpr auto wr = SP::wr;
364 inline static constexpr auto cr = SP::cr;
365
380 };
381
387 template< typename CSP, is_policy PP>
411
421
423
424 struct data_stats {
425 data_stats(float e, float v)
426 : E(e), var(v)
427 {}
428
429 template< tagged::tag ... TL>
430 data_stats(const tagged::tensor_class< float, TL...>& val)
431 : E(0.0f), var(0.0f)
432 {
433 auto&& rng = val.range();
434
435 for (auto ix : rng)
436 {
437 auto v = val[ix];
438 E += v;
439 var += v * v;
440 }
441
442 float c = (float)rng.size();
443
444 E /= c;
445 var /= c;
446 var -= E * E;
447 }
448
449 float E, var;
450 };
451
452 template< typename SP, is_policy PP>
453 inline data_stats value_stats(const dcnnsol::image_data<SP, PP>& dt)
454 {
455 return data_stats(dt.values);
456 }
457
458 template< typename CSP, is_policy PP>
459 inline data_stats value_stats(const dcnnsol::feature_data<CSP, PP>& dt)
460 {
461 return data_stats(dt.values);
462 }
463
467
471 class loss_data {
472 public:
473 using policy = loss_data_policy;
474 loss_data(const batch_range& nr) : loss(nr) {}
475 policy::loss_t loss;
476 };
477
479
480 inline data_stats loss_stats(const loss_data& dt)
481 {
482 return data_stats(dt.loss);
483 }
484
488
490
494
500 template< tagged::tag T1, tagged::tag T2>
501 struct delta_functor {
502 delta_functor(std::ptrdiff_t delta)
503 : delta_(delta)
504 {}
505
506 std::ptrdiff_t delta() const
507 {
508 return delta_;
509 }
510
511 tagged::index_class<T2> operator()(const tagged::index_class<T1>& ko) const
512 {
513 auto dox = ko.value();
514 return tagged::index_class<T2>(dox + delta_);
515 }
516 private:
517 std::ptrdiff_t delta_;
518 };
519
525 template< tagged::tag T1, tagged::tag T2>
526 struct neg_delta_functor {
527 neg_delta_functor(std::ptrdiff_t delta)
528 : delta_(delta)
529 {}
530
531 std::ptrdiff_t delta() const
532 {
533 return delta_;
534 }
535
536 tagged::index_class<T2> operator()(const tagged::index_class<T1>& ko) const
537 {
538 auto dox = ko.value();
539 return tagged::index_class<T2>(delta_ - dox);
540 }
541 private:
542 std::ptrdiff_t delta_;
543 };
544
551 template< tagged::tag T1, tagged::tag T2, std::ptrdiff_t MUL>
552 struct mul_delta_functor {
553 mul_delta_functor(std::ptrdiff_t delta)
554 : delta_(delta)
555 {}
556
557 std::ptrdiff_t delta() const
558 {
559 return delta_;
560 }
561
562 inline static constexpr std::ptrdiff_t multiplier = MUL;
563
564 tagged::index_class<T2> operator()(const tagged::index_class<T1>& ko) const
565 {
566 auto dox = ko.value();
567 return tagged::index_class<T2>(delta_ + multiplier * dox);
568 }
569 private:
570 std::ptrdiff_t delta_;
571 };
572
574
578
580 template< std::size_t KH>
581 struct kernel_height_stag : tagged::srr_tag<kernel_height_selector, 0, KH, tagged::rp_odd> {};
582
583 template< std::size_t KW>
584 struct kernel_width_stag : tagged::srr_tag<kernel_width_selector, 0, KW, tagged::rp_odd> {};
586
588
592
600 template< std::size_t KH, std::size_t KW>
606
607 using kernel_height_tag = kernel_height_stag<KH>;
608 using kernel_width_tag = kernel_width_stag<KW>;
609
611
616
617 inline static constexpr tagged::range_class< kernel_height_tag> khr{ KH };
618 inline static constexpr tagged::range_class< kernel_width_tag> kwr{ KW };
619
621 };
622
631 template< typename KSP, typename CSPI, typename CSPO>
637
638 using typename KSP::kernel_height_tag;
639 using typename KSP::kernel_width_tag;
640
641 using channel_in_tag = typename CSPI::channel_tag;
642 using channel_out_tag = typename CSPO::channel_tag;
643
645
650
651 using KSP::khr;
652 using KSP::kwr;
653 inline static constexpr auto cir = CSPI::cr;
654 inline static constexpr auto cor = CSPO::cr;
655
657 };
658
667 template< typename CSPI, typename CSPO>
673
674 using channel_in_tag = typename CSPI::channel_tag;
675 using channel_out_tag = typename CSPO::channel_tag;
676
678
683
684 inline static constexpr auto cir = CSPI::cr;
685 inline static constexpr auto cor = CSPO::cr;
686
688 };
689
697 template< typename KSP, typename CSPI, typename CSPO, is_policy PP>
698 struct conv_weight_policy : conv_weight_size_policy< KSP, CSPI, CSPO> {
699 private:
701 public:
702 using typename base_::kernel_height_tag;
703 using typename base_::kernel_width_tag;
704 using typename base_::channel_in_tag;
705 using typename base_::channel_out_tag;
706
714
724
726 };
727
735 template< typename CSPI, typename CSPO, is_policy PP>
763
765
769
771 template<std::size_t KD, std::size_t S>
772 struct conv_traits {
773 static_assert(KD / 2 >= S - 1);
774 inline static constexpr std::size_t LPAD = (KD - 1) / 2;
775 inline static constexpr std::size_t SHIFT = (KD - 1) / 2;
776 inline static constexpr std::size_t RPAD = KD / 2 + 1 - S;
777 // KD == LPAD + 1 + RPAD
778 };
780
789 template< tagged::tag TK, tagged::tag TO, std::size_t DI, std::size_t KD, std::size_t S>
791 using traits = conv_traits<KD, S>;
792 static_assert(DI > traits::LPAD);
793 static_assert(DI > traits::RPAD);
795 {
796 auto dox = o.value() * S;
797 return tagged::range_class< tagged::selector<TK>>(traits::LPAD - std::min(dox, traits::LPAD), (KD + DI - traits::RPAD - 1) - std::max(dox, DI - traits::RPAD - 1));
798 }
799
800 constexpr std::size_t multiplier() const
801 {
802 return S;
803 }
804
805 constexpr std::size_t lpad() const
806 {
807 return traits::LPAD;
808 }
809
810 constexpr std::size_t rpad() const
811 {
812 return traits::RPAD;
813 }
814 };
815
823 template< tagged::tag TI, tagged::tag TK, tagged::tag TO, std::size_t KD, std::size_t S>
825 using traits = conv_traits<KD, S>;
826 using df = delta_functor<TK, TI>;
827 df operator()(const tagged::index_class<TO>& o) const
828 {
829 auto dox = o.value() * S;
830 return df(dox - traits::SHIFT);
831 }
832
833 constexpr std::size_t multiplier() const
834 {
835 return S;
836 }
837
838 constexpr std::ptrdiff_t delta() const
839 {
840 return -traits::SHIFT;
841 }
842 };
843
851 template< tagged::tag TI, tagged::tag TK, std::size_t DI, std::size_t KD, std::size_t S>
853 using traits = conv_traits<KD, S>;
854 static_assert(DI > traits::LPAD);
855 static_assert(DI > traits::RPAD);
857 {
858 static_assert(S == 1, "The kernel range is not contiguous for stride > 1");
859 auto dix = i.value();
860 return tagged::range_class< tagged::selector<TK>>(std::max(dix, DI - traits::LPAD - 1) - (DI - traits::LPAD - 1), (KD - traits::RPAD) + std::min(dix, traits::RPAD));
861 }
862 };
863
871 template< tagged::tag TI, tagged::tag TK, tagged::tag TO, std::size_t KD, std::size_t S>
873 using traits = conv_traits<KD, S>;
874 using df = neg_delta_functor<TK, TO>;
875 df operator()(const tagged::index_class<TI>& i) const
876 {
877 static_assert(S == 1, "The kernel range is not contiguous for stride > 1");
878 auto dix = i.value();
879 return df(dix + traits::SHIFT);
880 }
881 };
882
890 template< tagged::tag TK, tagged::tag TO, std::size_t DI, std::size_t KD, std::size_t S>
892 using traits = conv_traits<KD, S>;
893 static_assert(DI > traits::LPAD);
894 static_assert(DI > traits::RPAD);
896 {
897 auto dkx = k.value();
898 return tagged::range_class< tagged::selector<TO>>(((traits::LPAD + S - 1) - std::min(dkx, traits::LPAD)) / S, ((DI + KD - traits::RPAD - 1) - std::max(dkx, KD - traits::RPAD - 1)) / S);
899 }
900 };
901
909 template< tagged::tag TK, tagged::tag TO, tagged::tag TI, std::size_t KD, std::size_t S>
911 using traits = conv_traits<KD, S>;
912 using df = std::conditional_t< S == 1, delta_functor<TO, TI>, mul_delta_functor<TO, TI, S>>;
913 df operator()(const tagged::index_class<TK>& k) const
914 {
915 auto dkx = k.value();
916 return df(dkx - traits::SHIFT);
917 }
918 };
919
921
925
933 template< typename SPI, typename SPO, typename KSP, is_policy PP>
935 {
936 public:
937 using CSPI = typename SPI::channel_policy;
938 using CSPO = typename SPO::channel_policy;
939
942
946 using input_data = dcnnsol::image_data<SPI, PP>;
950 using weights = dcnnsol::conv_weights<KSP, CSPI, CSPO, PP>;
954 using output_data = dcnnsol::image_data<SPO, PP>;
956
959
960 using height_in_tag = typename SPI::height_tag;
961 using width_in_tag = typename SPI::width_tag;
962 using channel_in_tag = typename SPI::channel_tag;
963
964 using kernel_height_tag = typename KSP::kernel_height_tag;
965 using kernel_width_tag = typename KSP::kernel_width_tag;
966
967 using height_out_tag = typename SPO::height_tag;
968 using width_out_tag = typename SPO::width_tag;
969 using channel_out_tag = typename SPO::channel_tag;
970
972
973 static_assert(tagged::same_tag<height_in_tag, height_out_tag>);
974 static_assert(tagged::same_tag<width_in_tag, width_out_tag>);
975
981
982 inline static constexpr auto hir = SPI::hr;
983 inline static constexpr auto wir = SPI::wr;
984 inline static constexpr auto cir = SPI::cr;
985 inline static constexpr auto khr = KSP::khr;
986 inline static constexpr auto kwr = KSP::kwr;
987 inline static constexpr auto hor = SPO::hr;
988 inline static constexpr auto wor = SPO::wr;
989 inline static constexpr auto cor = SPO::cr;
990
992
993 inline static constexpr std::size_t fanin = khr.size() * kwr.size() * cir.size();
994
1023
1028
1033
1038
1040
1043
1052 {
1053 auto&& inv = ind.values;
1054 auto&& wtv = wtd.weights;
1055 auto&& outv = outd.values;
1056
1057 auto&& inr = inv.range();
1058 auto&& wtr = wtv.range();
1059 auto&& outr = outv.range();
1060
1061 auto&& br = inr.template get<batch_tag>();
1062
1063 static_assert(inr.template get<height_in_tag>() == hir);
1064 static_assert(inr.template get<width_in_tag>() == wir);
1065 static_assert(inr.template get<channel_in_tag>() == cir);
1066
1067 static_assert(wtr.template get<kernel_height_tag>() == khr);
1068 static_assert(wtr.template get<kernel_width_tag>() == kwr);
1069 static_assert(wtr.template get< tagged::co<channel_in_tag>>() == ~cir);
1070 static_assert(wtr.template get<channel_out_tag>() == cor);
1071
1072 static_assert(outr.template get<height_out_tag>() == hor);
1073 static_assert(outr.template get<width_out_tag>() == wor);
1074 static_assert(outr.template get<channel_out_tag>() == cor);
1075
1076 assert(outr.template get<batch_tag>() == br);
1077
1078 return br;
1079 }
1080
1081 static std::size_t forward_complexity( const batch_range & br)
1082 {
1083 return (br & khr & kwr & hor & wor & ~cir & cor).size();
1084 }
1086
1088 };
1089
1097 template< typename SPI, typename SPO, typename KSP, is_policy PP>
1099 {
1100 public:
1101 using CSPI = typename SPI::channel_policy;
1102 using CSPO = typename SPO::channel_policy;
1103
1106
1110 using input_data = dcnnsol::image_data<SPI, PP>;
1114 using weights = dcnnsol::conv_weights<KSP, CSPI, CSPO, PP>;
1118 using output_data = dcnnsol::image_data<SPO, PP>;
1120
1123
1124 using height_in_tag = typename SPI::height_tag;
1125 using width_in_tag = typename SPI::width_tag;
1126 using channel_in_tag = typename SPI::channel_tag;
1127
1128 using kernel_height_tag = typename KSP::kernel_height_tag;
1129 using kernel_width_tag = typename KSP::kernel_width_tag;
1130
1131 using height_out_tag = typename SPO::height_tag;
1132 using width_out_tag = typename SPO::width_tag;
1133 using channel_out_tag = typename SPO::channel_tag;
1134
1136
1142
1143 inline static constexpr auto hir = SPI::hr;
1144 inline static constexpr auto wir = SPI::wr;
1145 inline static constexpr auto cir = SPI::cr;
1146 inline static constexpr auto khr = KSP::khr;
1147 inline static constexpr auto kwr = KSP::kwr;
1148 inline static constexpr auto hor = SPO::hr;
1149 inline static constexpr auto wor = SPO::wr;
1150 inline static constexpr auto cor = SPO::cr;
1151
1153
1154 inline static constexpr std::size_t fanin = khr.size() * kwr.size() * cir.size();
1155
1156 static_assert(hir.size() % hor.size() == 0);
1157 static_assert(wir.size() % wor.size() == 0);
1158
1163
1164 inline static constexpr std::size_t HSTRIDE = hir.size() / hor.size();
1165 inline static constexpr std::size_t WSTRIDE = wir.size() / wor.size();
1166
1168
1197
1202
1207
1212
1214
1217
1226 {
1227 auto&& inv = ind.values;
1228 auto&& wtv = wtd.weights;
1229 auto&& outv = outd.values;
1230
1231 auto&& inr = inv.range();
1232 auto&& wtr = wtv.range();
1233 auto&& outr = outv.range();
1234
1235 auto&& br = inr.template get<batch_tag>();
1236
1237 static_assert(inr.template get<height_in_tag>() == hir);
1238 static_assert(inr.template get<width_in_tag>() == wir);
1239 static_assert(inr.template get<channel_in_tag>() == cir);
1240
1241 static_assert(wtr.template get<kernel_height_tag>() == khr);
1242 static_assert(wtr.template get<kernel_width_tag>() == kwr);
1243 static_assert(wtr.template get< tagged::co<channel_in_tag>>() == ~cir);
1244 static_assert(wtr.template get<channel_out_tag>() == cor);
1245
1246 static_assert(outr.template get<height_out_tag>() == hor);
1247 static_assert(outr.template get<width_out_tag>() == wor);
1248 static_assert(outr.template get<channel_out_tag>() == cor);
1249
1250 assert(outr.template get<batch_tag>() == br);
1251
1252 return br;
1253 }
1254
1255 static std::size_t forward_complexity(const batch_range& br)
1256 {
1257 return (br & khr & kwr & hor & wor & ~cir & cor).size();
1258 }
1260
1262 };
1263
1265
1269
1271 template< typename CSP>
1272 struct image_transformed_relu_internal_policy : CSP {
1273 using typename CSP::channel_tag;
1274
1275 using CSP::cr;
1276
1277 using stat_t = tagged::tensor_class< float, channel_tag>;
1278 using multiplier_t = tagged::tensor_class< float, channel_tag>;
1279 using co_multiplier_t = tagged::tensor_class< float, tagged::co<channel_tag>>;
1280 using bias_t = tagged::tensor_class< float, channel_tag>;
1281 using co_bias_t = tagged::tensor_class< float, tagged::co<channel_tag>>;
1282 };
1284
1286
1290
1292 template< typename CSP>
1293 class image_transformed_relu_model {
1294 public:
1295 using policy = image_transformed_relu_internal_policy< CSP>;
1296 image_transformed_relu_model() : scales(policy::cr), betas(policy::cr) {}
1297 policy::stat_t scales;
1298 policy::bias_t betas;
1299 };
1301
1303
1307
1313 template< typename SP, is_policy PP>
1315 public:
1316 using CSP = typename SP::channel_policy;
1317
1321 using input_data = dcnnsol::image_data<SP, PP>;
1325 using model_data = image_transformed_relu_model<CSP>;
1329 using output_data = dcnnsol::image_data<SP, PP>;
1330
1334 using height_tag = typename SP::height_tag;
1338 using width_tag = typename SP::width_tag;
1342 using channel_tag = typename SP::channel_tag;
1343
1344 inline static constexpr auto hr = SP::hr;
1345 inline static constexpr auto wr = SP::wr;
1346 inline static constexpr auto cr = SP::cr;
1347
1348 static tagged::range_class<batch_tag> forward_check(const input_data& ind, const model_data& nd, output_data& outd)
1349 {
1350 auto&& inv = ind.values;
1351 auto&& scalev = nd.scales;
1352 auto&& betav = nd.betas;
1353 auto&& outv = outd.values;
1354
1355 auto&& inr = inv.range();
1356 auto&& scaler = scalev.range();
1357 auto&& betar = betav.range();
1358 auto&& outr = outv.range();
1359
1360 auto&& br = inr.template get<batch_tag>();
1361
1362 static_assert(inr.template get<height_tag>() == hr);
1363 static_assert(inr.template get<width_tag>() == wr);
1364 static_assert(inr.template get<channel_tag>() == cr);
1365
1366 static_assert(scaler.template get<channel_tag>() == cr);
1367 static_assert(betar.template get<channel_tag>() == cr);
1368
1369 static_assert(outr.template get<height_tag>() == hr);
1370 static_assert(outr.template get<width_tag>() == wr);
1371 static_assert(outr.template get<channel_tag>() == cr);
1372
1373 assert(outr.template get<batch_tag>() == br);
1374
1375 return br;
1376 }
1377
1379 static std::size_t forward_complexity( const batch_range & br)
1380 {
1381 return 5 * (br & hr & wr & cr).size();
1382 }
1384 };
1385
1390
1391 template< typename CSP, is_policy PP>
1392 struct feature_bias_policy : CSP {
1393 using typename CSP::channel_tag;
1394
1395 using CSP::cr;
1396
1399 };
1400
1402
1403
1407
1408 struct maxpool_height_selector : tagged::tag_base {};
1409 struct maxpool_width_selector : tagged::tag_base {};
1410
1411 template< std::size_t KH>
1412 struct maxpool_height_stag : tagged::srr_tag<maxpool_height_selector, 0, KH, tagged::rp_odd> {};
1413
1414 template< std::size_t KW>
1415 struct maxpool_width_stag : tagged::srr_tag<maxpool_width_selector, 0, KW, tagged::rp_odd> {};
1416
1418
1422
1423 template< tagged::tag TK, tagged::tag TO, tagged::tag TI, std::size_t KD>
1426 df operator()(const tagged::index_class<TK>& k) const
1427 {
1428 auto dkx = k.value();
1429 return df(dkx);
1430 }
1431 };
1432
1434
1438
1439 template< typename SPI, typename SPO, is_policy PP>
1441
1442 static_assert(SPI::hr.size() % SPO::hr.size() == 0);
1443 static_assert(SPI::wr.size() % SPO::wr.size() == 0);
1444 static_assert(SPI::cr == SPO::cr);
1445
1446 static constexpr std::size_t KH = SPI::hr.size() / SPO::hr.size();
1447 static constexpr std::size_t KW = SPI::wr.size() / SPO::wr.size();
1448
1449 using input_data = dcnnsol::image_data<SPI, PP>;
1450 using output_data = dcnnsol::image_data<SPO, PP>;
1451
1452 using height_in_tag = typename SPI::height_tag;
1453 using width_in_tag = typename SPI::width_tag;
1454 using channel_tag = typename SPI::channel_tag;
1455
1456 using height_out_tag = typename SPO::height_tag;
1457 using width_out_tag = typename SPO::width_tag;
1458
1459 static_assert(tagged::same_tag<channel_tag, typename SPO::channel_tag>);
1460
1461 inline static constexpr auto hir = SPI::hr;
1462 inline static constexpr auto wir = SPI::wr;
1463 inline static constexpr auto cr = SPI::cr;
1464
1465 using maxpool_height_tag = maxpool_height_stag< KH>;
1466 using maxpool_width_tag = maxpool_width_stag< KW>;
1467
1468 inline static constexpr tagged::range_class< maxpool_height_tag> khr{ KH };
1469 inline static constexpr tagged::range_class< maxpool_width_tag> kwr{ KW };
1470
1471 inline static constexpr auto hor = SPO::hr;
1472 inline static constexpr auto wor = SPO::wr;
1473
1476
1477 static tagged::range_class<batch_tag> forward_check(const input_data& ind, output_data& outd)
1478 {
1479 auto&& inv = ind.values;
1480 auto&& outv = outd.values;
1481
1482 auto&& inr = inv.range();
1483 auto&& outr = outv.range();
1484
1485 auto&& br = inr.template get<batch_tag>();
1486
1487 static_assert(inr.template get<height_in_tag>() == hir);
1488 static_assert(inr.template get<width_in_tag>() == wir);
1489 static_assert(inr.template get<channel_tag>() == cr);
1490
1491 static_assert(outr.template get<height_out_tag>() == hor);
1492 static_assert(outr.template get<width_out_tag>() == wor);
1493 static_assert(outr.template get<channel_tag>() == cr);
1494
1495 assert(outr.template get<batch_tag>() == br);
1496
1497 return br;
1498 }
1499
1501 static std::size_t forward_complexity( const batch_range & br)
1502 {
1503 return (br & khr & kwr & hor & wor & cr).size();
1504 }
1506 };
1507
1508 template< typename SPI, typename CSPO, is_policy PP>
1510 {
1511 private:
1512 using CSPI = typename SPI::channel_policy;
1513
1514 static_assert(CSPI::cr == CSPO::cr);
1515 public:
1518
1522 using input_data = dcnnsol::image_data<SPI, PP>;
1526 using output_data = dcnnsol::feature_data<CSPO, PP>;
1527
1529
1532
1533 using height_in_tag = typename SPI::height_tag;
1534 using width_in_tag = typename SPI::width_tag;
1535 using channel_tag = typename SPI::channel_tag;
1536
1538
1544
1545 inline static constexpr auto hir = SPI::hr;
1546 inline static constexpr auto wir = SPI::wr;
1547 inline static constexpr auto cr = SPI::cr;
1548
1550
1551 inline static constexpr std::size_t fanin = hir.size() * wir.size();
1552
1555
1564 {
1565 auto&& inv = ind.values;
1566 auto&& outv = outd.values;
1567
1568 auto&& inr = inv.range();
1569 auto&& outr = outv.range();
1570
1571 auto&& br = inr.template get<batch_tag>();
1572
1573 static_assert(inr.template get<height_in_tag>() == hir);
1574 static_assert(inr.template get<width_in_tag>() == wir);
1575 static_assert(inr.template get<channel_tag>() == cr);
1576
1577 static_assert(outr.template get<channel_tag>() == cr);
1578
1579 assert(outr.template get<batch_tag>() == br);
1580
1581 return br;
1582 }
1583
1585 static std::size_t forward_complexity(const batch_range& br)
1586 {
1587 return (br & hir & wir & cr).size();
1588 }
1590 };
1591
1593
1597
1604 template< typename CSP>
1606 {
1607 using kernel_height_tag = tagged::retag< dcnnasgn::kernel_height_selector, typename CSP::height_tag>;
1608 using kernel_width_tag = tagged::retag< dcnnasgn::kernel_width_selector, typename CSP::width_tag>;
1609
1610 inline static constexpr auto khr = CSP::hr.template retag< kernel_height_tag>();
1611 inline static constexpr auto kwr = CSP::wr.template retag< kernel_width_tag>();
1612 };
1613
1615
1619
1625 template< tagged::tag TI, tagged::tag TK>
1627 tagged::index_class<TK> operator()(const tagged::index_class<TI>& i) const
1628 {
1629 return i.template retag<TK>();
1630 }
1631 };
1632
1634
1638
1645 template< typename CSPI, typename CSPO, is_policy PP>
1647 {
1648 public:
1651
1655 using input_data = dcnnsol::feature_data<CSPI, PP>;
1659 using weights = dcnnsol::feature_weights< CSPI, CSPO, PP>;
1663 using output_data = dcnnsol::feature_data<CSPO, PP>;
1664
1666
1669
1670 using channel_in_tag = typename CSPI::channel_tag;
1671
1672 using channel_out_tag = typename CSPO::channel_tag;
1673
1675
1681
1682 inline static constexpr auto cir = CSPI::cr;
1683 inline static constexpr auto cor = CSPO::cr;
1684
1686
1687 inline static constexpr std::size_t fanin = cir.size();
1688
1691
1700 {
1701 auto&& inv = ind.values;
1702 auto&& wtv = wtd.weights;
1703 auto&& outv = outd.values;
1704
1705 auto&& inr = inv.range();
1706 auto&& wtr = wtv.range();
1707 auto&& outr = outv.range();
1708
1709 auto&& br = inr.template get<batch_tag>();
1710
1711 static_assert(inr.template get<channel_in_tag>() == cir);
1712
1713 static_assert(wtr.template get< tagged::co<channel_in_tag>>() == ~cir);
1714 static_assert(wtr.template get<channel_out_tag>() == cor);
1715
1716 static_assert(outr.template get<channel_out_tag>() == cor);
1717
1718 assert(outr.template get<batch_tag>() == br);
1719
1720 return br;
1721 }
1722
1724 static std::size_t forward_complexity(const batch_range& br)
1725 {
1726 return (br & ~cir & cor).size();
1727 }
1729 };
1730
1731 template< typename CSP, is_policy PP>
1733 using input_data = dcnnsol::feature_data<CSP, PP>;
1734 using bias_data = dcnnsol::feature_bias<CSP, PP>;
1735 using output_data = dcnnsol::feature_data<CSP, PP>;
1736
1737 using typename CSP::channel_tag;
1738
1739 using CSP::cr;
1740
1741 static tagged::range_class<batch_tag> forward_check(const input_data& ind, const bias_data& cd, output_data& outd)
1742 {
1743 auto&& inv = ind.values;
1744 auto&& betav = cd.betas;
1745 auto&& outv = outd.values;
1746
1747 auto&& inr = inv.range();
1748 auto&& betar = betav.range();
1749 auto&& outr = outv.range();
1750
1751 auto&& br = inr.template get<batch_tag>();
1752
1753 static_assert(inr.template get<channel_tag>() == cr);
1754
1755 static_assert(betar.template get<channel_tag>() == cr);
1756
1757 static_assert(outr.template get<channel_tag>() == cr);
1758
1759 assert(outr.template get<batch_tag>() == br);
1760
1761 return br;
1762 }
1763
1765 static std::size_t forward_complexity( const batch_range & br)
1766 {
1767 return (br & cr).size();
1768 }
1770 };
1771
1772 template< typename CSP, is_policy PP>
1774 {
1775 using input_data = dcnnsol::feature_data<CSP, PP>;
1776 using output_data = loss_data;
1777
1778 using channel_tag = typename CSP::channel_tag;
1779
1780 inline static constexpr auto cr = CSP::cr;
1781
1782 static tagged::range_class<batch_tag> forward_check(const input_data& ind, const gold_data& gd, output_data& outd)
1783 {
1784 auto&& inv = ind.values;
1785 auto&& labelv = gd.labels;
1786 auto&& outv = outd.loss;
1787
1788 auto&& inr = inv.range();
1789 auto&& labelr = labelv.range();
1790 auto&& outr = outv.range();
1791
1792 auto&& br = inr.template get<batch_tag>();
1793
1794 static_assert(inr.template get<channel_tag>() == cr);
1795
1796 assert(labelr.template get<batch_tag>() == br); sink(labelr);
1797
1798 assert(outr.template get<batch_tag>() == br); sink(outr);
1799
1800 return br;
1801 }
1802
1804 static std::size_t forward_complexity( const batch_range & br)
1805 {
1806 return (br & cr).size();
1807 }
1809 };
1810
1811
1818 template< typename CSP, is_policy PP>
1820 : loss_layer_base< CSP, PP>
1821 {
1822 private:
1823 using base_ = loss_layer_base< CSP, PP>;
1824
1825 using typename base_::input_data;
1826 using typename base_::output_data;
1827
1828 using base_::cr;
1829
1830 using base_::forward_check;
1831 public:
1838 static void forward(const input_data& ind, const gold_data& gd, output_data& outd)
1839 {
1840 auto br = forward_check(ind, gd, outd);
1841
1842 auto&& inv = ind.values;
1843 auto&& labelv = gd.labels;
1844 auto&& outv = outd.loss;
1845
1846 for (auto b : br)
1847 {
1848 auto label = labelv[b];
1849 float maxv = std::numeric_limits<float>::lowest();
1851 for (auto c : cr)
1852 {
1853 auto v = inv[b & c];
1854 if (v > maxv)
1855 {
1856 maxv = v;
1857 maxc = c;
1858 }
1859 }
1860 auto loss = maxc.value() == label ? 1.0f : 0.0f;
1861
1862 outv[b] = loss;
1863 }
1864 }
1865 };
1866
1867 using feature_ftl = tagged::tag_list<channel_selector>;
1869 using image_conv_ftl = tagged::tag_list<channel_selector, tagged::co<channel_selector>, kernel_height_selector, kernel_width_selector>;
1870}
1871
1872#endif
Loss data class.
Definition dcnnelements.hpp:471
A list of tagged indexes (a position in an N-dimensional space)
Definition tagged.hpp:784
A list of tagged ranges (an N-dimensional box)
Definition tagged.hpp:933
std::size_t size() const
Size (volume) of the range.
Definition tagged.hpp:951
A tensor - a multi-dimensional tagged generalization of vector/matrix.
Definition tagged.hpp:1617
const range_class< TL ... > & range() const
The range corresponding to this tensor.
Definition tagged.hpp:1710
Any tag used to specify a dimension.
Definition tagged.hpp:28
tagged::range_class< batch_tag > batch_range
The range of images within a minibatch.
Definition dcnnelements.hpp:91
typename impl::tag_traits< T >::selector selector
Extract selector tag from any tag.
Definition tagged.hpp:43
retag< typename impl::co_traits< selector< T > >::co, T > co
Provide a co-tag for a given tag.
Definition tagged.hpp:1911
impl::permute_t< P, impl::permutator_tensor_class< E, TL... > > permute_tensor_class
Provide a tensor_class for the selected dimensions with layout specified by a tagged::tag_list.
Definition tagged.hpp:1857
Functor to cast input to kernel indexes (without any change in value).
Definition dcnnelements.hpp:1626
Retag input dimension policy as kernel dimension policy.
Definition dcnnelements.hpp:1606
Tag: Images within a minibatch.
Definition dcnnelements.hpp:79
Definition dcnnelements.hpp:80
Tag: Channel dimension.
Definition dcnnelements.hpp:157
Channel size policy.
Definition dcnnelements.hpp:304
static constexpr tagged::range_class< channel_tag > cr
Channel index range, statically sized.
Definition dcnnelements.hpp:313
channel_stag< C > channel_tag
Tag: The channel dimension, statically sized.
Definition dcnnelements.hpp:308
Functor: Input index to kernel index range.
Definition dcnnelements.hpp:852
Functor: Input index to neg_delta_functor.
Definition dcnnelements.hpp:872
Policy class: Convolution kernel dimensions.
Definition dcnnelements.hpp:601
static constexpr tagged::range_class< kernel_height_tag > khr
Kernel (convolution) height range.
Definition dcnnelements.hpp:617
static constexpr tagged::range_class< kernel_width_tag > kwr
Kernel (convolution) width range.
Definition dcnnelements.hpp:618
kernel_width_stag< KW > kernel_width_tag
Kernel (convolution) width.
Definition dcnnelements.hpp:608
kernel_height_stag< KH > kernel_height_tag
Kernel (convolution) height.
Definition dcnnelements.hpp:607
Functor: Kernel index to output index range.
Definition dcnnelements.hpp:891
Functor: Kernel index to delta_functor.
Definition dcnnelements.hpp:910
Functor: Output index to kernel index range.
Definition dcnnelements.hpp:790
Functor: Output index to delta_functor.
Definition dcnnelements.hpp:824
Policy class: Model weight data types for convolutional layers.
Definition dcnnelements.hpp:698
tagged::permute_tensor_class< typename PP::weights, float, kernel_height_tag, kernel_width_tag, tagged::co< channel_in_tag >, channel_out_tag > weights_t
The tensor containing the weights of the convolution.
Definition dcnnelements.hpp:723
typename CSPO::channel_tag channel_out_tag
Output channel tag.
Definition dcnnelements.hpp:642
Policy class: Model weight dimensions for convolutional layers.
Definition dcnnelements.hpp:632
typename CSPO::channel_tag channel_out_tag
Output channel tag.
Definition dcnnelements.hpp:642
static constexpr auto cir
Input channel range.
Definition dcnnelements.hpp:653
typename CSPI::channel_tag channel_in_tag
Input channel tag.
Definition dcnnelements.hpp:641
static constexpr auto cor
Output channel range.
Definition dcnnelements.hpp:654
Definition dcnnelements.hpp:424
Functor to add a fixed value.
Definition dcnnelements.hpp:501
Definition dcnnelements.hpp:1392
Utility base class for the fully connected layer.
Definition dcnnelements.hpp:1647
dcnnsol::feature_weights< CSPI, CSPO, PP > weights
Model weights.
Definition dcnnelements.hpp:1659
static constexpr std::size_t fanin
Number of inputs for each output element.
Definition dcnnelements.hpp:1687
typename CSPO::channel_tag channel_out_tag
Output feature channel.
Definition dcnnelements.hpp:1672
static constexpr auto cor
Output feature channel range.
Definition dcnnelements.hpp:1683
dcnnsol::feature_data< CSPI, PP > input_data
Input activations.
Definition dcnnelements.hpp:1655
static constexpr auto cir
Input feature channel range.
Definition dcnnelements.hpp:1682
typename CSPI::channel_tag channel_in_tag
Input feature channel.
Definition dcnnelements.hpp:1670
static tagged::range_class< batch_tag > forward_check(const input_data &ind, const weights &wtd, output_data &outd)
Check argument compatibility for the forward function.
Definition dcnnelements.hpp:1699
dcnnsol::feature_data< CSPO, PP > output_data
Output activations.
Definition dcnnelements.hpp:1663
Final layer activation data policy.
Definition dcnnelements.hpp:388
static constexpr auto cr
Channel index range, statically sized.
Definition dcnnelements.hpp:394
tagged::permute_tensor_class< tagged::co_list< typename PP::feature_data >, float, tagged::co< channel_tag >, tagged::co< batch_tag > > co_values_t
2-dimensional tensor type carrying loss derivatives wrt. activations
Definition dcnnelements.hpp:409
tagged::permute_tensor_class< typename PP::feature_data, float, channel_tag, batch_tag > values_t
2-dimensional tensor type carrying activations
Definition dcnnelements.hpp:401
Definition dcnnelements.hpp:1732
Policy class: Model weight data types for fully connected layers.
Definition dcnnelements.hpp:736
typename CSPO::channel_tag channel_out_tag
Output channel tag.
Definition dcnnelements.hpp:675
tagged::permute_tensor_class< typename PP::feature_weights, float, tagged::co< channel_in_tag >, channel_out_tag > weights_t
The tensor containing the weights of the convolution.
Definition dcnnelements.hpp:759
Policy class: Model weight dimensions for fully connected layers.
Definition dcnnelements.hpp:668
typename CSPO::channel_tag channel_out_tag
Output channel tag.
Definition dcnnelements.hpp:675
static constexpr auto cor
Output channel range.
Definition dcnnelements.hpp:685
static constexpr auto cir
Input channel range.
Definition dcnnelements.hpp:684
typename CSPI::channel_tag channel_in_tag
Input channel tag.
Definition dcnnelements.hpp:674
Definition dcnnelements.hpp:1510
static constexpr auto cr
Input image channel range.
Definition dcnnelements.hpp:1547
dcnnsol::feature_data< CSPO, PP > output_data
Output activations.
Definition dcnnelements.hpp:1526
static tagged::range_class< batch_tag > forward_check(const input_data &ind, output_data &outd)
Check argument compatibility for the forward function.
Definition dcnnelements.hpp:1563
typename SPI::width_tag width_in_tag
Input image width.
Definition dcnnelements.hpp:1534
typename SPI::height_tag height_in_tag
Input image height.
Definition dcnnelements.hpp:1533
static constexpr auto hir
Input image height range.
Definition dcnnelements.hpp:1545
typename SPI::channel_tag channel_tag
Input image channel.
Definition dcnnelements.hpp:1535
static constexpr auto wir
Input image width range.
Definition dcnnelements.hpp:1546
static constexpr std::size_t fanin
Number of inputs for each output element.
Definition dcnnelements.hpp:1551
dcnnsol::image_data< SPI, PP > input_data
Input activations.
Definition dcnnelements.hpp:1522
Tag: Height dimension of an image.
Definition dcnnelements.hpp:102
Internal layer activation data policy.
Definition dcnnelements.hpp:339
tagged::permute_tensor_class< typename PP::data, float, height_tag, width_tag, channel_tag, batch_tag > values_t
4-dimensional tensor type carrying activations
Definition dcnnelements.hpp:371
static constexpr auto cr
Channel index range, statically sized.
Definition dcnnelements.hpp:364
static constexpr auto hr
Image height range, statically sized.
Definition dcnnelements.hpp:356
tagged::permute_tensor_class< tagged::co_list< typename PP::data >, float, tagged::co< height_tag >, tagged::co< width_tag >, tagged::co< channel_tag >, tagged::co< batch_tag > > co_values_t
4-dimensional tensor type carrying loss derivatives wrt. activations
Definition dcnnelements.hpp:379
static constexpr auto wr
Image width range, statically sized.
Definition dcnnelements.hpp:360
Combined image and channel size policy.
Definition dcnnelements.hpp:322
CSP channel_policy
Channel size policy.
Definition dcnnelements.hpp:330
ISP image_policy
Image size policy.
Definition dcnnelements.hpp:326
Definition dcnnelements.hpp:1440
Image size policy.
Definition dcnnelements.hpp:128
height_stag< H > height_tag
Tag: Height dimension of an image, statically sized.
Definition dcnnelements.hpp:132
width_stag< W > width_tag
Tag: Width dimension of an image, statically sized.
Definition dcnnelements.hpp:136
static constexpr tagged::range_class< height_tag > hr
Height range of an image, statically sized.
Definition dcnnelements.hpp:141
static constexpr tagged::range_class< width_tag > wr
Width range of an image, statically sized.
Definition dcnnelements.hpp:145
Utility base class for a transformed ReLU layer.
Definition dcnnelements.hpp:1314
static constexpr auto wr
Index range along image width.
Definition dcnnelements.hpp:1345
typename SP::height_tag height_tag
Tag: Image height dimension.
Definition dcnnelements.hpp:1334
typename SP::channel_tag channel_tag
Tag: Channel index.
Definition dcnnelements.hpp:1342
image_transformed_relu_model< CSP > model_data
Statistics.
Definition dcnnelements.hpp:1325
static constexpr auto cr
Index range along image channels.
Definition dcnnelements.hpp:1346
typename SP::width_tag width_tag
Tag: Image width dimension.
Definition dcnnelements.hpp:1338
static constexpr auto hr
Index range along image height.
Definition dcnnelements.hpp:1344
dcnnsol::image_data< SP, PP > output_data
Output activations.
Definition dcnnelements.hpp:1329
dcnnsol::image_data< SP, PP > input_data
Input activations.
Definition dcnnelements.hpp:1321
Tag: Kernel height dimension.
Definition dcnnelements.hpp:170
Tag: Kernel width dimension.
Definition dcnnelements.hpp:177
Loss data policy.
Definition dcnnelements.hpp:415
tagged::tensor_class< float, batch_tag > loss_t
1-dimensional tensor type carrying loss values for images in a minibatch
Definition dcnnelements.hpp:419
Definition dcnnelements.hpp:1774
The loss layer.
Definition dcnnelements.hpp:1821
static void forward(const input_data &ind, const gold_data &gd, output_data &outd)
The forward-propagation function of the loss layer.
Definition dcnnelements.hpp:1838
Definition dcnnelements.hpp:1408
Definition dcnnelements.hpp:1412
Definition dcnnelements.hpp:1424
Definition dcnnelements.hpp:1409
Definition dcnnelements.hpp:1415
Functor to multiply by a constant and add a fixed value.
Definition dcnnelements.hpp:552
Functor to subtract from a fixed value.
Definition dcnnelements.hpp:526
Utility base class for the convolutional layer.
Definition dcnnelements.hpp:935
typename KSP::kernel_width_tag kernel_width_tag
Kernel width.
Definition dcnnelements.hpp:965
static constexpr conv_iko_map_functor< tagged::selector< height_in_tag >, tagged::selector< kernel_height_tag >, tagged::selector< height_out_tag >, khr.size(), 1 > hikomf
input-height index to kernel-height index to output-height index
Definition dcnnelements.hpp:1030
static constexpr conv_ok_range_functor< tagged::selector< kernel_height_tag >, tagged::selector< height_out_tag >, hir.size(), khr.size(), 1 > hokrf
output-height index to kernel-height range
Definition dcnnelements.hpp:1024
dcnnsol::image_data< SPI, PP > input_data
Input activations.
Definition dcnnelements.hpp:946
static constexpr auto cor
Output image channel range.
Definition dcnnelements.hpp:989
static constexpr auto hir
Input image height range.
Definition dcnnelements.hpp:982
static constexpr auto wir
Input image width range.
Definition dcnnelements.hpp:983
static constexpr conv_koi_map_functor< tagged::selector< kernel_width_tag >, tagged::selector< width_out_tag >, tagged::selector< width_in_tag >, kwr.size(), 1 > wkoimf
kernel-width index to output-width index to input-width index
Definition dcnnelements.hpp:1037
typename SPI::height_tag height_in_tag
Input image height.
Definition dcnnelements.hpp:960
static constexpr conv_koi_map_functor< tagged::selector< kernel_height_tag >, tagged::selector< height_out_tag >, tagged::selector< height_in_tag >, khr.size(), 1 > hkoimf
kernel-height index to output-height index to input-height index
Definition dcnnelements.hpp:1035
typename SPI::width_tag width_in_tag
Input image width.
Definition dcnnelements.hpp:961
static constexpr auto cir
Input image channel range.
Definition dcnnelements.hpp:984
typename SPO::height_tag height_out_tag
Output image height.
Definition dcnnelements.hpp:967
static constexpr auto khr
Kernel height range.
Definition dcnnelements.hpp:985
dcnnsol::image_data< SPO, PP > output_data
Output activations.
Definition dcnnelements.hpp:954
static tagged::range_class< batch_tag > forward_check(const input_data &ind, const weights &wtd, output_data &outd)
Check argument compatibility for the forward function.
Definition dcnnelements.hpp:1051
static constexpr conv_ko_range_functor< tagged::selector< kernel_height_tag >, tagged::selector< height_out_tag >, hir.size(), khr.size(), 1 > hkorf
kernel-height index to output-height range
Definition dcnnelements.hpp:1034
static constexpr conv_oki_map_functor< tagged::selector< width_in_tag >, tagged::selector< kernel_width_tag >, tagged::selector< width_out_tag >, kwr.size(), 1 > wokimf
output-width index to kernel-width index to input-width index
Definition dcnnelements.hpp:1027
static constexpr conv_ik_range_functor< tagged::selector< width_in_tag >, tagged::selector< kernel_width_tag >, wir.size(), kwr.size(), 1 > wikrf
input-width index to kernel-width range
Definition dcnnelements.hpp:1031
static constexpr conv_ko_range_functor< tagged::selector< kernel_width_tag >, tagged::selector< width_out_tag >, wir.size(), kwr.size(), 1 > wkorf
kernel-width index to output-width range
Definition dcnnelements.hpp:1036
typename SPO::width_tag width_out_tag
Output image width.
Definition dcnnelements.hpp:968
static constexpr conv_oki_map_functor< tagged::selector< height_in_tag >, tagged::selector< kernel_height_tag >, tagged::selector< height_out_tag >, khr.size(), 1 > hokimf
output-height index to kernel-height index to input-height index
Definition dcnnelements.hpp:1025
static constexpr auto kwr
Kernel width range.
Definition dcnnelements.hpp:986
static constexpr conv_iko_map_functor< tagged::selector< width_in_tag >, tagged::selector< kernel_width_tag >, tagged::selector< width_out_tag >, kwr.size(), 1 > wikomf
input-width index to kernel-width index to output-width index
Definition dcnnelements.hpp:1032
static constexpr std::size_t fanin
Number of inputs for each output element.
Definition dcnnelements.hpp:993
typename SPI::channel_tag channel_in_tag
Input image channel.
Definition dcnnelements.hpp:962
typename KSP::kernel_height_tag kernel_height_tag
Kernel height.
Definition dcnnelements.hpp:964
typename SPO::channel_tag channel_out_tag
Output image channel.
Definition dcnnelements.hpp:969
dcnnsol::conv_weights< KSP, CSPI, CSPO, PP > weights
Model weights.
Definition dcnnelements.hpp:950
static constexpr conv_ok_range_functor< tagged::selector< kernel_width_tag >, tagged::selector< width_out_tag >, wir.size(), kwr.size(), 1 > wokrf
output-width index to kernel-width range
Definition dcnnelements.hpp:1026
static constexpr auto hor
Output image height range.
Definition dcnnelements.hpp:987
static constexpr conv_ik_range_functor< tagged::selector< height_in_tag >, tagged::selector< kernel_height_tag >, hir.size(), khr.size(), 1 > hikrf
input-height index to kernel-height range
Definition dcnnelements.hpp:1029
static constexpr auto wor
Output image width range.
Definition dcnnelements.hpp:988
Utility base class for the convolutional layer.
Definition dcnnelements.hpp:1099
static constexpr conv_iko_map_functor< tagged::selector< width_in_tag >, tagged::selector< kernel_width_tag >, tagged::selector< width_out_tag >, kwr.size(), WSTRIDE > wikomf
input-width index to kernel-width index to output-width index
Definition dcnnelements.hpp:1206
static tagged::range_class< batch_tag > forward_check(const input_data &ind, const weights &wtd, output_data &outd)
Check argument compatibility for the forward function.
Definition dcnnelements.hpp:1225
typename SPI::height_tag height_in_tag
Input image height.
Definition dcnnelements.hpp:1124
static constexpr conv_oki_map_functor< tagged::selector< height_in_tag >, tagged::selector< kernel_height_tag >, tagged::selector< height_out_tag >, khr.size(), HSTRIDE > hokimf
output-height index to kernel-height index to input-height index
Definition dcnnelements.hpp:1199
dcnnsol::image_data< SPI, PP > input_data
Input activations.
Definition dcnnelements.hpp:1110
static constexpr auto wor
Output image width range.
Definition dcnnelements.hpp:1149
static constexpr conv_oki_map_functor< tagged::selector< width_in_tag >, tagged::selector< kernel_width_tag >, tagged::selector< width_out_tag >, kwr.size(), WSTRIDE > wokimf
output-width index to kernel-width index to input-width index
Definition dcnnelements.hpp:1201
typename SPI::width_tag width_in_tag
Input image width.
Definition dcnnelements.hpp:1125
static constexpr conv_koi_map_functor< tagged::selector< kernel_height_tag >, tagged::selector< height_out_tag >, tagged::selector< height_in_tag >, khr.size(), HSTRIDE > hkoimf
kernel-height index to output-height index to input-height index
Definition dcnnelements.hpp:1209
static constexpr conv_ko_range_functor< tagged::selector< kernel_width_tag >, tagged::selector< width_out_tag >, wir.size(), kwr.size(), WSTRIDE > wkorf
kernel-width index to output-width range
Definition dcnnelements.hpp:1210
static constexpr conv_ik_range_functor< tagged::selector< height_in_tag >, tagged::selector< kernel_height_tag >, hir.size(), khr.size(), HSTRIDE > hikrf
input-height index to kernel-height range
Definition dcnnelements.hpp:1203
typename KSP::kernel_height_tag kernel_height_tag
Kernel height.
Definition dcnnelements.hpp:1128
typename SPO::channel_tag channel_out_tag
Output image channel.
Definition dcnnelements.hpp:1133
static constexpr auto hor
Output image height range.
Definition dcnnelements.hpp:1148
dcnnsol::image_data< SPO, PP > output_data
Output activations.
Definition dcnnelements.hpp:1118
static constexpr auto wir
Input image width range.
Definition dcnnelements.hpp:1144
static constexpr auto hir
Input image height range.
Definition dcnnelements.hpp:1143
static constexpr conv_ko_range_functor< tagged::selector< kernel_height_tag >, tagged::selector< height_out_tag >, hir.size(), khr.size(), HSTRIDE > hkorf
kernel-height index to output-height range
Definition dcnnelements.hpp:1208
typename SPO::width_tag width_out_tag
Output image width.
Definition dcnnelements.hpp:1132
static constexpr auto kwr
Kernel width range.
Definition dcnnelements.hpp:1147
static constexpr auto khr
Kernel height range.
Definition dcnnelements.hpp:1146
static constexpr auto cor
Output image channel range.
Definition dcnnelements.hpp:1150
typename SPI::channel_tag channel_in_tag
Input image channel.
Definition dcnnelements.hpp:1126
static constexpr conv_koi_map_functor< tagged::selector< kernel_width_tag >, tagged::selector< width_out_tag >, tagged::selector< width_in_tag >, kwr.size(), WSTRIDE > wkoimf
kernel-width index to output-width index to input-width index
Definition dcnnelements.hpp:1211
typename KSP::kernel_width_tag kernel_width_tag
Kernel width.
Definition dcnnelements.hpp:1129
static constexpr auto cir
Input image channel range.
Definition dcnnelements.hpp:1145
static constexpr conv_ik_range_functor< tagged::selector< width_in_tag >, tagged::selector< kernel_width_tag >, wir.size(), kwr.size(), WSTRIDE > wikrf
input-width index to kernel-width range
Definition dcnnelements.hpp:1205
typename SPO::height_tag height_out_tag
Output image height.
Definition dcnnelements.hpp:1131
static constexpr conv_ok_range_functor< tagged::selector< kernel_height_tag >, tagged::selector< height_out_tag >, hir.size(), khr.size(), HSTRIDE > hokrf
output-height index to kernel-height range
Definition dcnnelements.hpp:1198
dcnnsol::conv_weights< KSP, CSPI, CSPO, PP > weights
Model weights.
Definition dcnnelements.hpp:1114
static constexpr conv_iko_map_functor< tagged::selector< height_in_tag >, tagged::selector< kernel_height_tag >, tagged::selector< height_out_tag >, khr.size(), HSTRIDE > hikomf
input-height index to kernel-height index to output-height index
Definition dcnnelements.hpp:1204
static constexpr std::size_t fanin
Number of inputs for each output element.
Definition dcnnelements.hpp:1154
static constexpr conv_ok_range_functor< tagged::selector< kernel_width_tag >, tagged::selector< width_out_tag >, wir.size(), kwr.size(), WSTRIDE > wokrf
output-width index to kernel-width range
Definition dcnnelements.hpp:1200
Tag: Width dimension of an image.
Definition dcnnelements.hpp:106
A wrapped list of tags.
Definition tagged.hpp:228