static void calibrate_click_handler_select(ClickRecognizerRef recognizer, void *context) { if (is_measuring()) stop_measure(); else start_measure((MeasureHandler) calibrate_handle_measure, (FinalMeasureHandler) calibrate_handle_final); layer_mark_dirty(icon_layer); }
static int max8925_usb_get_prop(struct power_supply *psy, enum power_supply_property psp, union power_supply_propval *val) { struct max8925_power_info *info = dev_get_drvdata(psy->dev->parent); int ret = 0; switch (psp) { case POWER_SUPPLY_PROP_ONLINE: val->intval = info->usb_online; break; case POWER_SUPPLY_PROP_VOLTAGE_NOW: if (info->usb_online) { ret = start_measure(info, MEASURE_VCHG); if (ret >= 0) { val->intval = ret * 2000; /* unit is uV */ goto out; } } ret = -ENODATA; break; default: ret = -ENODEV; break; } out: return ret; }
int main(int argc, char **argv) { read_args(argc, argv); counters timer; start_measure(timer); // declarations Complex ioB(1.0, 1.0); ioBuffer = cl::sycl::buffer<Complex,2>(cl::sycl::range<2> {M, N}); ioABuffer = cl::sycl::buffer<Complex,2>(cl::sycl::range<2> {M, N}); ioBBuffer = cl::sycl::buffer<Complex,1>(&ioB, cl::sycl::range<1> {1}); // initialization for (size_t i = 0; i < M; ++i){ for (size_t j = 0; j < N; ++j){ float tmp = (float) (i*(j+2) + 10) / N; Complex value(tmp, tmp); cl::sycl::id<2> id = {i, j}; ioBuffer.get_access<cl::sycl::access::mode::write>()[id] = value; ioABuffer.get_access<cl::sycl::access::mode::write>()[id] = value; } } // our work coef_var2D<0, 0> c1; coef_var2D<1, 0> c2; coef_var2D<0, 1> c3; coef_var2D<-1, 0> c4; coef_var2D<0, -1> c5; auto st = c1+c2+c3+c4+c5; input_var2D<Complex, &ioABuffer, &ioBBuffer, &fdl_in, &fac> work_in; output_2D<Complex, &ioBuffer, &fdl_out> work_out; auto op_work = work_out << st << work_in; auto st_id = c1.toStencil(); input_var2D<Complex, &ioBuffer, &ioBBuffer, &fdl_in, &fac_id> copy_in; output_2D<Complex, &ioABuffer, &fdl_out> copy_out; auto op_copy = copy_out << st_id << copy_in; end_init(timer); auto begin_op = counters::clock_type::now(); // compute result with "gpu" { cl::sycl::queue myQueue; for (unsigned int i = 0; i < NB_ITER; ++i){ //op_work.doComputation(myQueue); op_work.doLocalComputation(myQueue); op_copy.doComputation(myQueue); } } auto end_op = counters::clock_type::now(); timer.stencil_time = std::chrono::duration_cast<counters::duration_type>(end_op - begin_op); // loading time is not watched end_measure(timer); return 0; }
void freqcount_mainloop(void) { if (freqcount_state>=FC_DISABLED) { #if FREQCOUNT_CHANNELS > 1 // look for the next enabled channel while (!freqcount_perchannel_data[freqcount_current_channel].enabled && freqcount_current_channel_store < FREQCOUNT_CHANNELS) { freqcount_current_channel_store++; } if (freqcount_current_channel_store==FREQCOUNT_CHANNELS) { // no active channel found so wrap around freqcount_current_channel_store=0; } else { start_measure(); } #else if (freqcount_perchannel_data[freqcount_current_channel].enabled) start_measure(); #endif } else if (freqcount_state>=FC_DONE && freqcount_state<=FC_DONE_OVERFLOW4) { if (measure_done() == FC_AVERAGE_DONE) { #if FREQCOUNT_CHANNELS > 1 // this channel is done, in the next loop try the next channel freqcount_current_channel_store++; #endif } } if (check_measure_timeout()) { #if FREQCOUNT_CHANNELS > 1 // this channel is done, in the next loop try the next channel freqcount_current_channel_store++; #endif } }
static int max8925_init_charger(struct max8925_chip *chip, struct max8925_power_info *info) { int ret; REQUEST_IRQ(MAX8925_IRQ_VCHG_DC_OVP, "ac-ovp"); if (!info->no_insert_detect) { REQUEST_IRQ(MAX8925_IRQ_VCHG_DC_F, "ac-remove"); REQUEST_IRQ(MAX8925_IRQ_VCHG_DC_R, "ac-insert"); } if (!info->no_temp_support) { REQUEST_IRQ(MAX8925_IRQ_VCHG_THM_OK_R, "batt-temp-in-range"); REQUEST_IRQ(MAX8925_IRQ_VCHG_THM_OK_F, "batt-temp-out-range"); } REQUEST_IRQ(MAX8925_IRQ_VCHG_SYSLOW_F, "vsys-high"); REQUEST_IRQ(MAX8925_IRQ_VCHG_SYSLOW_R, "vsys-low"); REQUEST_IRQ(MAX8925_IRQ_VCHG_RST, "charger-reset"); REQUEST_IRQ(MAX8925_IRQ_VCHG_DONE, "charger-done"); REQUEST_IRQ(MAX8925_IRQ_VCHG_TOPOFF, "charger-topoff"); REQUEST_IRQ(MAX8925_IRQ_VCHG_TMR_FAULT, "charger-timer-expire"); info->usb_online = 0; info->bat_online = 0; /* check for power - can miss interrupt at boot time */ if (start_measure(info, MEASURE_VCHG) * 2000 > 500000) info->ac_online = 1; else info->ac_online = 0; ret = max8925_reg_read(info->gpm, MAX8925_CHG_STATUS); if (ret >= 0) { /* * If battery detection is enabled, ID pin of battery is * connected to MBDET pin of MAX8925. It could be used to * detect battery presence. * Otherwise, we have to assume that battery is always on. */ if (info->batt_detect) info->bat_online = (ret & MAX8925_CHG_MBDET) ? 0 : 1; else info->bat_online = 1; if (ret & MAX8925_CHG_AC_RANGE_MASK) info->ac_online = 1; else info->ac_online = 0; } /* disable charge */ max8925_set_bits(info->gpm, MAX8925_CHG_CNTL1, 1 << 7, 1 << 7); /* set charging current in charge topoff mode */ max8925_set_bits(info->gpm, MAX8925_CHG_CNTL1, 3 << 5, info->topoff_threshold << 5); /* set charing current in fast charge mode */ max8925_set_bits(info->gpm, MAX8925_CHG_CNTL1, 7, info->fast_charge); return 0; }
void stress() { int i; configure_all_pc("label1"); start_measure("label1"); while(i < 100000000) { sqrt(rand()); i++; } stop_measure("label1"); }
void *rhythms_memory_new(t_symbol *s, int argc, t_atom *argv) { int i; time_t a; t_rhythms_memory *x = (t_rhythms_memory *)pd_new(rhythms_memory_class); // first is for bangs (to let this external play in realtime //x->l_out = outlet_new(&x->x_obj, &s_list); x->bangs_out = outlet_new(&x->x_obj, gensym("bang")); // this outputs lists of events x->list_out = outlet_new(&x->x_obj, gensym("symbol")); // this outputs info on the last detected rhythm x->info_out = outlet_new(&x->x_obj, gensym("symbol")); // inlet for rhythms in the form of lists inlet_new(&x->x_obj, &x->x_obj.ob_pd, gensym("list"), gensym("rhythm_in")); x->x_clock = clock_new(x, (t_method)rhythms_tick); x->seq_initialized = 0; rhythm_memory_create(&(x->rhythms_memory)); start_measure(x); return (x); }
void run_tests() { int i = 0, d = 0, k = 0; //int cpus = 0; int ncpus; state* s; get_init_state = get_init_stateI; get_moves_for_game_state = get_moves_for_game_stateI; get_state_for_move_and_game_state = get_state_for_move_and_game_stateI; evaluate_game_state = evaluate_game_stateI; free_state = free_stateI; free_moves = free_movesI; size_move = size_moveI; ncpus = sysconf(_SC_NPROCESSORS_ONLN); if(ncpus == -1) ncpus = 2; s = init_game(); printf("#ncpus %d\n", ncpus); printf("avg_seconds avg_num_exp avg_num_disc avg_num_evaluated avg_num_seen avg_branch_factor avg_num_theory avg_percent_seen\n"); for(d = 3; d < 7; d++) { max_depth = d; printf("#depth %d\n", max_depth); for(i = 0; i < ncpus; i++) { num_threads = i+1; printf("#threads %d\n", num_threads); double num_theory = 0.0; avg_seconds = 0.0; avg_num_exp = 0.0; avg_num_disc = 0.0; avg_seconds = 0.0; avg_num_exp = 0.0; avg_num_disc = 0.0; avg_num_evaluated = 0.0; avg_num_seen = 0.0; avg_branch_factor = 0.0; num_theory = 0.0; avg_num_theory = 0.0; avg_percent_seen = 0.0; for(k = 0; k < STAB; k++) { //display_board(stdout, 0, s); //i start_measure(); move* m = (move*)think((void*)s); stop_measure(); //print_measure(); free(m); avg_seconds += FSTAB*(((double)total.tv_sec) + (((double)total.tv_usec)/1000000.0)); avg_num_exp += FSTAB*((double)num_nodes_expanded); avg_num_disc += FSTAB*((double)num_nodes_discarded); avg_num_evaluated += FSTAB*((double)num_nodes_evaluated); avg_num_seen += FSTAB*((double)num_nodes_seen); avg_branch_factor += FSTAB*((double)branching_factor); num_theory = pow(branching_factor, (double)d); avg_num_theory += FSTAB*((double)num_theory); avg_percent_seen += FSTAB*(((double)num_nodes_seen)/(num_theory)); } printf("%f %f %f %f %f %f %f %f\n", avg_seconds, avg_num_exp, avg_num_disc, avg_num_evaluated, avg_num_seen, avg_branch_factor, avg_num_theory, avg_percent_seen); } } free(s); }
static int max8925_bat_get_prop(struct power_supply *psy, enum power_supply_property psp, union power_supply_propval *val) { struct max8925_power_info *info = dev_get_drvdata(psy->dev->parent); int ret = 0; switch (psp) { case POWER_SUPPLY_PROP_ONLINE: val->intval = info->bat_online; break; case POWER_SUPPLY_PROP_VOLTAGE_NOW: if (info->bat_online) { ret = start_measure(info, MEASURE_VMBATT); if (ret >= 0) { val->intval = ret * 2000; /* unit is uV */ ret = 0; break; } } ret = -ENODATA; break; case POWER_SUPPLY_PROP_CURRENT_NOW: if (info->bat_online) { ret = start_measure(info, MEASURE_ISNS); if (ret >= 0) { /* assume r_sns is 0.02 */ ret = ((ret * 6250) - 3125) /* uA */; val->intval = 0; if (ret > 0) val->intval = ret; /* unit is mA */ ret = 0; break; } } ret = -ENODATA; break; case POWER_SUPPLY_PROP_CHARGE_TYPE: if (!info->bat_online) { ret = -ENODATA; break; } ret = max8925_reg_read(info->gpm, MAX8925_CHG_STATUS); ret = (ret & MAX8925_CHG_STAT_MODE_MASK) >> 2; switch (ret) { case 1: val->intval = POWER_SUPPLY_CHARGE_TYPE_FAST; break; case 0: case 2: val->intval = POWER_SUPPLY_CHARGE_TYPE_TRICKLE; break; case 3: val->intval = POWER_SUPPLY_CHARGE_TYPE_NONE; break; } ret = 0; break; case POWER_SUPPLY_PROP_STATUS: if (!info->bat_online) { ret = -ENODATA; break; } ret = max8925_reg_read(info->gpm, MAX8925_CHG_STATUS); if (info->usb_online || info->ac_online) { val->intval = POWER_SUPPLY_STATUS_NOT_CHARGING; if (ret & MAX8925_CHG_STAT_EN_MASK) val->intval = POWER_SUPPLY_STATUS_CHARGING; } else val->intval = POWER_SUPPLY_STATUS_DISCHARGING; ret = 0; break; default: ret = -ENODEV; break; } return ret; }
float gpuEncode(EntropyCodingTaskInfo *infos, type_image *img, int count, int targetSize) { int codeBlocks = count; int maxOutLength = /*MAX_CODESTREAM_SIZE*/(1 << img->cblk_exp_w) * (1 << img->cblk_exp_h) * 14; // long int start_bebcot = start_measure(); int n = 0; for(int i = 0; i < codeBlocks; i++) n += infos[i].width * infos[i].height; mem_mg_t *mem_mg = img->mem_mg; CodeBlockAdditionalInfo *h_infos = (CodeBlockAdditionalInfo *)mem_mg->alloc->host(sizeof(CodeBlockAdditionalInfo) * codeBlocks, mem_mg->ctx); byte *d_cxd_pairs = (byte *)mem_mg->alloc->dev(sizeof(byte) * codeBlocks * maxOutLength, mem_mg->ctx); CodeBlockAdditionalInfo *d_infos = (CodeBlockAdditionalInfo *)mem_mg->alloc->dev(sizeof(CodeBlockAdditionalInfo) * codeBlocks, mem_mg->ctx); int magconOffset = 0; for(int i = 0; i < codeBlocks; i++) { h_infos[i].width = infos[i].width; h_infos[i].height = infos[i].height; h_infos[i].nominalWidth = infos[i].nominalWidth; h_infos[i].stripeNo = (int) ceil(infos[i].height / 4.0f); h_infos[i].subband = infos[i].subband; h_infos[i].magconOffset = magconOffset + infos[i].width; h_infos[i].magbits = infos[i].magbits; h_infos[i].coefficients = infos[i].coefficients; h_infos[i].compType = infos[i].compType; h_infos[i].dwtLevel = infos[i].dwtLevel; h_infos[i].stepSize = infos[i].stepSize; magconOffset += h_infos[i].width * (h_infos[i].stripeNo + 2); } GPU_JPEG2K::CoefficientState *d_stBuffors = (GPU_JPEG2K::CoefficientState *)mem_mg->alloc->dev(sizeof(GPU_JPEG2K::CoefficientState) * magconOffset, mem_mg->ctx); CHECK_ERRORS(cudaMemset((void *) d_stBuffors, 0, sizeof(GPU_JPEG2K::CoefficientState) * magconOffset)); cuda_memcpy_htd(h_infos, d_infos, sizeof(CodeBlockAdditionalInfo) * codeBlocks); // printf("before launch encode: %d\n", stop_measure(start_bebcot)); long int start_ebcot = start_measure(); if(targetSize == 0) { //printf("No pcrd\n"); CHECK_ERRORS(GPU_JPEG2K::launch_encode((int) ceil((float) codeBlocks / THREADS), THREADS, d_stBuffors, d_cxd_pairs, maxOutLength, d_infos, codeBlocks, mem_mg)); } else { // printf("Pcrd\n"); CHECK_ERRORS(GPU_JPEG2K::launch_encode_pcrd((int) ceil((float) codeBlocks / THREADS), THREADS, d_stBuffors, maxOutLength, d_infos, codeBlocks, targetSize, mem_mg)); } // printf("launch encode: %d\n", stop_measure(start_ebcot)); // long int start_mqc = start_measure(); cuda_memcpy_dth(d_infos, h_infos, sizeof(CodeBlockAdditionalInfo) * codeBlocks); img->codestream = mqc_gpu_encode(infos, h_infos, codeBlocks, d_cxd_pairs, maxOutLength, mem_mg); // printf("mqc: %d\n", stop_measure(start_mqc)); // long int start_aebcot = start_measure(); for(int i = 0; i < codeBlocks; i++) { infos[i].significantBits = h_infos[i].significantBits; infos[i].codingPasses = h_infos[i].codingPasses; /*if(h_infos[i].length > 0) { infos[i].length = h_infos[i].length; int len = h_infos[i].length; infos[i].codeStream = (byte *) malloc(sizeof(byte) * len); cuda_memcpy_dth(d_outbuf + i * maxOutLength, infos[i].codeStream, sizeof(byte) * len); } else { infos[i].length = 0; infos[i].codeStream = NULL; }*/ } mem_mg->dealloc->dev(d_stBuffors, mem_mg->ctx); mem_mg->dealloc->dev(d_infos, mem_mg->ctx); mem_mg->dealloc->dev(d_cxd_pairs, mem_mg->ctx); mem_mg->dealloc->host(h_infos, mem_mg->ctx); // printf("after launch encode: %d\n", stop_measure(start_aebcot)); float elapsed = 0.0f; return elapsed; }
int main(int argc, char **argv) { read_args(argc, argv); struct counters timer; start_measure(timer); // declarations float tab_var = 1.0; float *ioB = &tab_var; ioBuffer = cl::sycl::buffer<float,2>(cl::sycl::range<2> {M, N}); ioABuffer = cl::sycl::buffer<float,2>(cl::sycl::range<2> {M, N}); ioBBuffer = cl::sycl::buffer<float,1>(ioB, cl::sycl::range<1> {1}); #if DEBUG_STENCIL float *a_test = (float *) malloc(sizeof(float)*M*N); float *b_test = (float *) malloc(sizeof(float)*M*N); #endif // initialization for (size_t i = 0; i < M; ++i){ for (size_t j = 0; j < N; ++j){ float value = ((float) i*(j+2) + 10) / N; cl::sycl::id<2> id = {i, j}; ioBuffer.get_access<cl::sycl::access::mode::write, cl::sycl::access::target::host_buffer>()[id] = value; ioABuffer.get_access<cl::sycl::access::mode::write, cl::sycl::access::target::host_buffer>()[id] = value; #if DEBUG_STENCIL a_test[i*N+j] = value; b_test[i*N+j] = value; #endif } } // our work coef_var2D<0, 0> c1; coef_var2D<1, 0> c2; coef_var2D<0, 1> c3; coef_var2D<-1, 0> c4; coef_var2D<0, -1> c5; auto st = c1+c2+c3+c4+c5; input_var2D<float, &ioABuffer, &ioBBuffer, &fdl_in, &fac> work_in; output_2D<float, &ioBuffer, &fdl_out> work_out; auto op_work = work_out << st << work_in; auto st_id = c1.toStencil(); input_var2D<float, &ioBuffer, &ioBBuffer, &fdl_in, &fac_id> copy_in; output_2D<float, &ioABuffer, &fdl_out> copy_out; auto op_copy = copy_out << st_id << copy_in; end_init(timer); struct op_time time_op; begin_op(time_op); // compute result with "gpu" { cl::sycl::queue myQueue; for (unsigned int i = 0; i < NB_ITER; ++i){ //op_work.doComputation(myQueue); op_work.doLocalComputation(myQueue); op_copy.doComputation(myQueue); } } end_op(time_op, timer.stencil_time); // loading time is not watched end_measure(timer); #if DEBUG_STENCIL // get the gpu result auto C = (ioABuffer).get_access<cl::sycl::access::mode::read, cl::sycl::access::target::host_buffer>(); ute_and_are(a_test,b_test,C); free(a_test); free(b_test); #endif return 0; }
// called when a measure ends void end_measure(t_rhythms_memory *x) { float fduration; event *currEvent, *lastEvent; unsigned short int is_it_a_new_rhythm; unsigned short int id, subid; float root_closeness, sub_closeness; int counter; t_atom *lista; // these 2 are for output rhythm int rhythm_found; t_rhythm_event *wanted_rhythm; t_rhythm_event *curr_rhythm; event *lastOutEvent; // I call the pd functions to get a representation // of this very moment x->measure_length = clock_gettimesince(x->measure_start_time); // now that i know the exact length of the current measure // i can process the rhythm in the current measure // and evaluate it currEvent = x->events; // this is not the first event // now I translate events in rhythm counter = 0; while(currEvent) { fduration = (float) (((float) currEvent->when) / ((float) x->measure_length)); if (x->seq_initialized) { concatenateBeat(x->curr_seq, currEvent->voice, fduration, 1); } else { setFirstBeat(&(x->curr_seq), currEvent->voice, fduration, 1); x->seq_initialized = 1; } currEvent = currEvent->next; counter++; } // delete events after having evaluated them currEvent = x->events; // this is not the first event while(currEvent) { lastEvent = currEvent; currEvent = currEvent->next; free(lastEvent); } x->events = 0; if (x->curr_seq) { // now I evaluate this rhythm with the memory rhythm_memory_evaluate(x->rhythms_memory, x->curr_seq, &is_it_a_new_rhythm, &id, &subid, &root_closeness, &sub_closeness); // tell out the answer // allocate space for the list lista = (t_atom *) malloc(sizeof(t_atom) * 5); SETFLOAT(lista, (float) is_it_a_new_rhythm); SETFLOAT(lista+1, (float) id); SETFLOAT(lista+2, (float) subid); SETFLOAT(lista+3, (float) root_closeness); SETFLOAT(lista+4, (float) sub_closeness); outlet_anything(x->info_out, gensym("list") , 5, lista); free(lista); // rhythm_memory_evaluate freed the memory for the rhythm if needed x->seq_initialized = 0; x->curr_seq = 0; } // I free the list of events_out (if present) currEvent = x->events_out; // this is not the first event while(currEvent) { lastEvent = currEvent; currEvent = currEvent->next; free(lastEvent); } x->events_out = 0; // i set up the list of events_out // for the wanted rhythm if (x->next_main_rhythm_out) { wanted_rhythm = 0; // ask the memory for the wanted rhythm rhythm_found = rhythm_memory_get_rhythm(x->rhythms_memory, // the memory &wanted_rhythm, // a pointer to the returned rhythm // the id of the main rhythm wanted x->next_main_rhythm_out, // the sub-id of the sub-rhythm wanted x->next_sub_rhythm_out); if (rhythm_found==0) { post("rhythms_memory: rhythm %i %i was not found ", x->next_main_rhythm_out, x->next_sub_rhythm_out); return; } if (wanted_rhythm==0) { error("rhythms_memory: wanted_rhythm should not be null! "); return; } // now I setup the events_out list // for each event in wanted_rhythm // allocate and link an element of elements_out curr_rhythm = wanted_rhythm; lastOutEvent = 0; while (curr_rhythm) { event *newEvent; newEvent = malloc(sizeof(event)); newEvent->next = 0; newEvent->voice = curr_rhythm->voice; newEvent->when = (double) (duration2float(curr_rhythm->start) * x->measure_length); post("DEBUG: add event in moment: %f", newEvent->when); if (x->events_out) { // this is not the first event // assign the next lastOutEvent->next = newEvent; } else { // this is the first event x->events_out = newEvent; } // change the last pointer lastOutEvent = newEvent; curr_rhythm = curr_rhythm->next; } // also setup the timer for the first event if (x->events_out) { // setup the clock clock_delay(x->x_clock, x->events_out->when); // remember when next event will occour x->last_event_out_time = x->events_out->when; // remember the curr event lastOutEvent = x->events_out; //reassign next event x->events_out = x->events_out->next; // free old event free(lastOutEvent); } x->next_main_rhythm_out = 0; } // also start the new measure! start_measure(x); }