From 8c9cf470baa67c0151c036d0fc737dbacf9ed27b Mon Sep 17 00:00:00 2001 From: lauriebose Date: Thu, 12 Sep 2024 16:36:22 +0100 Subject: [PATCH] More moving --- EXAMPLES/EX08_DREG_SHIFTING.hpp | 184 +++++++++++++++++++++++++ EXAMPLES/MAIN.cpp | 91 ------------ {MISC => EXAMPLES/MISC}/MISC_FUNCS.hpp | 0 EXAMPLES/MISC_FUNCS.hpp | 146 -------------------- EXAMPLES/TEST.CPP | 1 - scamp5_main.cpp | 118 ++++------------ 6 files changed, 213 insertions(+), 327 deletions(-) create mode 100644 EXAMPLES/EX08_DREG_SHIFTING.hpp delete mode 100644 EXAMPLES/MAIN.cpp rename {MISC => EXAMPLES/MISC}/MISC_FUNCS.hpp (100%) delete mode 100644 EXAMPLES/MISC_FUNCS.hpp delete mode 100644 EXAMPLES/TEST.CPP diff --git a/EXAMPLES/EX08_DREG_SHIFTING.hpp b/EXAMPLES/EX08_DREG_SHIFTING.hpp new file mode 100644 index 0000000..bf915d1 --- /dev/null +++ b/EXAMPLES/EX08_DREG_SHIFTING.hpp @@ -0,0 +1,184 @@ +#include + +#include "MISC/MISC_FUNCS.hpp" +using namespace SCAMP5_PE; + +vs_stopwatch frame_timer; +vs_stopwatch output_timer; +vs_stopwatch areg_shift_timer; + +int main() +{ + vs_init(); + + ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + //SETUP IMAGE DISPLAYS + + int disp_size = 2; + auto display_00 = vs_gui_add_display("Captured Image",0,0,disp_size); + auto display_01 = vs_gui_add_display("Binary Thresholded Image",0,disp_size,disp_size); + auto display_02 = vs_gui_add_display("Shifted Binary Thresholded Image",0,disp_size*2,disp_size); + + ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + //SETUP GUI ELEMENTS & CONTROLLABLE VARIABLES + + int threshold_value = 64; + vs_gui_add_slider("threshold_value",-127,127,threshold_value,&threshold_value); + + //for controlling the shift applied to the DREG content + int shift_x = 40; + vs_gui_add_slider("shift_x",-255,255,shift_x,&shift_x); + int shift_y = 40; + vs_gui_add_slider("shift_y",-255,255,shift_y,&shift_y); + + //for toggling between using "DNEWS0" or "DNEWS1" + int use_DNEWS1 = 0; + vs_gui_add_switch("use_DNEWS1",1,&use_DNEWS1); + + int output_just_shifted_img = 0; + vs_gui_add_switch("output_just_shifted_img",output_just_shifted_img == 1,&output_just_shifted_img); + + //CONTINOUS FRAME LOOP + while(true) + { + frame_timer.reset();//reset frame_timer + + vs_disable_frame_trigger(); + vs_frame_loop_control(); + + ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + //CAPTURE FRAME AND PERFORM THRESHOLDING + + //load threshold value into C across all PEs + scamp5_in(C,threshold_value); + scamp5_kernel_begin(); + get_image(A,F); //A = pixel data of latest frame, F = intermediate result + + sub(F,A,C); //C = (A - C) == (latest frame pixel - threshold) + + where(F);//sets FLAG = 1 in PEs where F > 0 (i.e. where A > C), else FLAG = 0 + + MOV(S0,FLAG);//copy FLAG into S0, will be performed on all PEs as FLAG does not effect Digital instruction execution, only analogue + MOV(S1,FLAG); + all();//Resets FLAG = 1 across all PEs + scamp5_kernel_end(); + + ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + //shift content of S1 using DNEWS + + areg_shift_timer.reset(); + + //First shift horizontally + { + scamp5_kernel_begin(); + CLR(RN,RS,RE,RW);//Clear all DREG controlling DNEWS behaviour + scamp5_kernel_end(); + + //set the appropriate DREG to shift horizontally left or right + if(shift_x > 0) + { + scamp5_kernel_begin(); + SET(RW); + scamp5_kernel_end(); + } + else + { + scamp5_kernel_begin(); + SET(RE); + scamp5_kernel_end(); + } + + //Now after setting up the RN,RS,RE,RW correctly, shift the content of S1 horizontally by repeatedly performing DNEWS operations + int iteration = abs(shift_x); + if(!use_DNEWS1) + { + for(int n = 0 ; n < iteration ; n++) + { + scamp5_kernel_begin(); + DNEWS0(S6,S1);//S6 = DNEWS(S0) + MOV(S1,S6);//Copy the results in S6 back into S0 + scamp5_kernel_end(); + } + } + else + { + for(int n = 0 ; n < iteration ; n++) + { + scamp5_kernel_begin(); + DNEWS1(S6,S1); + MOV(S1,S6); + scamp5_kernel_end(); + } + } + } + + //Now also shift vertically + { + scamp5_kernel_begin(); + CLR(RN,RS,RE,RW);//Clear all DREG controlling DNEWS behaviour + scamp5_kernel_end(); + + //set the appropriate DREG to shift vertically up or down + if(shift_y > 0) + { + scamp5_kernel_begin(); + SET(RN); + scamp5_kernel_end(); + } + else + { + scamp5_kernel_begin(); + SET(RS); + scamp5_kernel_end(); + } + + //Now after setting up the RN,RS,RE,RW correctly, shift the content of S1 vertically by repeatedly performing DNEWS operations + int iteration = abs(shift_y); + if(!use_DNEWS1) + { + for(int n = 0 ; n < iteration ; n++) + { + scamp5_kernel_begin(); + DNEWS0(S6,S1); + MOV(S1,S6); + scamp5_kernel_end(); + } + } + else + { + for(int n = 0 ; n < iteration ; n++) + { + scamp5_kernel_begin(); + DNEWS1(S6,S1); + MOV(S1,S6); + scamp5_kernel_end(); + } + } + } + + int time_spent_shifting = areg_shift_timer.get_usec(); + + + ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + //OUTPUT IMAGES + + output_timer.reset(); + if(!output_just_shifted_img) + { + output_4bit_image_via_DNEWS(A,display_00);//output AREG quickly using 4bit approximation + scamp5_output_image(S0,display_01);//display thresholded image + } + scamp5_output_image(S1,display_02);//displayed shifted thresholded image + int output_time_microseconds = output_timer.get_usec();//get the time taken for image output + + ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + //OUTPUT TEXT INFO + + int frame_time_microseconds = frame_timer.get_usec(); //get the time taken this frame + int max_possible_frame_rate = 1000000/frame_time_microseconds; //calculate the possible max FPS + int image_output_time_percentage = (output_time_microseconds*100)/frame_time_microseconds; //calculate the % of frame time which is used for image output + vs_post_text("time spent shifting %d \n",time_spent_shifting); + vs_post_text("frame time %d microseconds(%%%d image output), potential FPS ~%d \n",frame_time_microseconds,image_output_time_percentage,max_possible_frame_rate); //display this values on host + } + return 0; +} diff --git a/EXAMPLES/MAIN.cpp b/EXAMPLES/MAIN.cpp deleted file mode 100644 index df83430..0000000 --- a/EXAMPLES/MAIN.cpp +++ /dev/null @@ -1,91 +0,0 @@ - -#define EX_KERNEL_COST -1 -#define EX_AREG_DECAY -2 -#define EX_AREG_SATURATION -3 -#define EX_EVENT_READOUT -4 -#define EX_AREG_DEGRADATION -5 -#define EX_DREG_LOAD_PATTERN -6 -#define EX_RF_AND_RM -7 -#define EX_GLOBAL_OR -8 -#define EX_SHAPE_EXTRACTION -9 -#define EX_DREG_BOUNDING_BOX -10 -#define EX_DREG_FLOODING -11 - -#define EX_INTERLEAVED_DATA -15 -#define EX_ADC_DAC -16 -#define EX_DREG_SHIFTING1 -17 -#define EX_DREG_SHIFTING2 -18 -#define EX_AREG_QUANTIZED_STORAGE - 19 - -#define EX_IMAGE_CAPTURE 0 -#define EX_IMAGE_CAPTURE_AND_AREG 1 -#define EX_DREG_BASICS 2 -#define EX_FLAG 3 -#define EX_IMAGE_THRESHOLDING 4 -#define EX_AREG_NEWS 5 -#define EX_SIMPLE_EDGE_DETECTION 6 -#define EX_DNEWS 7 -#define EX_DREG_SHIFTING 8 -#define EX_DREG_EXPAND_AND_ERODE 9 -#define EX_HALF_SCALING 10 - -#define selected_algo -19 - - -#if selected_algo == 999 -#elif selected_algo == EX_IMAGE_CAPTURE - #include "EX00_IMAGE_CAPTURE.hpp" -#elif selected_algo == EX_IMAGE_CAPTURE_AND_AREG - #include "EX01_IMAGE_CAPTURE_AND_AREG.hpp" -#elif selected_algo == EX_DREG_BASICS - #include "EX02_DREG_BASICS.hpp" -#elif selected_algo == EX_FLAG - #include "EX03_FLAG.hpp" -#elif selected_algo == EX_IMAGE_THRESHOLDING - #include "EX04_IMAGE_THRESHOLDING.hpp" -#elif selected_algo == EX_AREG_NEWS - #include "EX05_AREG_NEWS.hpp" -#elif selected_algo == EX_SIMPLE_EDGE_DETECTION - #include "EX06_SIMPLE_EDGE_DETECTION.hpp" -#elif selected_algo == EX_DNEWS - #include "EX07_DNEWS.hpp" -#elif selected_algo == EX_DREG_EXPAND_AND_ERODE - #include "EX09_DREG_EXPAND_AND_ERODE.hpp" -#elif selected_algo == EX_HALF_SCALING - #include "EX10_HALF_SCALING.hpp" -#elif selected_algo == EX_INTERLEAVED_DATA - #include "EX_INTERLEAVED_DATA.hpp" -#elif selected_algo == EX_ADC_DAC - #include "EX_ADC_DAC.hpp" -#elif selected_algo == EX_DREG_SHIFTING1 - #include "EX_DREG_SHIFTING1.hpp" -#elif selected_algo == EX_DREG_SHIFTING2 - #include "EX_DREG_SHIFTING2.hpp" - -#elif selected_algo == EX_EVENT_READOUT - #include "EX_EVENT_READOUT.hpp" -#elif selected_algo == EX_DREG_FLOODING - #include "EX_DREG_FLOODING.hpp" -#elif selected_algo == EX_AREG_DECAY - #include "EX_AREG_DECAY.hpp" -#elif selected_algo == EX_KERNEL_COST - #include "EX_KERNEL_COST.hpp" -#elif selected_algo == EX_AREG_SATURATION - #include "EX_AREG_SATURATION.hpp" -#elif selected_algo == EX_AREG_DEGRADATION - #include "EX_AREG_DEGRADATION.hpp" -#elif selected_algo == EX_DREG_LOAD_PATTERN - #include "EX_DREG_LOAD_PATTERN.hpp" -#elif selected_algo == EX_RF_AND_RM - #include "EX_RF_AND_RM.hpp" -#elif selected_algo == EX_GLOBAL_OR - #include "EX_GLOBAL_OR.hpp" -#elif selected_algo == EX_SHAPE_EXTRACTION - #include "EX_SHAPE_EXTRACTION.hpp" -#elif selected_algo == EX_DREG_BOUNDING_BOX - #include "EX_DREG_BOUNDING_BOX.hpp" -#elif selected_algo == EX_AREG_QUANTIZED_STORAGE - #include "EX_AREG_QUANTIZED_STORAGE.hpp" - -#endif - diff --git a/MISC/MISC_FUNCS.hpp b/EXAMPLES/MISC/MISC_FUNCS.hpp similarity index 100% rename from MISC/MISC_FUNCS.hpp rename to EXAMPLES/MISC/MISC_FUNCS.hpp diff --git a/EXAMPLES/MISC_FUNCS.hpp b/EXAMPLES/MISC_FUNCS.hpp deleted file mode 100644 index ae42762..0000000 --- a/EXAMPLES/MISC_FUNCS.hpp +++ /dev/null @@ -1,146 +0,0 @@ -#include -using namespace SCAMP7_PE; - -#ifndef MISC_FUNCS_HPP -#define MISC_FUNCS_HPP - const int preset_in_val1 = 127; - const int preset_in_val2 = 74; - const int preset_in_val3 = 38; - const int preset_in_val4 = 20; - - void output_4bit_F_via_DNEWS(areg_t reg,vs_handle display,bool use_div = false, int in_val1 = preset_in_val1, int in_val2 = preset_in_val2, int in_val3 = preset_in_val3, int in_val4 = preset_in_val4) - { - if(use_div) - { - scamp7_in(E,127); - scamp7_kernel_begin(); - CLR(RS,RW,RN,RE); - - where(F); - MOV(RE,FLAG); - NOT(RF,FLAG); - WHERE(RF); - add(F,F,E); - all(); - - divq(D,E); - mov(E,D); - - sub(D,F,E); - where(D); - MOV(RN,FLAG); - mov(F,D); - all(); - - divq(D,E); - mov(E,D); - - sub(D,F,E); - where(D); - MOV(RW,FLAG); - mov(F,D); - all(); - - divq(D,E); - mov(E,D); - - sub(D,F,E); - where(D); - MOV(RS,FLAG); - mov(F,D); - all(); - scamp7_kernel_end(); - - scamp7_output_bitstack_begin(display,4); - scamp7_output_bitstack_bit(RE); - scamp7_output_bitstack_bit(RN); - scamp7_output_bitstack_bit(RW); - scamp7_output_bitstack_bit(RS); - scamp7_output_bitstack_end(); - } - else - { - - scamp7_in(E,127); - scamp7_kernel_begin(); - CLR(RS,RW,RN,RE); - - where(F); - MOV(RE,FLAG); - NOT(RF,FLAG); - WHERE(RF); - add(F,F,E); - all(); - scamp7_kernel_end(); - - scamp7_in(E,64); - scamp7_kernel_begin(); - sub(E,E,F); - where(E); - NOT(RN,FLAG); - WHERE(RN); - bus(F,E); - all(); - scamp7_kernel_end(); - - scamp7_in(E,32); - scamp7_kernel_begin(); - sub(E,E,F); - where(E); - NOT(RW,FLAG); - WHERE(RW); - bus(F,E); - all(); - scamp7_kernel_end(); - - scamp7_in(E,16); - scamp7_kernel_begin(); - sub(E,E,F); - where(E); - NOT(RS,FLAG); - WHERE(RS); - bus(F,E); - all(); - scamp7_kernel_end(); - - scamp7_output_bitstack_begin(display,4); - scamp7_output_bitstack_bit(RE); - scamp7_output_bitstack_bit(RN); - scamp7_output_bitstack_bit(RW); - scamp7_output_bitstack_bit(RS); - scamp7_output_bitstack_end(); - } - } - - void output_4bit_image_via_DNEWS(areg_t reg,vs_handle display,bool use_div = false, int in_val1 = 127, int in_val2 = 77, int in_val3 = 40, int in_val4 = 21) - { - scamp7_dynamic_kernel_begin(); - mov(F,reg); - scamp7_dynamic_kernel_end(); - output_4bit_F_via_DNEWS(reg,display,use_div,in_val1,in_val2,in_val3,in_val4); - } - - void DREG_load_centered_rect(dreg_t reg, int x, int y, int width, int height) - { - if(width == 0 || height == 0) - { - return; - } - - int top_row = y-height/2; - if(top_row < 0) - { - height += top_row; - top_row = 0; - } - int right_column = x-width/2; - if(right_column < 0) - { - width += right_column; - right_column = 0; - } - int bottom_row = top_row+height; - int left_column = right_column+width; - scamp7_load_region(reg, top_row, right_column, bottom_row-1, left_column-1); - } -#endif diff --git a/EXAMPLES/TEST.CPP b/EXAMPLES/TEST.CPP deleted file mode 100644 index 8b13789..0000000 --- a/EXAMPLES/TEST.CPP +++ /dev/null @@ -1 +0,0 @@ - diff --git a/scamp5_main.cpp b/scamp5_main.cpp index 6a5daaf..4dab405 100644 --- a/scamp5_main.cpp +++ b/scamp5_main.cpp @@ -1,89 +1,29 @@ - -#define EX_KERNEL_COST -1 -#define EX_AREG_DECAY -2 -#define EX_AREG_SATURATION -3 -#define EX_EVENT_READOUT -4 -#define EX_AREG_DEGRADATION -5 -#define EX_DREG_LOAD_PATTERN -6 -#define EX_RF_AND_RM -7 -#define EX_GLOBAL_OR -8 -#define EX_SHAPE_EXTRACTION -9 -#define EX_DREG_BOUNDING_BOX -10 -#define EX_DREG_FLOODING -11 - -#define EX_INTERLEAVED_DATA -15 -#define EX_ADC_DAC -16 -#define EX_DREG_SHIFTING1 -17 -#define EX_DREG_SHIFTING2 -18 - -#define EX_IMAGE_CAPTURE 0 -#define EX_IMAGE_CAPTURE_AND_AREG 1 -#define EX_DREG_BASICS 2 -#define EX_FLAG 3 -#define EX_IMAGE_THRESHOLDING 4 -#define EX_AREG_NEWS 5 -#define EX_SIMPLE_EDGE_DETECTION 6 -#define EX_DNEWS 7 -#define EX_DREG_SHIFTING 8 -#define EX_DREG_EXPAND_AND_ERODE 9 -#define EX_HALF_SCALING 10 - -#define selected_algo -18 - - -#if selected_algo == 999 -#elif selected_algo == EX_IMAGE_CAPTURE - #include "EX00_IMAGE_CAPTURE.hpp" -#elif selected_algo == EX_IMAGE_CAPTURE_AND_AREG - #include "EX01_IMAGE_CAPTURE_AND_AREG.hpp" -#elif selected_algo == EX_DREG_BASICS - #include "EX02_DREG_BASICS.hpp" -#elif selected_algo == EX_FLAG - #include "EX03_FLAG.hpp" -#elif selected_algo == EX_IMAGE_THRESHOLDING - #include "EX04_IMAGE_THRESHOLDING.hpp" -#elif selected_algo == EX_AREG_NEWS - #include "EX05_AREG_NEWS.hpp" -#elif selected_algo == EX_SIMPLE_EDGE_DETECTION - #include "EX06_SIMPLE_EDGE_DETECTION.hpp" -#elif selected_algo == EX_DNEWS - #include "EX07_DNEWS.hpp" -#elif selected_algo == EX_DREG_EXPAND_AND_ERODE - #include "EX09_DREG_EXPAND_AND_ERODE.hpp" -#elif selected_algo == EX_HALF_SCALING - #include "EX10_HALF_SCALING.hpp" -#elif selected_algo == EX_INTERLEAVED_DATA - #include "EX_INTERLEAVED_DATA.hpp" -#elif selected_algo == EX_ADC_DAC - #include "EX_ADC_DAC.hpp" -#elif selected_algo == EX_DREG_SHIFTING1 - #include "EX_DREG_SHIFTING1.hpp" -#elif selected_algo == EX_DREG_SHIFTING2 - #include "EX_DREG_SHIFTING2.hpp" - -#elif selected_algo == EX_EVENT_READOUT - #include "EX_EVENT_READOUT.hpp" -#elif selected_algo == EX_DREG_FLOODING - #include "EX_DREG_FLOODING.hpp" -#elif selected_algo == EX_AREG_DECAY - #include "EX_AREG_DECAY.hpp" -#elif selected_algo == EX_KERNEL_COST - #include "EX_KERNEL_COST.hpp" -#elif selected_algo == EX_AREG_SATURATION - #include "EX_AREG_SATURATION.hpp" -#elif selected_algo == EX_AREG_DEGRADATION - #include "EX_AREG_DEGRADATION.hpp" -#elif selected_algo == EX_DREG_LOAD_PATTERN - #include "EX_DREG_LOAD_PATTERN.hpp" -#elif selected_algo == EX_RF_AND_RM - #include "EX_RF_AND_RM.hpp" -#elif selected_algo == EX_GLOBAL_OR - #include "EX_GLOBAL_OR.hpp" -#elif selected_algo == EX_SHAPE_EXTRACTION - #include "EX_SHAPE_EXTRACTION.hpp" -#elif selected_algo == EX_DREG_BOUNDING_BOX - #include "EX_DREG_BOUNDING_BOX.hpp" - - -#endif - +//#include "EXAMPLES/EX_ADC_DAC.hpp" +//#include "EXAMPLES/EX_ANALOGUE_DIFFUSION.hpp" +//#include "EXAMPLES/EX_AREG_DECAY.hpp" +//#include "EXAMPLES/EX_AREG_DEGRADATION.hpp" +//#include "EXAMPLES/EX_AREG_QUANTIZED_STORAGE.hpp" +//#include "EXAMPLES/EX_AREG_SATURATION.hpp" +//#include "EXAMPLES/EX_DREG_BOUNDING_BOX.hpp" +//#include "EXAMPLES/EX_DREG_FLOODING.hpp" +//#include "EXAMPLES/EX_DREG_LOAD_PATTERN.hpp" +//#include "EXAMPLES/EX_DREG_SHIFTING1.hpp" +//#include "EXAMPLES/EX_DREG_SHIFTING2.hpp" +//#include "EXAMPLES/EX_EVENT_READOUT.hpp" +//#include "EXAMPLES/EX_GLOBAL_OR.hpp" +//#include "EXAMPLES/EX_INTERLEAVED_DATA.hpp" +//#include "EXAMPLES/EX_KERNEL_COST.hpp" +//#include "EXAMPLES/EX_OPTIMIZING_AREG_SHIFT.hpp" +//#include "EXAMPLES/EX_RF_AND_RM.hpp" +//#include "EXAMPLES/EX_SHAPE_EXTRACTION.hpp" +#include "EXAMPLES/EX00_IMAGE_CAPTURE.hpp" +//#include "EXAMPLES/EX01_IMAGE_CAPTURE_AND_AREG.hpp" +//#include "EXAMPLES/EX02_DREG_BASICS.hpp" +//#include "EXAMPLES/EX03_FLAG.hpp" +//#include "EXAMPLES/EX04_IMAGE_THRESHOLDING.hpp" +//#include "EXAMPLES/EX05_AREG_NEWS.hpp" +//#include "EXAMPLES/EX06_SIMPLE_EDGE_DETECTION.hpp" +//#include "EXAMPLES/EX07_DNEWS.hpp" +//#include "EXAMPLES/EX08_DREG_SHIFTING.hpp" +//#include "EXAMPLES/EX09_DREG_EXPAND_AND_ERODE.hpp" +//#include "EXAMPLES/EX10_HALF_SCALING.hpp"