bool Doc2Vec::obj_knn_objs(const char * search, real * src, bool search_is_word, bool target_is_word, knn_item_t * knns, int k) { long long a = -1, b, c, target_size; real * search_vectors, * target, * target_vectors; Vocabulary * search_vocab, * target_vocab; search_vocab = search_is_word ? m_word_vocab : m_doc_vocab; search_vectors = search_is_word ? m_nn->m_syn0norm : m_nn->m_dsyn0norm; target_vectors = target_is_word ? m_nn->m_syn0norm : m_nn->m_dsyn0norm; target_size = target_is_word ? m_nn->m_vocab_size : m_nn->m_corpus_size; target_vocab = target_is_word ? m_word_vocab : m_doc_vocab; if(!src) { a = search_vocab->searchVocab(search); if(a < 0) return false; src = &(search_vectors[a * m_nn->m_dim]); } for(b = 0, c = 0; b < target_size; b++) { if(search_is_word == target_is_word && a == b) continue; target = &(target_vectors[b * m_nn->m_dim]); if(c < k){ knns[c].similarity = similarity(src, target); knns[c].idx = b; c++; if(c == k) top_init(knns, k); } else top_collect(knns, k, b, similarity(src, target)); } top_sort(knns, k); for(b = 0; b < k; b++) strcpy(knns[b].word, target_vocab->m_vocab[knns[b].idx].word); return true; }
int hslink_input(user_data_rec *udta, /* current user data record */ int argc, /* argument count */ char *argv[]) /* argument values */ { /* allocate application workspace if needed */ if (udta->substt == 0) { udta->appws = (workspace_rec*)mem_alloc(sizeof(workspace_rec)); if (udta->appws == 0) { cprintf("Cannot allocate workspace for user %d!\r\n",usrnum); return 0; } } /* current workspace to application workspace for this user */ current_hsws = udta->appws; /* process current substate */ switch (udta->substt) { case 0: if (top_init()) { udta->substt = 0; break; } set_defaults(); if (argc == 1) { usage("No command line given\r\n",""); udta->substt = 0; break; } if (process_options(argc,argv)) { usage("No command line given\r\n",""); udta->substt = 0; break; } ComOpen(); WS.Option.ComSpeed = ComGetSpeed(); if (!WS.Option.EffSpeed) WS.Option.EffSpeed = WS.Option.ComSpeed; /* we're now ready for SlowHandshake to work */ WS.IoLevel = 0; /* allocate up to 10k for file buffers, but no more */ WS.buffer_sizes = mem_avail()-1000>10240: 10240:mem_avail()-1000; /* display opening screen */ prepare_display(); process_filespecs(argc,argv); /* verify hardware handshake status */ if (!ComGetCts() && !WS.Option.ForceCts) { cprintf("CTS signal missing! Please use -HC or -FC option.\r\n"); WS.Option.CtsHandshake = 0; } udta->substt = 1; break; case 1: /* wait for ready handshake with remote */ service_receive(); udta->substt = wait_for_ready()? 1:2; break; case 2: /* select first file in batch and begin transmit */ udta->curnode = WS.first_send; udta->substt = 3; break; case 3: /* end of batch? change to state 4 */ if (udta->curnode == NULL) { udta->substt = 4; PSEND("%d file%s transmitted.\r\n",WS.files_sent, WS.files_sent==1?"":"s"); break; } service_receive(); if (transmit_file(udta->curnode->name)) break; /* remain in state 3 */ /* advance to next file in the batch */ udta->curnode = udta->curnode->next; break; case 4: /* wait for remaining receive activity to terminate */ service_receive(); udta->substt = finish_receive()? 4:5; break; case 5: /* close down link */ udta->substt = terminate_link()? 5:6; break; case 6: /* process exit codes */ if (ComCarrierLost()) set_cancel_link(CANCEL_CARRIER_LOST); if ((WS.files_received+WS.files_sent) ==0) set_cancel_link(CANCEL_NO_FILES); ComClose(); close_display(); cprintf("HS/Link finished! (t:%d r:%d)",WS.files_sent,WS.files_received); cprintf(" Exit code = %d\r\n",(int)WS.cancel_link); udta->substt = 0; break; } /* if substt is 0 we are done and need to free the workspace */ if (udta->substt == 0) { current_hsws = 0; mem_free(udta->appws); udta->appws = 0; } /* otherwise we need more calls- return non 0 */ return udta->substt; }
/*..........................................................................*/ QState QHsmSata_top(QHsmSata *me, QEvent const *e) { switch (e->sig) { case Q_ENTRY_SIG: BSP_display("top-ENTRY;"); return Q_HANDLED(); case Q_EXIT_SIG: BSP_display("top-EXIT;"); return Q_HANDLED(); case Q_INIT_SIG: BSP_display("top-INIT;"); top_init(me); return Q_TRAN(&QHsmSata_linkdown); case LINKUP_SIG: BSP_display("top-UP;"); me->PxSSTS = 0x123; hw_reg_begin (me->port, INTC_LINK); hw_reg_update(me->port, C_DATA, 0x0); hw_reg_update(me->port, C_PxSSTS, me->PxSSTS); hw_reg_end (me->port); return Q_TRAN(&Ht_HostIdle); case HCMD_SIG: { SataEvent *se = (SataEvent *)e; if ((se->cmd->header & 0xffff) == 0x0003) { /* cmd is x00, valid bit is 2'b11 */ BSP_display("top-CMD(ADDR);"); me->host_hdr = (struct ahci_cmd_hdr *)(se->cmd->d[0] + 0xC0000000); me->rx_fis = se->cmd->d[1]; in_irq_ack(); #ifdef MPI_TRACE hw_reg_begin (me->port, INTC_TRACE); hw_reg_update(me->port, C_DATA, __LINE__ | _QHsmSata_top<<16); hw_reg_update(me->port, 1, me->host_hdr); hw_reg_update(me->port, 2, me->rx_fis); hw_reg_end (me->port); #endif } else if ((se->cmd->header & 0xffff) == 0x1000) { /* StartComm */ /* cmd is x10, valid bit is 2'b00 */ BSP_display("top-StartComm;"); me->PxTFD = 0x7F; me->pUpdateSig = 1; pBsy_set(me, 0, 0); pDrq_set(me, 0, 1); hw_oob(me->port); in_irq_ack(); #ifdef MPI_TRACE hw_reg_begin (me->port, INTC_TRACE); hw_reg_update(me->port, C_DATA, __LINE__ | _QHsmSata_top<<16); hw_reg_end (me->port); #endif return Q_HANDLED(); } else if ((se->cmd->header & 0xffff) == 0x0200) { /* start engine */ in_irq_ack(); #ifdef MPI_TRACE hw_reg_begin (me->port, INTC_TRACE); hw_reg_update(me->port, C_DATA, __LINE__ | _QHsmSata_top<<16); hw_reg_end (me->port); #endif return Q_HANDLED(); } else { BSP_display("top-CMD(ERROR);"); hw_reg_begin (me->port, INTC_REJECT); hw_reg_update(me->port, C_DATA, 0x0); hw_reg_update(me->port, C_PxCI, se->cmd->header); hw_reg_end (me->port); in_irq_ack(); } return Q_HANDLED(); } case RX_REGFIS_SIG: BSP_display("top-RFIS(SYNC);"); rx_dma_start(me->port, 0x0, 1<<25); cx_fifo_ack(me->port, 0); hw_reg_begin (me->port, INTC_REGFIS); hw_reg_update(me->port, C_DATA, 3); hw_reg_end (me->port); return Q_HANDLED(); case RX_DATFIS_SIG: case RX_GOOD_SIG: case RX_BAD_SIG: case TX_ROK_SIG: case TX_RERR_SIG: case TX_SYNC_SIG: case TX_SRCV_SIG: BSP_display("TOP-%d(ERROR);", e->sig); hw_reg_begin (me->port, INTC_PANIC); hw_reg_update(me->port, C_DATA, 0x1); hw_reg_update(me->port, C_PxCI, e->sig); hw_reg_end (me->port); return Q_HANDLED(); } return Q_SUPER(&QHsm_top); }
//----------------------------------------------------------------- // main //----------------------------------------------------------------- int main(int argc, char **argv, char **env) { int c; int err; unsigned int loadAddr = MEM_BASE; unsigned int execAddr = MEM_BASE + MEM_EXEC_OFFSET; unsigned int breakAddr = 0xFFFFFFFF; char *filename = NULL; int help = 0; int exitcode = 0; int cycles = -1; int intr_after = -1; Verilated::commandArgs(argc, argv); while ((c = getopt (argc, argv, "f:l:c:i:b:e:")) != -1) { switch(c) { case 'l': loadAddr = strtoul(optarg, NULL, 0); break; case 'f': filename = optarg; break; case 'c': cycles = strtoul(optarg, NULL, 0); break; case 'i': intr_after = strtoul(optarg, NULL, 0); break; case 'b': breakAddr = strtoul(optarg, NULL, 0); break; case '?': default: help = 1; break; } } if (loadAddr < MEM_BASE) { fprintf (stderr,"Load address incorrect (0x%x)\n", loadAddr); exit(-1); } if (help || filename == NULL) { fprintf (stderr,"Usage:\n"); fprintf (stderr,"-t = Enable program trace\n"); fprintf (stderr,"-l 0xnnnn = Executable load address\n"); fprintf (stderr,"-f filename = Executable to load\n"); fprintf (stderr,"-c num = Max number of cycles\n"); fprintf (stderr,"-i num = Generate interrupt after num cycles\n"); fprintf (stderr,"-b addr = Break at address\n"); exit(0); } top_init(); if (strstr(filename, ".elf")) { #ifdef INCLUDE_ELF_SUPPORT if (!elf_load(filename, &execAddr)) { fprintf (stderr,"Error: Could not open ELF file %s\n", filename); exit(-1); } #else fprintf (stderr,"Error: ELF files not supported\n"); exit(-1); #endif } else { FILE *f; printf("Opening %s\n", filename); f = fopen(filename, "rb"); if (f) { long size; char *buf; // Get size fseek(f, 0, SEEK_END); size = ftell(f); rewind(f); buf = (char*)malloc(size+1); if (buf) { unsigned int addr; // Read file data in int len = fread(buf, 1, size, f); buf[len] = 0; printf("Loading to 0x%x\n", loadAddr); for (addr=0;addr<len;addr++) top_load(loadAddr + addr, buf[addr]); free(buf); fclose(f); } } else { printf("Could not read file!\n"); exit(-1); } } // Setup breakpoint to stop at (or 0xFFFFFFFF if none) top_setbreakpoint(0, breakAddr); // Run err = top_run(execAddr, cycles, intr_after); // Cleanup top_done(); printf("Exit\n"); exit((err == TOP_RES_FAULT) ? 1 : 0); }
static uint64_t run_eng_bench_real(const struct EngineInfo *info, int tnum) { int i; struct TopRotor *top; struct EngineThread *eng_list = NULL, *eng; usec_t t_launch, t_start = 0, t_end, t_now; bool warmup = true; unsigned long long total = 0; /* init generator & threads */ top = top_init(8, 12, "a-zA-Z0-9"); for (i = 0; i < tnum; i++) { eng = new_thread(info, top); eng->next = eng_list; eng_list = eng; } for (i = 0; info->sample_list[i]; i++) { add_hash(info->sample_list[i], eng_list); } for (eng = eng_list; eng; eng = eng->next) eng_run(eng); /* main loop */ t_launch = get_time(); while (1) { usleep(500000); t_now = get_time(); if (warmup) { if (t_now < t_launch + bench_warmup) continue; warmup = false; t_start = t_now; for (eng = eng_list; eng; eng = eng->next) eng->last_counter = eng->counter; } else if (t_now > t_start + bench_dur) break; } t_end = t_now; for (eng = eng_list; eng; eng = eng->next) { total += eng->counter - eng->last_counter; eng->active = 0; } /* wait for threads to finish */ while (1) { usleep(500000); for (eng = eng_list; eng; eng = eng->next) if (!eng->stopped) continue; break; } /* all done, free resources */ for (eng = eng_list; eng; ) { eng_list = eng->next; eng->info->release(eng); free(eng); eng = eng_list; } top_free(top); return (total * USEC / (t_end - t_start)); }