/** \brief This function can read the configuration space of the MACPHY * For this purpose, the EEPROM interface is used. No direct access * to the flash memory will be done. * @param *dev Pointer to the PCI device of this MACPHY * @param address Address inside the flash where reading will start * @param count Number of words (16 bit values) to read * @param *buffer Pointer to the buffer where to store read data * @return void I210_NO_ERROR or an error code */ static u32 read_flash(struct device *dev, u32 address, u32 count, u16 *buffer) { u32 bar; u32 *eeprd; u32 i; /* Get the BAR to memory mapped space*/ bar = pci_read_config32(dev, PCI_BASE_ADDRESS_0); if ((!bar) || ((address + count) > 0x40)) return I210_INVALID_PARAM; eeprd = (u32*)(bar + I210_REG_EEREAD); /* Prior to start ensure flash interface is ready by checking DONE-bit */ if (wait_done(eeprd, I210_DONE)) return I210_NOT_READY; /*OK, interface is ready, we can use it now */ for (i = 0; i < count; i++) { /* To start a read cycle write desired address in bits 12..2 */ *eeprd = ((address + i) << 2) & 0x1FFC; /* Wait until read is done */ if (wait_done(eeprd, I210_DONE)) return I210_READ_ERROR; /* Here, we can read back desired word in bits 31..16 */ buffer[i] = (*eeprd & 0xffff0000) >> 16; } return I210_SUCCESS; }
static void goto_first_line(void) { int16_t a, x, y; aversive_get_pos(&aversive_device, &a, &x, &y); if (is_red) x = 500; else x = 3000 - 500; aversive_goto_xy_abs(&aversive_device, x, y); wait_done(); }
void unit_center(void) { igreboard_get_color_switch(&igreboard_device, &is_red); first_pos(); goto_first_line(); aversive_goto_xy_abs(&aversive_device, 3000 / 2, 2100 / 2); wait_done(); }
void unit_aversive(void) { int16_t a, x, y; aversive_goto_xy_abs(&aversive_device, 100, 100); wait_done(&aversive_device); aversive_get_pos(&aversive_device, &a, &x, &y); lcd_string(3, 0, uint16_to_string((uint16_t)x)); lcd_string(3, 30, uint16_to_string((uint16_t)y)); }
/** \brief This function can write the configuration space of the MACPHY * For this purpose, the EEPROM interface is used. No direct access * to the flash memory will be done. This function will update * the checksum after a value was changed. * @param *dev Pointer to the PCI device of this MACPHY * @param address Address inside the flash where writing will start * @param count Number of words (16 bit values) to write * @param *buffer Pointer to the buffer where data to write is stored in * @return void I210_NO_ERROR or an error code */ static u32 write_flash(struct device *dev, u32 address, u32 count, u16 *buffer) { u32 bar; u32 *eepwr; u32 *eectrl; u16 checksum; u32 i; /* Get the BAR to memory mapped space */ bar = pci_read_config32(dev, 0x10); if ((!bar) || ((address + count) > 0x40)) return I210_INVALID_PARAM; eepwr = (u32*)(bar + I210_REG_EEWRITE); eectrl = (u32*)(bar + I210_REG_EECTRL); /* Prior to start ensure flash interface is ready by checking DONE-bit */ if (wait_done(eepwr, I210_DONE)) return I210_NOT_READY; /* OK, interface is ready, we can use it now */ for (i = 0; i < count; i++) { /* To start a write cycle write desired address in bits 12..2 */ /* and data to write in bits 31..16 into EEWRITE-register */ *eepwr = ((((address + i) << 2) & 0x1FFC) | (buffer[i] << 16)); /* Wait until write is done */ if (wait_done(eepwr, I210_DONE)) return I210_WRITE_ERROR; } /* Since we have modified data, we need to update the checksum */ if (compute_checksum(dev, &checksum)) return I210_CHECKSUM_ERROR; *eepwr = (0x3f << 2) | checksum << 16; if (wait_done(eepwr, I210_DONE)) return I210_WRITE_ERROR; /* Up to now, desired data was written into shadowed RAM. We now need */ /* to perform a flash cycle to bring the shadowed RAM into flash memory. */ /* To start a flash cycle we need to set FLUPD-bit and wait for FLDONE. */ *eectrl = *eectrl | I210_FLUPD; if (wait_done(eectrl, I210_FLUDONE)) return I210_FLASH_UPDATE_ERROR; return I210_SUCCESS; }
bool MTFloatRun(Node * node) { std::vector<sub_op_task> task_list; for(int i=0;i<cpu_info->GetCPUNumber()*2;i++) { sub_op_task task; task.exec_func=std::bind(&DemoOps::FloatAider,this,std::placeholders::_1, std::placeholders::_2,std::placeholders::_3); task.seq=i; task.data=(void *)((unsigned long)i); task_list.push_back(task); } task_dispatch(task_list,-1); wait_done(); return true; }
int main(void) { pthread_t thrd[3]; int done = 0; mill_pipe p[3]; mill_init(-1, -1); chan ch = chmake(int, 1); mill_wgroup wg = mill_wgmake(); int j; for (j = 0; j < 3; j++) { p[j] = mill_pipemake(sizeof (int)); go(recv_chs(p[j], chdup(ch), wg)); pthread_create(&thrd[j], NULL, produce, mill_pipedup(p[j])); } /* wait for all reader coroutines to finish and then close the channel */ go(wait_done(ch, wg)); while (! done) { choose { in(ch, int, val): printf(" %d", val); done = ! val; otherwise: yield(); end } } printf("\n"); for (j = 0; j < 3; j++) { pthread_join(thrd[j], NULL); mill_pipefree(p[j]); } mill_wgfree(wg); chclose(ch); mill_fini(); return 0; }
bool Run(Node * node) { const Tensor * input_tensor=node->GetInputTensor(0); Tensor * output_tensor=node->GetOutputTensor(0); const TShape& shape=input_tensor->GetShape(); const std::vector<int> dims=shape.GetDim(); int batch_number=dims[0]; int channel_num=dims[1]; int channel_size=dims[2]*dims[3]; Tensor * gamma_tensor=node->GetInputTensor(1); Tensor * beta_tensor=node->GetInputTensor(2); Tensor * mean_tensor=node->GetInputTensor(3); Tensor * var_tensor=node->GetInputTensor(4); float * gamma=(float *)get_tensor_mem(gamma_tensor); float * beta=(float *)get_tensor_mem(beta_tensor); float * mean=(float *)get_tensor_mem(mean_tensor); float * var=(float *)get_tensor_mem(var_tensor); const float * input=(const float *)get_tensor_mem(input_tensor); float * output=(float *)get_tensor_mem(output_tensor); int cpu_number=cpu_info->GetCPUNumber(); for(int i=0;i<batch_number;i++) { if(cpu_number==1) { bn_scale_relu_neon(input,gamma,beta,mean,var,channel_num,channel_size,output); input+=channel_size*channel_num; output+=channel_size*channel_num; } else { std::vector<sub_op_task> task_list; std::vector<BNParam> param_list; auto f=std::bind(&FusedOps::Aider,this,std::placeholders::_1, std::placeholders::_2,std::placeholders::_3); int step=(channel_num+(cpu_number-1))/cpu_number; if(channel_num-(cpu_number-1)*step<=0) step=channel_num/cpu_number; task_list.resize(cpu_number); param_list.resize(cpu_number); for(int i=0;i<cpu_number;i++) { BNParam * param=¶m_list[i]; sub_op_task * task=&task_list[i]; task->exec_func=f; task->seq=i; task->data=param; param->input=input; param->gamma=gamma; param->beta=beta; param->mean=mean; param->var=var; param->channel_num=step; param->channel_size=channel_size; param->output=output; input+=channel_size*step; output+=channel_size*step; gamma+=step; beta+=step; mean+=step; var+=step; } param_list[cpu_number-1].channel_num=channel_num-(cpu_number-1)*step; task_dispatch(task_list,-1); wait_done(); } /* the c code of assembly code for(int c=0;c<channel_num;c++) { float s_mean=mean[c]; float s_var=var[c]; float s_gamma=gamma[c]; float s_beta=beta[c]; for(int l=0;l<channel_size;l++) { float data=input[l]; data=data*s_var+s_mean; data=data*s_gamma+s_beta; if(data<0.0) data=0; output[l]=data; } input+=channel_size; output+=channel_size; } */ } return true; }