/*Copyright 2024 Infxl LLC. All rights reserved. This is proprietary software. No warranty, explicit or implicit, provided. In no event shall Infxl LLC be liable for any claim or damages. *********************************************************************************************** ******** RANKING BY ACCURACY 34-16-8-1508-616-663-rb-ecR-OFimp ******** ACCURACY COST ******** 0.9576 1244 Most accurate ******** 0.9576 2708 ******** 0.9569 607 Fastest, most energy-efficient and compact (see code below) ******** 0.9562 1587 ******** 0.9549 2521 ******** WHAT FOLLOWS IS THE CODE FOR A DEEP NET BUILT BY Infxl. THREE VERSIONS ARE PROVIDED: ******** 2- USES FOR-LOOPS & ARRAYS ***********************************************************************************************/ //these 333 inputs were found to be irrelevant: 0,2,5,6,8,12,13,14,15,17,18,19,20,21,26,29,30,35,43,44,45,46,47,48,59,60,61,65,67,68,71,74,78,79,80,81,82,83,84,85,86,88,90,91,94,95,96,97,98,100,101,107,120,123,124,126,128,130,133,135,136,137,138,153,154,161,162,164,165,166,167,168,169,170,171,173,174,175,176,177,178,180,181,188,204,206,207,208,209,211,213,217,218,219,220,221,223,224,226,228,229,230,231,232,234,235,239,240,241,242,243,244,245,246,247,252,253,254,255,256,257,258,259,265,266,272,277,278,279,280,281,282,283,284,285,286,290,291,293,294,301,302,303,304,305,306,307,308,309,310,311,312,313,314,315,316,318,319,320,322,323,324,325,326,327,328,329,330,331,332,333,334,335,336,337,338,339,340,341,342,343,344,345,346,347,349,350,351,352,353,355,357,358,360,361,362,364,370,375,376,378,379,380,381,382,383,384,385,386,387,389,391,392,393,394,395,396,397,398,399,400,401,402,403,404,405,406,407,408,409,410,412,413,414,415,416,418,419,420,421,422,423,424,425,426,427,429,430,431,432,434,435,436,437,438,439,440,441,443,447,448,460,462,463,464,465,466,467,468,469,470,471,472,473,474,475,476,477,478,479,480,481,482,483,484,485,486,487,488,489,490,491,492,493,494,495,496,497,498,499,500,503,505,506,508,509,514,515,517,518,520,521,522,524,528,529,530,531,532,533,534,535,537,540,541,542,543,544,545,546,547,548,553 //******** VERSION 2: USES FOR-LOOPS & ARRAYS ************************************************* #include int16_t const ROM16[] = { 561,6,26,-34,0,1,102,458,27,38,105,110,114,121,142,146,147,148,149,151,152,155,182,192,198,260,298,371,373,374,445,527,550,556,559,560,24,27,28,32,36,37,41,42,50,53,63,143,145,150,158,185,186,187,194,195,210,238,264,296,451,535,40,1,4,27,28,32,36,40,41,49,50,53,110,111,118,143,144,145,150,156,158,185,186,187,191,194,197,198,212,237,238,261,292,295,368,374,428,451,458,510,538,26,25,37,42,57,77,105,114,115,122,142,147,148,149,151,155,182,192,196,263,298,372,445,452,555,557,559,167,19,3,9,16,62,70,129,141,143,184,194,201,203,236,271,296,366,455,523,525,16,37,117,118,156,197,198,199,222,250,295,317,348,369,526,538,552,-10,26,24,37,92,114,115,117,118,142,156,197,198,199,227,273,287,289,295,366,367,368,450,516,523,526,536,538,17,36,55,62,70,72,131,134,157,185,186,192,205,261,296,442,444,458,468,32,4,7,22,37,55,106,108,117,119,127,131,132,134,140,148,159,163,190,192,205,261,269,270,276,298,299,321,451,458,459,512,552,29,1,9,23,24,28,89,92,93,118,143,158,189,197,202,227,233,262,267,274,297,365,367,390,411,417,433,502,504,507,149,0,1,377,549,18,10,32,36,39,55,63,99,134,141,157,185,193,261,269,300,451,458,558,30,1,24,31,73,75,92,104,114,115,116,118,139,142,147,197,199,237,248,289,295,367,368,449,450,510,516,523,526,538,549,759,22,23,24,28,57,58,66,102,103,104,114,116,118,159,197,237,288,367,445,454,525,549,558,13,40,49,52,55,56,76,106,157,388,501,513,552,559,293,33,36,37,39,40,49,52,55,56,64,87,106,108,113,117,119,125,148,156,179,198,199,202,276,354,356,369,449,453,458,461,519,551,552,25,3,9,11,28,38,57,62,109,172,186,189,190,194,195,200,214,215,225,268,297,363,446,452,504,558,278,29,1,32,36,41,50,51,53,63,69,118,119,144,145,150,158,183,185,186,187,191,194,197,225,237,238,446,451,538,539,22,34,39,110,112,142,149,156,182,189,196,198,260,263,366,372,374,445,452,511,554,559,560,139,26,7,36,37,102,103,104,157,159,160,163,192,249,251,269,275,287,348,366,367,433,456,457,458,512,523,559,17,1,28,33,54,89,92,114,152,195,201,214,216,274,359,502,504,507,323,1,571,2,566,569,309,2,566,572,1,562,157,6,564,566,568,569,571,572,3,563,565,570,0,3,561,566,572,1,567,452,2,565,569,3,564,566,572,381,5,563,564,568,569,571,2,562,565,340,3,568,570,571,5,562,563,564,569,572,180,2,561,564,5,566,568,570,571,572,64,5,575,576,577,578,579,3,573,574,580,265,6,573,574,576,578,579,580,2,575,577,224,2,576,579,3,574,577,578,31,3,574,576,577,4,575,578,579,580,139,4,576,577,578,580,3,574,575,579,101,4,574,575,576,578,3,573,577,579 }; //modify only copy_inp_vec_to_ram8_head() and read_op_vec_frm_ram8_tail() to meet the needs of your project void copy_inp_vec_to_ram8_head(int8_t ram8[]) { //the following line is a placeholder for code that brings the data from the sensors after it has been pre-processed to the range [-127, 127] int8_t preprocessed_inp_vec8[] = { 33,-3,-2,-119,-117,-84,-121,-117,-85,-113,-70,-60,91,80,100,-111,-127,-127,-119,-124,-121,-105,-22,-49,32,66,-62,62,-6,27,-17,17,-2,-14,9,-22,5,10,-63,-90,119,-36,15,-117,-119,-71,-118,-119,-77,115,-36,20,120,-34,-10,-2,105,-110,-123,-121,-120,-96,-54,-127,28,-55,55,-55,55,-101,99,-99,100,-125,125,-126,125,125,-127,-122,9,6,-14,-115,-119,-119,-116,-119,-120,-115,-121,-113,114,121,120,-118,-126,-127,-127,-119,-120,-123,-11,-40,-64,66,-29,63,40,29,15,28,54,-11,18,-25,9,-34,5,-45,15,-12,24,-112,-103,-119,-113,-109,-120,-84,-90,-82,106,105,103,-101,-124,-125,-126,-112,-115,-122,98,-34,58,-10,-2,30,-25,4,-10,1,31,28,-36,32,2,82,-30,-39,-26,-22,-12,-114,-116,-119,-116,-118,-121,-110,-116,-114,115,116,120,-118,-126,-126,-127,-119,-122,-123,5,10,-25,14,-3,25,39,15,7,9,25,40,-27,22,19,16,-20,-41,-110,-89,-94,-96,-125,-110,-124,-109,33,7,-26,77,-71,-110,-89,-94,-96,-125,-110,-124,-109,33,7,-26,77,-71,-118,-114,-114,-115,-124,-118,-126,-116,-17,31,-44,42,-34,-101,-97,-99,-91,-97,-101,-124,-106,84,5,-21,20,-1,-117,-113,-114,-116,-124,-117,-126,-116,42,65,-65,5,2,-117,-117,-100,-120,-117,-80,-118,-117,-92,-123,-119,-75,-123,-125,-121,-110,-127,-126,-119,-115,-119,-110,-43,-62,-21,-127,-127,-127,1,16,-66,-72,-114,-43,-87,24,-15,-127,-127,-126,-126,-126,-126,-126,-127,-127,-126,-126,-126,-127,-126,-127,-127,-127,-127,-127,-126,-127,-127,-126,-127,-127,-127,-127,-127,-117,-126,-126,-127,-127,-126,-126,-124,-119,-127,-127,-125,-119,-127,-114,-119,-117,-117,-120,-120,-114,-119,-120,-120,-122,-122,-120,-125,-124,-115,-126,-127,-127,-113,-119,-121,-60,-85,-75,-66,10,41,58,18,-23,-73,-115,-79,-120,-84,-116,-127,-127,-126,-126,-126,-125,-125,-127,-127,-126,-126,-125,-127,-126,-127,-127,-127,-127,-127,-126,-127,-127,-127,-127,-126,-127,-127,-126,-126,-127,-127,-127,-127,-126,-127,-127,-126,-127,-126,-127,-127,-127,-104,-102,-116,-115,-104,-121,-110,-105,-119,-115,-112,-123,-111,-120,-117,-105,-126,-125,-127,-111,-106,-118,0,26,-32,-127,-119,-118,24,-8,56,-51,-88,-50,-100,-62,-100,-126,-126,-126,-126,-125,-125,-125,-125,-126,-126,-125,-125,-126,-126,-124,-126,-127,-126,-126,-125,-126,-125,-125,-127,-126,-125,-125,-126,-127,-127,-127,-127,-127,-126,-126,-126,-127,-127,-127,-126,-127,-127,-100,-90,-92,-99,-120,-100,-121,-111,-22,-127,-62,1,-49,-114,-114,-113,-118,-114,-114,-126,-117,-62,-127,-5,-33,-89,-98,-101,-97,-104,-119,-98,-123,-101,23,-127,-6,-60,-96,-113,-115,-114,-116,-115,-113,-126,-114,-30,-127,9,-42,-89,1,21,-105,35,-91,35,-7 }; for (int16_t ip = 0; ip < ROM16[0]; ip++) { //copy preprocessed inputs to the start of ram8 ram8[ip] = preprocessed_inp_vec8[ip]; } } void read_op_vec_frm_ram8_tail(int8_t ram8[]) { int8_t computed_op_vec8[ROM16[1]]; for (int16_t op = 0; op < ROM16[1]; op++) { //copy values from ram8's tail to computed_op_vec8 computed_op_vec8[op] = ram8[ROM16[0] + ROM16[2] - ROM16[1] + op]; } } void deep_net_inference( int8_t ram8[]) { int8_t const static ROM8[] = {-126,-126,-126,-126,-126,-126,-126,-126,-126,-126,-126,-126,-126,-126,-126,-126,-126,-126,-126,-126,-126,-126,-126,-126,-126,-126,-126,-126,-126,-126,-126,-126,-126,-125,-125,-125,-125,-125,-125,-125,-125,-125,-125,-125,-125,-125,-125,-125,-125,-125,-125,-125,-125,-125,-125,-124,-124,-124,-124,-124,-124,-124,-124,-124,-124,-124,-124,-124,-124,-124,-124,-123,-123,-123,-123,-123,-123,-123,-123,-123,-123,-123,-123,-123,-122,-122,-122,-122,-122,-122,-122,-122,-122,-122,-122,-121,-121,-121,-121,-121,-121,-121,-121,-121,-120,-120,-120,-120,-120,-120,-120,-120,-120,-119,-119,-119,-119,-119,-119,-119,-118,-118,-118,-118,-118,-118,-118,-117,-117,-117,-117,-117,-117,-116,-116,-116,-116,-116,-115,-115,-115,-115,-115,-115,-114,-114,-114,-114,-113,-113,-113,-113,-113,-112,-112,-112,-112,-111,-111,-111,-111,-110,-110,-110,-110,-109,-109,-109,-109,-108,-108,-108,-107,-107,-107,-107,-106,-106,-106,-105,-105,-105,-104,-104,-104,-103,-103,-103,-102,-102,-101,-101,-101,-100,-100,-100,-99,-99,-98,-98,-97,-97,-97,-96,-96,-95,-95,-94,-94,-93,-93,-93,-92,-92,-91,-91,-90,-90,-89,-89,-88,-88,-87,-86,-86,-85,-85,-84,-84,-83,-82,-82,-81,-81,-80,-79,-79,-78,-78,-77,-76,-76,-75,-74,-74,-73,-72,-72,-71,-70,-70,-69,-68,-67,-67,-66,-65,-65,-64,-63,-62,-61,-61,-60,-59,-58,-58,-57,-56,-55,-54,-54,-53,-52,-51,-50,-49,-48,-48,-47,-46,-45,-44,-43,-42,-41,-41,-40,-39,-38,-37,-36,-35,-34,-33,-32,-31,-30,-29,-29,-28,-27,-26,-25,-24,-23,-22,-21,-20,-19,-18,-17,-16,-15,-14,-13,-12,-11,-10,-9,-8,-7,-6,-5,-4,-3,-2,-1,0,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,29,30,31,32,33,34,35,36,37,38,39,40,41,41,42,43,44,45,46,47,48,48,49,50,51,52,53,54,54,55,56,57,58,58,59,60,61,61,62,63,64,65,65,66,67,67,68,69,70,70,71,72,72,73,74,74,75,76,76,77,78,78,79,79,80,81,81,82,82,83,84,84,85,85,86,86,87,88,88,89,89,90,90,91,91,92,92,93,93,93,94,94,95,95,96,96,97,97,97,98,98,99,99,100,100,100,101,101,101,102,102,103,103,103,104,104,104,105,105,105,106,106,106,107,107,107,107,108,108,108,109,109,109,109,110,110,110,110,111,111,111,111,112,112,112,112,113,113,113,113,113,114,114,114,114,115,115,115,115,115,115,116,116,116,116,116,117,117,117,117,117,117,118,118,118,118,118,118,118,119,119,119,119,119,119,119,120,120,120,120,120,120,120,120,120,121,121,121,121,121,121,121,121,121,122,122,122,122,122,122,122,122,122,122,122,123,123,123,123,123,123,123,123,123,123,123,123,123,124,124,124,124,124,124,124,124,124,124,124,124,124,124,124,124,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126}; uint16_t nr_ptr = ROM16[0] - 1; //-1 nullifies the first pre-increment uint16_t ROM16_ptr = 1; int16_t static n_nr16, n_wt16, nr16, wt16, count16; for ( n_nr16 = ROM16[++ROM16_ptr], nr16 = 0; nr16 < n_nr16; ++nr16) { count16 = ROM16[++ROM16_ptr]; for (n_wt16 = ROM16[++ROM16_ptr], wt16 = 0; wt16 < n_wt16; ++wt16) { count16 += ram8[ROM16[++ROM16_ptr]]; } for (n_wt16 = ROM16[++ROM16_ptr], wt16 = 0; wt16 < n_wt16; ++wt16) { count16 -= ram8[ROM16[++ROM16_ptr]]; } if ( count16 < 0) { ram8[++nr_ptr] = -127; } else if (count16 > 656) { ram8[++nr_ptr] = 127; } else { ram8[++nr_ptr] = ROM8[count16]; } } } int main() { int8_t ram8[ ROM16[0] + ROM16[2] ]; while (1) { //get inputs, write them to ram8, run forward pass, read outputs from ram8 copy_inp_vec_to_ram8_head(ram8); deep_net_inference( ram8); read_op_vec_frm_ram8_tail(ram8); } return 0; }