Changes between Version 1 and Version 2 of Component/Virtual Coprocessor Wrapper
- Timestamp:
- Jan 14, 2013, 6:14:17 PM (12 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
Component/Virtual Coprocessor Wrapper
v1 v2 69 69 = Component usage = 70 70 71 == Object == 71 The virtual Coprocessor Wrapper is primarily intended to be used with Dsx-vm (to be released soon?), but it can also be used "by hand". In the following is an example of a dummy ''adder'' task, which makes a vectorial 32-bit addition of size 8 (i.e. there are 16 words in input and 8 words in output). 3 files must be created: 72 * `my_adder_copro.sd` 73 * `my_adder_copro.h` 74 * `my_adder_copro.cpp` 75 76 The file `my_adder_copro.sd` must contain the following: 72 77 73 78 {{{ 74 soclib::common::ProcessWrapper *process; 79 #!python 80 #-*- python -*- 81 82 Module('caba:my_adder_copro', 83 classname = 'dsx::caba::MyAdderCopro', 84 header_files = [ 85 "my_adder_copro.h", 86 87 ], 88 interface_files = [ 89 ], 90 implementation_files = [ 91 "my_adder_copro.cpp", 92 93 ], 94 ports = [ 95 ], 96 uses = [ 97 Uses('caba:virtual_copro_wrapper'), 98 ], 99 instance_parameters = [ 100 ], 101 tmpl_parameters = [ 102 ], 103 extensions = [ 104 ], 105 ) 75 106 }}} 76 107 77 == Instanciation == 108 The file `my_adder_copro.h` must be as following: 109 110 {{{ 111 #!cpp 112 113 #ifndef _ADDER_COPRO_H 114 #define _ADDER_COPRO_H 115 116 #include <systemc> 117 118 #include "virtual_copro_wrapper.h" 119 120 namespace dsx { namespace caba { 121 122 class MyAdderCopro 123 : public dsx::caba::VirtualCoprocessorWrapper 124 { 78 125 79 126 80 {{{ 81 soclib::common::ProcessWrapper( 82 const std::string &cmd, 83 const std::vector<std::string> &argv ); 127 public: 128 ~MyAdderCopro(); 129 MyAdderCopro(sc_core::sc_module_name insname); 130 131 private: 132 void * task_func(); // Task code 133 134 }; 135 136 }} 137 #endif /* _ADDER_COPRO_H */ 84 138 }}} 85 139 86 cmd:: 87 The command to launch, it will be looked for in $PATH 88 argv:: 89 The argv in a standart unix style. argv[0] should look like cmd. 90 91 == Usage == 140 Finally, the file `my_adder_copro.cpp` must contain the task code. We declare here two "input fifos" (`input0` and `input1`) and one "output fifo" (`output`) in the constructor. 92 141 93 142 {{{ 94 std::vector<std::string> argv; 95 argv.push_back("date"); 96 argv.push_back("+%s"); 97 soclib::common::ProcessWrapper process("date", argv); 143 #!cpp 98 144 99 char buffer[128]; 100 process.read( buffer, 128 ); 101 std::cout << "Date is " << buffer << " seconds since EPOCH" << std::endl; 145 #include "my_adder_copro.h" 146 147 namespace dsx { namespace caba { 148 149 150 #define tmpl(...) __VA_ARGS__ MyAdderCopro 151 152 tmpl(/**/)::~MyAdderCopro() 153 { 154 } 155 156 tmpl(/**/)::MyAdderCopro(sc_core::sc_module_name insname) 157 dsx::caba::VirtualCoprocessorWrapper(insname, stringArray("output", NULL), intArray(1, 8), stringArray("input0", "input1", NULL), intArray(2, 8, 8)) 158 { 159 } 160 161 tmpl(void *)::task_func() { 162 srl_mwmr_t input = SRL_GET_MWMR(input); 163 srl_mwmr_t output = SRL_GET_MWMR(output); 164 165 uint32_t in0[8]; 166 uint32_t in1[8]; 167 uint32_t out[8]; 168 169 while (true) { 170 srl_mwmr_read(input0, &in0, 1); // Read 8 words from input0, i.e. 1 item since the fifo is 8-word wide 171 srl_mwmr_read(input1, &in1, 1); // Read 8 words from input1 172 for (int32_t i = 0; i < 8; i++) { 173 out[i] = in0[i] + in1[i]; 174 } 175 srl_mwmr_write(output, &out, 1); // Write 8 words to output 176 } 177 } 178 179 }} 102 180 }}} 103 181 182 183 À compléter... 184