COIRESULT Engine::compute( _Offload_stream stream, const std::list<COIBUFFER> &buffers, const void* data, uint16_t data_size, void* ret, uint16_t ret_size, uint32_t num_deps, const COIEVENT* deps, COIEVENT* event ) /* const */ { COIBUFFER *bufs; COI_ACCESS_FLAGS *flags; COIRESULT res; // convert buffers list to array int num_bufs = buffers.size(); if (num_bufs > 0) { bufs = (COIBUFFER*) alloca(num_bufs * sizeof(COIBUFFER)); flags = (COI_ACCESS_FLAGS*) alloca(num_bufs * sizeof(COI_ACCESS_FLAGS)); int i = 0; for (std::list<COIBUFFER>::const_iterator it = buffers.begin(); it != buffers.end(); it++) { bufs[i] = *it; // TODO: this should be fixed flags[i++] = COI_SINK_WRITE; } } else { bufs = 0; flags = 0; } COIPIPELINE pipeline = (stream == no_stream) ? get_pipeline() : get_pipeline(stream); // start computation res = COI::PipelineRunFunction(pipeline, m_funcs[c_func_compute], num_bufs, bufs, flags, num_deps, deps, data, data_size, ret, ret_size, event); return res; }
void Application::quit() { std::cout << "Quitting the application." << std::endl; get_pipeline().stop(); gtk_main_quit(); }
gboolean GstPipeliner::push_thread_context(gpointer user_data) { auto context = static_cast<GstPipeliner*>(user_data); g_main_context_push_thread_default(context->main_loop_->get_main_context()); gst_bus_add_watch( gst_pipeline_get_bus(GST_PIPELINE(context->get_pipeline())), bus_watch, user_data); return FALSE; }
void* __thread_pipeline_test(void *thread_input) { char * ip = ((thread_struct*)thread_input)->in_ip; int port = ((thread_struct*)thread_input)->in_port; int my_tid = ((thread_struct*)thread_input)->tid; clusterInfo *cluster = connectRedis("192.168.1.22",6667); if(cluster == NULL) { printf("unable to connect to cluster\n"); }else { printf("connection succeed\n"); } int step = ((thread_struct*)thread_input)->step; //three steps before using a cluster mode pipeline clusterPipe *mypipe = get_pipeline(); set_pipeline_count(mypipe,PIPE_TEST_COUNT); bind_pipeline_to_cluster(cluster,mypipe); char key[256],value[256]; int count = 0; int init = (my_tid/step - 1)*step; printf("tid=%d start=%d end=%d\n",my_tid,init,my_tid); for(int i=init;i<my_tid;i++) { sprintf(key,"key=%d",i); sprintf(value,"value=%d",i); //we have a key and value here, so we can use the pipeline count++; if(count<PIPE_TEST_COUNT){ cluster_pipeline_set(cluster,mypipe,key,value); }else{ cluster_pipeline_set(cluster,mypipe,key,value); count=0; cluster_pipeline_flushBuffer(cluster,mypipe); int inner = 0; for(;inner<PIPE_TEST_COUNT;inner++) { redisReply *reply = cluster_pipeline_getReply(cluster,mypipe); if(reply == NULL) { printf("NULL reply in %d\n",i); }else{ freeReplyObject(reply); } } cluster_pipeline_complete(cluster,mypipe); reset_pipeline_count(mypipe,PIPE_TEST_COUNT); } } disconnectDatabase(cluster); return (void*)0; }
pid_t Engine::init_device(void) { struct init_data { int device_index; int devices_total; int console_level; int offload_report_level; } data; COIRESULT res; COIEVENT event; pid_t pid; OFFLOAD_DEBUG_TRACE_1(2, 0, c_offload_init, "Initializing device with logical index %d " "and physical index %d\n", m_index, m_physical_index); // setup misc data data.device_index = m_index; data.devices_total = mic_engines_total; data.console_level = console_enabled; data.offload_report_level = offload_report_level; res = COI::PipelineRunFunction(get_pipeline(), m_funcs[c_func_init], 0, 0, 0, 0, 0, &data, sizeof(data), &pid, sizeof(pid), &event); check_result(res, c_pipeline_run_func, m_index, res); res = COI::EventWait(1, &event, -1, 1, 0, 0); check_result(res, c_event_wait, res); OFFLOAD_DEBUG_TRACE(2, "Device process pid is %d\n", pid); return pid; }
void Engine::init_ptr_data(void) { COIRESULT res; COIEVENT event; // Prepare table of host entries std::vector<const VarTable::Entry*> host_table( Iterator(__offload_vars.get_head()), Iterator()); // no need to do anything further is host table is empty if (host_table.size() <= 0) { return; } // Get var table entries from the target. // First we need to get size for the buffer to copy data struct { int64_t nelems; int64_t length; } params; res = COI::PipelineRunFunction(get_pipeline(), m_funcs[c_func_var_table_size], 0, 0, 0, 0, 0, 0, 0, ¶ms, sizeof(params), &event); check_result(res, c_pipeline_run_func, m_index, res); res = COI::EventWait(1, &event, -1, 1, 0, 0); check_result(res, c_event_wait, res); if (params.length == 0) { return; } // create buffer for target entries and copy data to host COIBUFFER buffer; res = COI::BufferCreate(params.length, COI_BUFFER_NORMAL, 0, 0, 1, &m_process, &buffer); check_result(res, c_buf_create, m_index, res); COI_ACCESS_FLAGS flags = COI_SINK_WRITE; res = COI::PipelineRunFunction(get_pipeline(), m_funcs[c_func_var_table_copy], 1, &buffer, &flags, 0, 0, ¶ms.nelems, sizeof(params.nelems), 0, 0, &event); check_result(res, c_pipeline_run_func, m_index, res); res = COI::EventWait(1, &event, -1, 1, 0, 0); check_result(res, c_event_wait, res); // patch names in target data VarList::BufEntry *target_table; COIMAPINSTANCE map_inst; res = COI::BufferMap(buffer, 0, params.length, COI_MAP_READ_ONLY, 0, 0, 0, &map_inst, reinterpret_cast<void**>(&target_table)); check_result(res, c_buf_map, res); VarList::table_patch_names(target_table, params.nelems); // and sort entries std::sort(target_table, target_table + params.nelems, target_entry_cmp); std::sort(host_table.begin(), host_table.end(), host_entry_cmp); // merge host and target entries and enter matching vars map std::vector<const VarTable::Entry*>::const_iterator hi = host_table.begin(); std::vector<const VarTable::Entry*>::const_iterator he = host_table.end(); const VarList::BufEntry *ti = target_table; const VarList::BufEntry *te = target_table + params.nelems; while (hi != he && ti != te) { int res = strcmp((*hi)->name, reinterpret_cast<const char*>(ti->name)); if (res == 0) { bool is_new; // add matching entry to var map PtrData *ptr = insert_ptr_data((*hi)->addr, (*hi)->size, is_new); // store address for new entries if (is_new) { ptr->mic_addr = ti->addr; ptr->is_static = true; } ptr->alloc_ptr_data_lock.unlock(); hi++; ti++; } else if (res < 0) { hi++; } else { ti++; } } // cleanup res = COI::BufferUnmap(map_inst, 0, 0, 0); check_result(res, c_buf_unmap, res); res = COI::BufferDestroy(buffer); check_result(res, c_buf_destroy, res); }
int main(){ clusterInfo *cluster = connectRedis("192.168.1.22",6667); if(cluster == NULL) { printf("unable to connect to cluster\n"); }else{ printf("connection succeed\n"); } clusterPipe* mypipe = get_pipeline(); set_pipeline_count(mypipe,20); bind_pipeline_to_cluster(cluster,mypipe); cluster_pipeline_get(cluster,mypipe,"k1"); cluster_pipeline_get(cluster,mypipe,"k2"); cluster_pipeline_get(cluster,mypipe,"k3"); cluster_pipeline_get(cluster,mypipe,"k4"); cluster_pipeline_get(cluster,mypipe,"k5"); cluster_pipeline_get(cluster,mypipe,"k6"); cluster_pipeline_get(cluster,mypipe,"k7"); cluster_pipeline_get(cluster,mypipe,"k8"); cluster_pipeline_get(cluster,mypipe,"k9"); cluster_pipeline_get(cluster,mypipe,"k10"); cluster_pipeline_get(cluster,mypipe,"k11"); cluster_pipeline_get(cluster,mypipe,"k12"); cluster_pipeline_get(cluster,mypipe,"k13"); cluster_pipeline_get(cluster,mypipe,"k14"); cluster_pipeline_get(cluster,mypipe,"k15"); cluster_pipeline_get(cluster,mypipe,"k16"); cluster_pipeline_get(cluster,mypipe,"k17"); cluster_pipeline_get(cluster,mypipe,"k18"); cluster_pipeline_get(cluster,mypipe,"k19"); cluster_pipeline_get(cluster,mypipe,"k20"); cluster_pipeline_flushBuffer(cluster,mypipe); int i; for (i=0;i<20;i++) { redisReply* reply = cluster_pipeline_getReply(cluster,mypipe); if(reply == NULL) { printf("NULL reply\n"); continue; } printf("%s\n",reply->str); freeReplyObject(reply); } cluster_pipeline_complete(cluster,mypipe); printf("set a new pipeline hahahaha .......\n"); set_pipeline_count(mypipe,10); cluster_pipeline_get(cluster,mypipe,"k11"); cluster_pipeline_get(cluster,mypipe,"k12"); cluster_pipeline_get(cluster,mypipe,"k13"); cluster_pipeline_get(cluster,mypipe,"k14"); cluster_pipeline_get(cluster,mypipe,"k15"); cluster_pipeline_get(cluster,mypipe,"k16"); cluster_pipeline_get(cluster,mypipe,"k17"); cluster_pipeline_get(cluster,mypipe,"k18"); cluster_pipeline_get(cluster,mypipe,"k19"); cluster_pipeline_get(cluster,mypipe,"k20"); cluster_pipeline_flushBuffer(cluster,mypipe); for (i=0;i<10;i++) { redisReply* reply = cluster_pipeline_getReply(cluster,mypipe); if(reply == NULL) { printf("NULL reply\n"); continue; } printf("%s\n",reply->str); freeReplyObject(reply); } cluster_pipeline_complete(cluster,mypipe); disconnectDatabase(cluster); return 0; }