int main (int argc, const char * argv[]) { printf("4. OpenCL Profile No Overhead in the Loop\n"); float range = BIG_RANGE; float *in, *out; // ======== Initialize init_all_perfs(); create_data(&in, &out); start_perf_measurement(&total_perf); // ======== Setup OpenCL setup_cl(argc, argv, &opencl_device, &opencl_context, &opencl_queue); // ======== Setup the computation setup_cl_compute(); start_perf_measurement(&write_perf); copy_data_to_device(in, out); stop_perf_measurement(&write_perf); // ======== Compute while (range > LIMIT) { // Calculation start_perf_measurement(&update_perf); update_cl(get_in_buffer(), get_out_buffer()); stop_perf_measurement(&update_perf); // Read back the data start_perf_measurement(&read_perf); read_back_data(get_out_buffer(), out); stop_perf_measurement(&read_perf); // Compute Range start_perf_measurement(&range_perf); range = find_range(out, SIZE*SIZE); stop_perf_measurement(&range_perf); iterations++; printf("Iteration %d, range=%f.\n", iterations, range); } // ======== Finish and cleanup OpenCL start_perf_measurement(&finish_perf); clFinish(opencl_queue); stop_perf_measurement(&finish_perf); start_perf_measurement(&cleanup_perf); cleanup_cl(); stop_perf_measurement(&cleanup_perf); stop_perf_measurement(&total_perf); print_perfs(); free(in); free(out); }
/** * offfload the given task to the pipeline */ inline bool offload(void * task, unsigned int retry=((unsigned int)-1), unsigned int ticks=ff_node::TICKS2WAIT) { FFBUFFER * inbuffer = get_in_buffer(); if (inbuffer) { for(unsigned int i=0;i<retry;++i) { if (inbuffer->push(task)) return true; ticks_wait(ticks); } return false; } if (!has_input_channel) error("PIPE: accelerator is not set, offload not available\n"); else error("PIPE: input buffer creation failed\n"); return false; }
/** * The last stage output queue will be connected * to the first stage input queue (feedback channel). */ int wrap_around() { if (nodes_list.size()<2) { error("PIPE, too few pipeline nodes\n"); return -1; } fixedsize=false; // NOTE: force unbounded size for the queues! if (create_input_buffer(out_buffer_entries, fixedsize)<0) return -1; if (set_output_buffer(get_in_buffer())<0) return -1; nodes_list[0]->skip1pop = true; return 0; }