void load_engine(int engine_id){ if (-1!=cur_engine){ max_unload(max_engines[cur_engine]); } max_engines[engine_id] = max_load(max_files[engine_id],"*"); cur_engine = engine_id; }
bool LSH_DFE::prepare_max_file(){ cout<<"----------loading DFE----------"<<endl; mf = LSH_init(); bool check = check_parameters(); if(!check) return false; me = max_load(mf, "*"); cout<<"----------loading DFE finished----------"<<endl; return true; }
unsigned int simplex(const int m, const int n, lp_t * p) { // init DFE max_file_t * maxfile = Simplex_init(); max_engine_t * engine = max_load(maxfile, "*"); // align for streaming int align_m, align_n; lp_t * align_p = copy_aligned(m, n, p, &align_m, &align_n); if (trace > 0) printf("aligned: %dx%d -> %dx%d\n", m, n, align_m, align_n); // reserve buffers lp_t * pivcol = (lp_t *) malloc(align_m * sizeof(lp_t)); lp_t * pivrow = (lp_t *) malloc(align_n * sizeof(lp_t)); // Simplex action to call DFE Simplex_actions_t act; act.param_m = align_m; act.param_n = align_n; act.instream_pivcol = pivcol; act.instream_pivrow = pivrow; act.instream_x = align_p; act.outstream_y = align_p; // main loop unsigned int count = 0; while (count < max_iterations || max_iterations == 0) { // column int col = pivot_rule == 0 ? find_pivot_column_first(align_n, align_p) : find_pivot_column_max(align_n, align_p); if (col < 0) break; // optimum found // row int row = find_pivot_row(align_m, align_n, align_p, col); if (row < 0) { align_p[0] = NAN; break; } // unbounded // pivoting count++; lp_t pivot = align_p[row * align_n + col]; if (trace > 0) printf("%d: pivoting on %d, %d: %"lp_t_fmt1"\n", count, row, col, pivot); // store pivcol & pivrow for DFE streaming for (int i = 0; i < align_m; i++) pivcol[i] = align_p[i * align_n + col]; for (int j = 0; j < align_n; j++) pivrow[j] = align_p[row * align_n + j]; // call DFE for pivoting act.param_row = row; act.param_col = col; act.param_pivot = 1 / pivot; Simplex_run(engine, &act); // tracing if (trace >= 9) write_bg(stdout, m, n, p); if (trace >= 2) print_obj(n, p); if (trace >= 3) print_bounds(m, n, p); } // unload DFE max_unload(engine); // free buffers free(pivcol); free(pivrow); p[0] = align_p[0]; return count; }
int main(int argc, char *argv[]) { if (argc < 4) { printf("Syntax: %s <TOP local IP> <BOT local IP> <forward IP>\n", argv[0]); return 1; } struct in_addr top_ip; struct in_addr bot_ip; struct in_addr fwd_ip; struct in_addr netmask; inet_aton(argv[1], &top_ip); inet_aton(argv[2], &bot_ip); inet_aton(argv[3], &fwd_ip); inet_aton("255.255.255.0", &netmask); uint16_t port = 7653; printf("EthFwd: TOP IP '%s', BOT IP '%s', Forward IP '%s', port %u\n", argv[1], argv[2], argv[3], port); max_file_t *maxfile = EthFwd_init(); max_engine_t * engine = max_load(maxfile, "*"); max_ip_config(engine, MAX_NET_CONNECTION_QSFP_TOP_10G_PORT1, &top_ip, &netmask); max_ip_config(engine, MAX_NET_CONNECTION_QSFP_BOT_10G_PORT1, &bot_ip, &netmask); struct ether_addr local_mac2, remote_mac2; max_arp_lookup_entry(engine, MAX_NET_CONNECTION_QSFP_BOT_10G_PORT1, &fwd_ip, &remote_mac2); max_eth_get_default_mac_address(engine, MAX_NET_CONNECTION_QSFP_BOT_10G_PORT1, &local_mac2); uint64_t localMac = 0, forwardMac = 0; memcpy(&localMac, &local_mac2, 6); memcpy(&forwardMac, &remote_mac2, 6); max_config_set_bool(MAX_CONFIG_PRINTF_TO_STDOUT, true); max_actions_t *action = max_actions_init(maxfile, NULL); max_set_uint64t(action, "fwdKernel", "localIp", bot_ip.s_addr); max_set_uint64t(action, "fwdKernel", "forwardIp", fwd_ip.s_addr); max_set_uint64t(action, "fwdKernel", "localMac", localMac); max_set_uint64t(action, "fwdKernel", "forwardMac", forwardMac); max_set_uint64t(action, "fwdKernel", "port", port); max_run(engine, action); printf("JDFE Running.\n"); getchar(); max_unload(engine); max_file_free(maxfile); printf("Done.\n"); return 0; }
int main(void) { printf("Loading image from '%s'\n", in_filename); uint8_t *in_data; uint64_t width, height; loadImage(in_filename, &in_data, &width, &height); uint64_t data_size = width * height * 3; uint8_t *out_data = malloc(data_size); printf("Configuring DFE with full bitstream\n"); max_file_t *maxfile = PRImageFilter_init(); max_engine_t *engine = max_load(maxfile, "*"); printf("Running DFE\n"); PRImageFilter_actions_t myaction = { data_size, in_data, out_data }; PRImageFilter_run(engine, &myaction); printf("Partially reconfiguring DFE\n"); max_reconfig_partial_bitstream(engine, "EdgeLaplaceKernel"); max_reconfig_partial_bitstream(engine, "ThresholdKernel"); printf("Running DFE\n"); myaction.instream_input = out_data; PRImageFilter_run(engine, &myaction); max_unload(engine); printf("Saving image to '%s'\n", out_filename); writeImage(out_filename, out_data, width, height); printf("Checking result against '%s'\n", golden_filename); int ret = checkResult(out_data); if (!ret) printf("Result correct\n"); else printf("Result incorrect\n"); free(in_data); free(out_data); return ret; }
/** * Constructor takes a string where a plan is contained and a pointer to a domain object, parses the plan and sets up unrolled arrays for streaming to DFE */ AirfoilDFEInterface::AirfoilDFEInterface(std::string planfile, AirfoilDFEDomain * domain_) { domain = domain_; nEdgeComputeDFE = (*domain).nedgecomputedfe; nCellComputeDFE = (*domain).ncellcomputedfe; maxfile = airfoildfe_init(); engine = max_load(maxfile,"*"); memAddresses = (int * ) malloc(sizeof(int)*(MEM_ADDRESS_ITEMS+1)); parsePlan(planfile); int cumulativeAddress = 0; memAddresses[adtDx] = cumulativeAddress*burstSize; int floatBits = max_get_constant_uint64t(maxfile,"floatBits"); int adtDxBursts = getNBursts(floatBits, nCellComputeDFE*12); cumulativeAddress += adtDxBursts; memAddresses[resReadOnly] = cumulativeAddress*burstSize; int resReadOnlyBursts = getNBursts(resReadOnlyBits, nEdgeComputeDFE); cumulativeAddress += resReadOnlyBursts; memAddresses[q] = cumulativeAddress*burstSize; int qBursts = getNBursts(floatBits, nCellComputeDFE*4); cumulativeAddress += qBursts; memAddresses[qold] = cumulativeAddress*burstSize; cumulativeAddress += qBursts; memAddresses[MEM_ADDRESS_ITEMS] = cumulativeAddress*burstSize; qpadtPortWidth = max_get_constant_uint64t(maxfile, "qpadtPortPCIeWidthInBytes"); ; printf("Generated lmem addresses, sizes:\n"); for (int i = 0; i < MEM_ADDRESS_ITEMS; i++) printf("%d,%d\n",memAddresses[i], memAddresses[i+1]- memAddresses[i]); printf("\n"); }
int main(void) { const int no = 50; const int k = 2; const int row = 24; const int col = 24; const int batch_size = 384; int z2_offset = 0; int z2_size = no*row*col*batch_size*sizeof(real); int sel_offset = z2_offset+z2_size; int sel_size = no*row*col*batch_size/8; int z_offset = sel_offset+sel_size; int z_size = no*row*col/k/k*batch_size*sizeof(real); int a_offset = z_offset+z_size; int a_size = no*row*col/k/k*batch_size*sizeof(real); real* z2 = (real*)malloc(z2_size); uchar* sel = (uchar*)malloc(sel_size); real* z = (real*)malloc(z_size); real* a = (real*)malloc(a_size); max_file_t *maxfile = CNN_FW_MaxPool_V0_DP_L0_0_init(); max_engine_t *engine = max_load(maxfile, "*"); printf("Writing to LMem.\n"); max_actions_t* act = max_actions_init(maxfile, "writeLMem"); max_set_param_uint64t(act, "offset", z2_offset); max_set_param_uint64t(act, "size", z2_size); max_queue_input(act, "cpu_to_lmem_at_cpu", z2, z2_size); max_run(engine, act); printf("Running on DFE.\n"); act = max_actions_init(maxfile, "default"); max_set_param_uint64t(act, "no", no); max_set_param_uint64t(act, "z2_offset", z2_offset); max_set_param_uint64t(act, "sel_offset", sel_offset); max_set_param_uint64t(act, "z_offset", z_offset); max_set_param_uint64t(act, "a_offset", a_offset); max_run(engine, act); printf("Reading from LMemBytes.\n"); act = max_actions_init(maxfile, "readLMemBytes"); max_set_param_uint64t(act, "offset", sel_offset); max_set_param_uint64t(act, "size", sel_size); max_queue_output(act, "lmem_to_cpu_at_cpu", sel, sel_size); max_run(engine, act); printf("Reading from LMem.\n"); act = max_actions_init(maxfile, "readLMem"); max_set_param_uint64t(act, "offset", z_offset); max_set_param_uint64t(act, "size", z_size); max_queue_output(act, "lmem_to_cpu_at_cpu", z, z_size); max_run(engine, act); printf("Reading from LMem.\n"); act = max_actions_init(maxfile, "readLMem"); max_set_param_uint64t(act, "offset", a_offset); max_set_param_uint64t(act, "size", a_size); max_queue_output(act, "lmem_to_cpu_at_cpu", a, a_size); max_run(engine, act); max_unload(engine); printf("Done.\n"); free(z2); free(sel); free(z); free(a); return 0; }
int main() { const int padH = Top_pad; const int padW = Top_pad; const int kH = Top_k; const int kW = Top_k; const int stride = Top_stride; int inH = 7;//get_min_in(padH,kH,stride); int inW = 7;//get_min_in(padW,kW,stride); printf("inH,inW=%d,%d\n",inH,inW); const int NY = inH+2*padH; const int NX = inW+2*padW; const float kernel[kH*kW] = {0,1,0,1,2,1,0,1,0}; int paddedH = inH+2*padH; int paddedW = inW+2*padW; int outH = 1+(paddedH-kH)/stride; int outW = 1+(paddedW-kW)/stride; uint32_t inSizeBytes = adjust(inH * inW*sizeof(float),384); uint32_t outSizeBytes = adjust(outH * outW*sizeof(float),384); uint32_t inAddr = 0; uint32_t outAddr = inAddr + inSizeBytes; if ((paddedH-kH)%stride || (paddedW-kW)%stride) { printf("BAD!\n"); exit(1); } printf("inSize,outSize=%d,%d\n",inSizeBytes,outSizeBytes); float *dataIn = malloc(inSizeBytes); float *dataOut = malloc(outSizeBytes); float *expectedOut = malloc(outSizeBytes); uint32_t *debug = malloc(outSizeBytes); if ( (paddedH-kH)%stride !=0 || (paddedW-kW)%stride !=0 ) { printf("Constants are not compatible!!\n"); exit(1); } int nxMax = Top_nxMax; if (NX > nxMax) { printf("2D filter with maximum size nxMax=%d can not process data with nx=%d\n",nxMax,NX); exit(1); } generateInputData(dataIn, inH, inW); LineBufferCPU(inH,inW,padH,padW,kH,kW,stride,kernel,dataIn, expectedOut); print_2d_data(dataIn, "INPUT DATA", inH, inW); print_2d_data(expectedOut, "BEFORE: EXPECTED DATA", outH, outW); max_file_t *maxfile = Top_init(); max_engine_t *engine = max_load(maxfile, "local:*"); Top_writeLMem_actions_t write; write.param_size = inSizeBytes; write.param_start = inAddr; write.instream_fromcpu = dataIn; Top_writeLMem_run(engine,&write); Top_actions_t lb; lb.param_NX = NX; lb.param_inH = inH; lb.param_inW = inW; lb.param_inBytes = inSizeBytes; lb.param_inAddr = inAddr; lb.param_outBytes = outSizeBytes; lb.param_outAddr = outAddr; printf("BEFORE run\n"); Top_run(engine,&lb); printf("AFTER run\n"); Top_readLMem_actions_t read; read.param_size = outSizeBytes; read.param_start = outAddr; read.outstream_tocpu = dataOut; Top_readLMem_run(engine,&read); printf("AFTER read\n"); print_2d_data(dataOut, "OUTPUT DATA", outH, outW); print_2d_data(expectedOut, "EXPECTED DATA", outH, outW); int status = check(outW*outH, dataOut, expectedOut); if (status) printf("Test failed.\n"); else printf("Test passed OK!\n"); //cleanup free(dataIn); free(dataOut); max_unload(engine); return 0; }
int main(int argc, char *argv[]) { if (argc != 3) { printf("Usage: %s <dfe_ip> <netmask>\n", argv[0]); return 1; } uint16_t Nsockets = 1; const int port = 80; struct in_addr dfe_ip; inet_aton(argv[1], &dfe_ip); struct in_addr netmask; inet_aton(argv[2], &netmask); // initialization files for crcIndex table, generated by init_code char fileCrcIndex1[] = "./results/romCrcIndex1_init.html"; char fileCrcIndex2[] = "./results/romCrcIndex2_init.html"; // LMEM initialization file location, generated by init_code char fileLmem[] = "./results/lmem_generated_file.html"; uint64_t *arrCrc1; uint64_t *arrCrc2; long Lcrc; FILE *fpCrc1 = fopen(fileCrcIndex1, "rb"); FILE *fpCrc2 = fopen(fileCrcIndex2, "rb"); FILE *fpLmem = fopen(fileLmem, "rb"); if (!(fpCrc1 && fpCrc2 && fpLmem)) { printf("Error with file\n"); exit(0); } // obtain file size fseek(fpCrc1, 0, SEEK_END); Lcrc = ftell(fpCrc1); rewind(fpCrc1); fillRomCrcIndex(fpCrc1, &arrCrc1, Lcrc); fillRomCrcIndex(fpCrc2, &arrCrc2, Lcrc); printf("Preparing for init() and max_load()\n"); max_file_t *maxfile = httpserver_init(); max_engine_t * engine = max_load(maxfile, "*"); printf("Done\n"); max_actions_t *actions = max_actions_init(maxfile, NULL); int romDepthCrc = Lcrc / 8; for (uint32_t i = 0; i < romDepthCrc; i++) { max_set_mem_uint64t(actions, "CrcIndexTable", "romCrcIndex1", i, arrCrc1[i]); max_set_mem_uint64t(actions, "CrcIndexTable", "romCrcIndex2", i, arrCrc2[i]); } max_run(engine, actions); max_actions_free(actions); long L; size_t result; uint64_t* arrLmem; // obtain file size fseek(fpLmem, 0, SEEK_END); L = ftell(fpLmem); rewind(fpLmem); double diff = ceil(L / 8.0) - L / 8.0; // NULL character padding if (diff != 0) { L = (int) ceil(L / 8.0) * 8; } // allocate memory to contain the whole file size_t Nelem = sizeof(uint64_t) * (L / 8); arrLmem = (uint64_t*) malloc(Nelem); result = fread(arrLmem, 1, L, fpLmem); int romDepth = L / 8; int burstLengthInBytes = max_get_burst_size(maxfile, "cmd_tolmem"); inline int max(int a, int b) { return a > b ? a : b; } ; const int size = romDepth; int sizeBytes = size * sizeof(uint64_t); uint64_t *inData; printf("Writing to DFE memory.\n"); inData = arrLmem; writeDataToLMem(inData, size, sizeBytes, burstLengthInBytes, engine, maxfile); printf("Done\n"); max_ip_config(engine, MAX_NET_CONNECTION_QSFP_BOT_10G_PORT1, &dfe_ip, &netmask); //all sockets MUST be created before first call to max_tcp_connect or max_tcp_listen max_tcp_socket_t *(dfe_socket[Nsockets]); uint16_t socketNumber[Nsockets]; for (int i = 0; i < Nsockets; i++) { //dfe_socket[i] = max_tcp_create_socket(engine, "tcp_ISCA_QSFP_BOT_10G_PORT1"); dfe_socket[i] = max_tcp_create_socket_with_number(engine, "tcp_ISCA_QSFP_BOT_10G_PORT1", i); socketNumber[i] = max_tcp_get_socket_number(dfe_socket[i]); printf("Socket %d was assigned socket number %u\n", i, socketNumber[i]); } for (int i = 0; i < Nsockets; i++) { max_tcp_listen(dfe_socket[i], port + i); max_tcp_await_state(dfe_socket[i], MAX_TCP_STATE_LISTEN, NULL); } printf("CPU code: Total %u socket(s), listening on the port(s) %u-%u\n\n", Nsockets, port, port + Nsockets - 1); void *read_ptr; uint8_t *read_buffer; max_llstream_t *read_llstream; uint64_t *byteNumber; printf("CPU code: Setting up 'toCpuByteNumber' stream.\n"); int Nslots_byteNumber = 512; size_t tCBN_buffer_size = Nslots_byteNumber * 16; posix_memalign((void *) &read_buffer, 4096, tCBN_buffer_size); read_llstream = max_llstream_setup(engine, "toCpuFileSizeBytes", Nslots_byteNumber, 16, read_buffer); uint8_t *read_buffer_socket; max_llstream_t *read_llstream_socket; printf("CPU code: Setting up 'toCpuSocketNumber' stream.\n"); int Nslots_socketNumber = 512; size_t tCSB_buffer_size = Nslots_socketNumber * 16; posix_memalign((void *) &read_buffer_socket, 4096, tCSB_buffer_size); read_llstream_socket = max_llstream_setup(engine, "toCpuSocketNumber", Nslots_socketNumber, 16, read_buffer_socket); void *read_ptr_socket_slot; uint16_t ti = 10; while(ti > 0) { printf("CPU code: time=%u, waiting file size and socket numbers stream data to be sent to CPU\n", ti); usleep(1000*1000*1); ti--; } //while(1); uint64_t num_rx_bytes; uint64_t num_tx_bytes; uint8_t session_id; while (1) { //part 1: first wait to receive LengthBytes number printf("CPU code: PART 1 - waiting to receive LengthBytes number\n"); int FoundByteNumber = 0; ti=0; while (FoundByteNumber != 1) //first wait to receive LengthBytes number { usleep(1000*1000*1); for (int i = 0; i < Nsockets; i++) { max_tcp_get_num_bytes_received(dfe_socket[i], &num_rx_bytes); max_tcp_get_num_bytes_transmitted(dfe_socket[i], &num_tx_bytes, &session_id); printf("CPU code: waiting, time=%u, port=%u, socket=%i, max_tcp_get_num_bytes_received=%llu, max_tcp_get_num_bytes_transmitted=%llu\n", ti, port + i, i, (long long unsigned int) num_rx_bytes, (long long unsigned int) num_tx_bytes); } ti++; uint8_t ii = max_llstream_read(read_llstream, 1, &read_ptr); if (ii) { byteNumber = (uint64_t*) read_ptr; printf("CPU code: number of slots found to contain new data=%u, fileSizeBytes=%u\n", ii, (unsigned int) *byteNumber); max_llstream_read_discard(read_llstream, 1); FoundByteNumber = 1; } } //part 2: receive total number of data transfered printf("CPU code: PART 2 - receive socket number\n"); while (max_llstream_read(read_llstream_socket, 1, &read_ptr_socket_slot) == 0) ; uint16_t socket_returned = (uint16_t) *((uint16_t*) read_ptr_socket_slot); //event->socketID; unsigned int fileBytes = (unsigned int) *byteNumber; printf("CPU code: fileBytes=%u, socket_returned=%u\n", fileBytes, socket_returned); ti = 0; while (1) { { for (int i = 0; i < Nsockets; i++) { max_tcp_get_num_bytes_received(dfe_socket[i], &num_rx_bytes); max_tcp_get_num_bytes_transmitted(dfe_socket[i], &num_tx_bytes, &session_id); printf("CPU code: time=%i, port=%u, socket=%i, max_tcp_get_num_bytes_received=%llu, max_tcp_get_num_bytes_transmitted=%llu\n", ti, port + i, i, (long long unsigned int) num_rx_bytes, (long long unsigned int) num_tx_bytes); } ti++; printf("\n"); max_tcp_get_num_bytes_transmitted(dfe_socket[socket_returned], &num_tx_bytes, &session_id); printf("CPU code: fileSizeBytes=%u, socketReturned=%u, num_tx_bytes=%llu\n", fileBytes, socket_returned, (long long unsigned int) num_tx_bytes); } //usleep(1000*100); //printf("CPU code: While LOOP, socket_returned=%u, fileBytes=%u, num_tx_bytes(max_tcp_get_num_bytes_transmitted)=%llu\n", socket_returned, fileBytes, (long long unsigned int) num_tx_bytes); if (num_tx_bytes == fileBytes) { //usleep(1000*1000*3); printf("CPU code: MATCH num_tx_bytes==fileBytes, socket_returned=%u, fileBytes=%u, num_tx_bytes(max_tcp_get_num_bytes_transmitted)=%llu\n", socket_returned, fileBytes, (long long unsigned int) num_tx_bytes); printf("CPU code: Closing socket=%u\n", socket_returned); max_tcp_close(dfe_socket[socket_returned]); //max_tcp_close_mode_t close_mode=MAX_TCP_CLOSE_ABORT_RESET; //max_tcp_close_advanced(dfe_socket[socket_returned],close_mode); printf("CPU code: Waiting for MAX_TCP_STATE_CLOSED\n"); max_tcp_await_state(dfe_socket[socket_returned], MAX_TCP_STATE_CLOSED, NULL); printf("CPU code: Set LISTEN state\n"); max_tcp_listen(dfe_socket[socket_returned], port); printf("CPU code: Waiting for MAX_TCP_STATE_LISTEN\n"); max_tcp_await_state(dfe_socket[socket_returned], MAX_TCP_STATE_LISTEN, NULL); printf("CPU code: Again opened socket=%u\n", socket_returned); printf("\nCPU code: State of rx/tx after socket closing\n"); break; } usleep(1000*1000*1); } } for (int i = 0; i < Nsockets; i++) { max_tcp_close(dfe_socket[i]); printf("max_tcp_close(dfe_socket[i])"); } max_unload(engine); printf("max_unload(engine)"); max_file_free(maxfile); printf("max_file_free(maxfile)"); printf("The end\n"); return 0; }
unsigned int simplex(const int m, const int n, lp_t * p) { // init DFE max_file_t * maxfile = Simplex_init(); max_engine_t * engine = max_load(maxfile, "*"); // align for streaming int align_m, align_n; lp_t * align_p = copy_aligned(m, n, p, &align_m, &align_n); if (trace > 0) printf("aligned: %dx%d -> %dx%d\n", m, n, align_m, align_n); // reserve buffers lp_t * c = malloc(align_n * sizeof(lp_t)); lp_t * ratio = malloc(align_m * sizeof(lp_t)); lp_t * pivcol = malloc(align_m * sizeof(lp_t)); lp_t * pivrow = malloc(align_n * sizeof(lp_t)); // init buffers: c, ratio, pivcol, pivrow for (int j = 0; j < n; j++) c[j] = p[j]; uint64_t col = find_pivot_column_max(n, c); for (int i = 0; i < align_m; ++i) { pivcol[i] = align_p[i * align_n + col]; ratio[i] = align_p[i * align_n] / pivcol[i]; } int row = find_pivot_row(m, ratio); for (int i = 0; i < align_n; i++) pivrow[i] = align_p[row * align_n + i]; // write LP to LMem Simplex_writeLMem_actions_t writeact; writeact.param_address = 0; writeact.param_count = align_m * align_n; writeact.instream_tolmem = align_p; Simplex_writeLMem_run(engine, &writeact); // simplex action to call DFE Simplex_actions_t act; act.param_m = align_m; act.param_n = align_n; act.instream_pivcol = pivcol; act.instream_pivrow = pivrow; act.outscalar_MaxKernel_maxcol_out = &col; act.outstream_ratio_out = ratio; act.outstream_pivcol_out = pivcol; act.outstream_c_out = c; // main loop unsigned int count = 0; while (count < max_iterations || max_iterations == 0) { // read pivot row from lmem Simplex_readLMem_actions_t readact; readact.param_address = row * align_n; readact.param_count = align_n; readact.outstream_fromlmem = pivrow; Simplex_readLMem_run(engine, &readact); // pivoting,max,filter count++; lp_t pivot = pivrow[col]; if (trace > 0) printf("%u: pivoting on %d, %lu: %g\n", count, row, col, pivot); act.param_pivot = 1 / pivot; act.param_col = col; act.param_row = row; Simplex_run(engine, &act); ratio[0] = -1; pivcol[0] = c[col]; //if (trace >= 9) write_bg(stdout, m, n, p); if (col <= 0) break; // optimum found // row row = find_pivot_row(m, ratio); if (row < 0) { p[0] = NAN; break; } // unbounded } // unload DFE max_unload(engine); // return results (TODO: copy full lp from lmem to p) p[0] = c[0]; // free buffers free(c); free(ratio); free(pivcol); free(pivrow); return count; }
int main(int argc, char *argv[]) { if(argc != 4) { printf("Usage: %s <dfe_ip> <cpu_ip> <netmask>\n", argv[0]); return 1; } struct in_addr dfe_ip; inet_aton(argv[1], &dfe_ip); struct in_addr cpu_ip; inet_aton(argv[2], &cpu_ip); struct in_addr netmask; inet_aton(argv[3], &netmask); const int port = 5008; /* Create DFE Socket, then listen */ max_file_t *maxfile = FieldAccumulatorTCP_init(); max_engine_t *engine = max_load(maxfile, "*"); max_ip_config(engine, MAX_NET_CONNECTION_CH2_SFP1, &dfe_ip, &netmask); max_udp_socket_t *dfe_socket = max_udp_create_socket(engine, "udp_ch2_sfp1"); max_udp_bind(dfe_socket, port); max_udp_connect(dfe_socket, &cpu_ip, port); int cpu_socket = create_cpu_udp_socket(&cpu_ip, &dfe_ip, port); FILE *stream = fopen("source_data1.csv", "r"); char line[BUFFERSIZE]; // char *to_be_free = line; /* Ignore Header File */ fgets(line, BUFFERSIZE, stream); printf(line); while (fgets(line, BUFFERSIZE, stream)) { struct input_data data; parse(line,&data); printf("\n Instrument id = %d \n level = %d \n side = %d \n Quantity = %d \n Price = %d",data.instrument_id,data.level,data.side,data.quantity,data.price); calculateDeltas(cpu_socket, &data); } // /* Set Value A */ // data.instrument_id = 0; // data.level = 0; // data.side = 0; // data.quantity = 5; // data.price = 10; // calculateDeltas(cpu_socket, &data); // // /* Set B*/ // data.instrument_id = 1; // data.level = 0; // data.side = 1; // data.quantity = 3; // data.price = 4; // calculateDeltas(cpu_socket, &data); // // /* Hold */ // data.instrument_id = 1; // data.level = 0; // data.side = 1; // data.quantity = 5; // data.price = 6; // calculateDeltas(cpu_socket, &data); // // /* Set AB */ // data.instrument_id = 2; // data.level = 0; // data.side = 1; // data.quantity = 7; // data.price = 8; // calculateDeltas(cpu_socket, &data); max_udp_close(dfe_socket); max_unload(engine); max_file_free(maxfile); return 0; }
int main(int argc, char *argv[]) { max_file_t *maxfile = Gap_init(); max_engine_t * engine = max_load(maxfile, "*"); max_config_set_bool(MAX_CONFIG_PRINTF_TO_STDOUT, true); max_actions_t *action = max_actions_init(maxfile, NULL); max_run(engine, action); size_t bufferSize = 4096 * 4096; void *inBuffer = NULL; void *outBuffer = NULL; if (posix_memalign(&inBuffer, 4096, bufferSize)) { err(1, "Couldn't allocation input buffer"); } if (posix_memalign(&outBuffer, 4096, bufferSize)) { err(1, "Couldn't allocation output buffer"); } max_framed_stream_t *inFrame = max_framed_stream_setup(engine, "src", inBuffer, bufferSize, 2048-16); max_framed_stream_t *outFrame = max_framed_stream_setup(engine, "dst", outBuffer, bufferSize, -1); // Now, stream in some frames and see what happens. for (size_t i=0 ; i < 8; i++) { void *f; while (max_framed_stream_write_acquire(inFrame, 1, &f) != 1) usleep(10); uint8_t *inputData = f; /* * Request a gap every other packet */ inputData[20] = i % 2 == 1 ? 'G' : 'N'; size_t frameSize = 60; printf("Sending frame %zd\n", i); max_framed_stream_write(inFrame, 1, &frameSize); void *oFrame; size_t oFrameSize; while (max_framed_stream_read(outFrame, 1, &oFrame, &oFrameSize) != 1) usleep(10); printf("Got frame %zd - %zd bytes (Expecting %zd)\n", i, oFrameSize, frameSize); dump(oFrame, oFrameSize); max_framed_stream_discard(outFrame, 1); } max_unload(engine); max_file_free(maxfile); printf("Done.\n"); return 0; }
int main(int argc, char *argv[]) { if(argc < 3) { printf("Usage: $0 dfe_ip cpu_ip\n"); return 1; } struct in_addr dfe_ip; inet_aton(argv[1], &dfe_ip); struct in_addr cpu_ip; inet_aton(argv[2], &cpu_ip); struct in_addr netmask; inet_aton("255.255.255.0", &netmask); const int port = 5007; max_file_t *maxfile = Tracker_init(); max_engine_t * engine = max_load(maxfile, "*"); max_config_set_bool(MAX_CONFIG_PRINTF_TO_STDOUT, true); max_actions_t *actions = max_actions_init(maxfile, NULL); char regName[32]; for (int i=0; i < 1024; i++) { sprintf(regName, "filter_%d", i); if (i == 150) { max_set_uint64t(actions, "filteringKernel", regName, 0xCC /* a value to match... */); } else { max_set_uint64t(actions, "filteringKernel", regName, 0x4D1B /* or any value you want */); } } max_run(engine, actions); max_actions_free(actions); void *buffer; size_t bufferSize = 4096 * 512; posix_memalign(&buffer, 4096, bufferSize); max_framed_stream_t *toCpu = max_framed_stream_setup(engine, "toCPU", buffer, bufferSize, -1); /* * This executable both creates a normal Linux UDP socket as well as a DFE UDP Socket. * We then exchange data between the two. */ // DFE Socket max_ip_config(engine, MAX_NET_CONNECTION_QSFP_TOP_10G_PORT1, &dfe_ip, &netmask); max_udp_socket_t *dfe_socket = max_udp_create_socket(engine, "udpTopPort1"); max_udp_bind(dfe_socket, port); max_udp_connect(dfe_socket, &cpu_ip, port); // Linux Socket int cpu_socket = create_cpu_udp_socket(&cpu_ip, &dfe_ip, port); printf("Sending test frame...\n"); sendTestFrame(cpu_socket); printf("Waiting for kernel response...\n"); fflush(stdout); void *f; size_t fsz; size_t numMessageRx = 0; uint8_t received_data[512]; while (numMessageRx < NUM_MESSAGES_EXPECTED) { if (max_framed_stream_read(toCpu, 1, &f, &fsz) == 1) { printf("CPU: Got output frame - size %zd - NumMsg = %zd!\n", fsz, numMessageRx); // Frame size would be rounded up to the next 8 bytes. memcpy(received_data, f, fsz); numMessageRx++; max_framed_stream_discard(toCpu, 1); } else usleep(10); } max_udp_close(dfe_socket); max_unload(engine); max_file_free(maxfile); printf("Done.\n"); fflush(stdout); return 0; }
int main(int argc, char *argv[]) { if(argc < 3) { printf("Usage: $0 dfe_ip remote_ip\n"); return 1; } struct in_addr dfe_ip; inet_aton(argv[1], &dfe_ip); struct in_addr remote_ip; inet_aton(argv[2], &remote_ip); struct in_addr netmask; inet_aton("255.255.255.0", &netmask); const int in_port = 2000; const int out_port = 2000; // struct in_addr mcastaddr; // inet_aton("224.0.0.1", &mcastaddr); max_file_t *maxfile = SignExtWithPatternMatching_init(); max_engine_t * engine = max_load(maxfile, "*"); max_config_set_bool(MAX_CONFIG_PRINTF_TO_STDOUT, true); max_actions_t *actions = max_actions_init(maxfile, NULL); max_run(engine, actions); max_actions_free(actions); void *buffer; size_t bufferSize = 4096 * 512; posix_memalign(&buffer, 4096, bufferSize); max_framed_stream_t *toCpu = max_framed_stream_setup(engine, "toCPU", buffer, bufferSize, -1); max_ip_config(engine, MAX_NET_CONNECTION_QSFP_TOP_10G_PORT1, &dfe_ip, &netmask); max_udp_socket_t *dfe_socket = max_udp_create_socket(engine, "udpTopPort1"); // max_ip_multicast_join_group(engine, MAX_NET_CONNECTION_QSFP_TOP_10G_PORT1, &mcastaddr); // max_udp_bind_ip(dfe_socket, &mcastaddr, in_port); max_udp_bind(dfe_socket, in_port); max_udp_connect(dfe_socket, &remote_ip, out_port); printf("Listening on %s in_port %d\n", argv[1], in_port); printf("Waiting for kernel response...\n"); fflush(stdout); void *f; size_t fsz; size_t numMessageRx = 0; while (1) { if (max_framed_stream_read(toCpu, 1, &f, &fsz) == 1) { numMessageRx++; printf("CPU: Got output frame %zd - size %zd bytes\n", numMessageRx, fsz); uint64_t *w = f; for (size_t i=0; i < 3; i++) { printf("Frame [%zd] Word[%zd]: 0x%lx\n", numMessageRx, i, w[i]); } max_framed_stream_discard(toCpu, 1); } else usleep(10); } // max_ip_multicast_leave_group(engine, MAX_NET_CONNECTION_QSFP_TOP_10G_PORT1, &mcastaddr); max_udp_close(dfe_socket); max_unload(engine); max_file_free(maxfile); printf("Done.\n"); fflush(stdout); return 0; }
int main(int argc, char *argv[]) { if(argc != 4) { printf("Usage: %s <topIp>:<topNetmask> <botIp>:<botNetmask> <remoteIp>:<remotePort>\n", argv[0]); return 1; } char top_ip_str[16]; char top_netmask_str[16]; char bot_ip_str[16]; char bot_netmask_str[16]; char remote_ip_str[16]; uint remote_port; if (sscanf(argv[1], "%15[0-9.]:%15[0-9.]", top_ip_str, top_netmask_str) != 2) { printf("Failed to parse top port IP and netmask"); return 1; } if (sscanf(argv[2], "%15[0-9.]:%15[0-9.]", bot_ip_str, bot_netmask_str) != 2) { printf("Failed to parse bot port IP and netmask"); return 1; } if (sscanf(argv[3], "%15[0-9.]:%u", remote_ip_str, &remote_port) != 2) { printf("Failed to parse remote IP and port"); return 1; } struct in_addr top_ip = { inet_addr(top_ip_str) }; struct in_addr top_netmask = { inet_addr(top_netmask_str) }; struct in_addr bot_ip = { inet_addr(bot_ip_str) }; struct in_addr bot_netmask = { inet_addr(bot_netmask_str) }; struct in_addr remote_ip = { inet_addr(remote_ip_str) }; max_file_t* maxfile = CmeTrading_init(); max_engine_t* engine = max_load(maxfile, "*"); max_ip_config(engine, MAX_NET_CONNECTION_QSFP_TOP_10G_PORT1, &top_ip, &top_netmask); max_ip_config(engine, MAX_NET_CONNECTION_QSFP_BOT_10G_PORT1, &bot_ip, &bot_netmask); max_cme_mdp_handle_t* mdp; if (max_cme_mdp_open_handler(engine, &mdp, "md", "templates_FixBinary.xml", "config.xml")) { printf("Failed to open market data handler.\nError trace: %s\n", max_cme_mdp_get_error_trace(mdp)); return 1; } max_cme_ilink_handle_t* ilink; // The NULL arguments here are the iLink output folders. Passing NULL disables iLink logging and session persistence. if (max_cme_ilink_open_handler(&ilink, engine, "orderEntry", NULL, NULL)) { printf("Failed to open iLink handler.\nError trace: %s\n", max_cme_ilink_get_error_trace(ilink)); return 1; } struct timeval timeout = {5, 0}; // 5 seconds max_cme_ilink_session_t* session = max_cme_ilink_session_connect(ilink, &remote_ip, remote_port, &timeout); if (!session) { printf("Failed to connect iLink session.\nError trace: %s\n", max_cme_ilink_get_error_trace(ilink)); return 1; } const char* session_id = "ABC"; const char* sender_sub_id = "subID"; const char* firm_id = "123"; const char* location_id = "GB"; const char* password = "******"; const int heartbeat_interval = 30; if (max_cme_ilink_session_login( session, session_id, sender_sub_id, firm_id, MAXCMEILINK_CUSTOMERORFIRM_CUSTOMER, MAXCMEILINK_CTICODE_1, location_id, password, MAXELER_APPLICATION_SYSTEM_NAME, MAXELER_TRADING_SYSTEM_VERSION, MAXELER_APPLICATION_SYSTEM_VENDOR, heartbeat_interval, &timeout)) { printf("Failed to login iLink session.\nError trace: %s\n", max_cme_ilink_get_error_trace(ilink)); return 1; } // allow iLink to send some orders from the hardware if (max_cme_ilink_alloc_orders(session, 512)) { printf("Failed to alloc orders.\nError trace: %s\n", max_cme_ilink_get_error_trace(ilink)); return 1; } const uint channel_id = 342; const uint security_id = 295722; const uint market_depth = 10; const max_cme_mdp_channel_t* channel = max_cme_mdp_get_channel_by_id(mdp, channel_id); if (!channel) { printf("Failed to find channel with id '%d'.\nError trace: %s\n", channel_id, max_cme_mdp_get_error_trace(mdp)); return 1; } max_cme_mdp_instrument_t* instrument = max_cme_mdp_new_instrument(mdp, channel, security_id, market_depth); if (!instrument) { printf("Failed to create new instrument.\nError trace: %s\n", max_cme_mdp_get_error_trace(mdp)); return 1; } if (max_cme_mdp_add_instrument(mdp, instrument) < 0) { printf("Failed to add instrument.\nError trace: %s\n", max_cme_mdp_get_error_trace(mdp)); return 1; } // Don't wait for iLink events here as market data events might pile up. struct timeval no_wait = {0}; while (1) { int activity = 0; max_cme_mdp_event_t* md_event; while (max_cme_mdp_get_next_event(mdp, &md_event) == 1) { max_cme_mdp_print_event(md_event); max_cme_mdp_destroy_event(md_event); activity = 1; } max_cme_ilink_session_event_t session_event; while (max_cme_ilink_get_next_session_event(session, &session_event, &no_wait) == 1) { max_cme_ilink_display_session_event(&session_event); activity = 1; } max_cme_ilink_order_event_t order_event; while (max_cme_ilink_get_next_order_event(session, &order_event, &no_wait) == 1) { max_cme_ilink_display_order_event(&order_event); activity = 1; } if (!activity) usleep(1000); } return 0; }
int main(int argc, char *argv[]) { (void) argc; (void) argv; max_file_t *maxfile = INIT_NAME(); if(!maxfile) { printf("Failed to init MAX file\n"); return -1; } max_config_set_bool(MAX_CONFIG_PRINTF_TO_STDOUT, true); const char *device_name = "*"; printf("Opening device: %s\n", device_name); max_engine_t *engine = max_load(maxfile, device_name); if(!engine) { printf("Failed to open Max device\n"); exit(-1); } max_reset_engine(engine); /* * SLiC is so shit, that if we don't run an empty action, no debug outputs will be generated. */ max_actions_t *action = max_actions_init(maxfile, NULL); max_run(engine, action); max_actions_free(action); srand(time(NULL)); single_entry_t *outputData = calloc(MAX_DEPTH, sizeof(single_entry_t)); void *configWordBuffer = NULL; posix_memalign(&configWordBuffer, 4096, 512 * sizeof(configWord_t)); max_llstream_t *configWordStream = max_llstream_setup(engine, "configWord", 512, sizeof(configWord_t), configWordBuffer); uint64_t configBase = 0; printf("Sending config word...\n"); void *configWordSlot; while (max_llstream_write_acquire(configWordStream, 1, &configWordSlot) != 1) usleep(10); configWord_t *configWord = configWordSlot; configWord->wordCount = MAX_DEPTH; configWord->base = configBase; max_llstream_write(configWordStream, 1); getchar(); printf("Streaming 'read_fifo'...\n"); fflush(stdout); action = max_actions_init(maxfile, NULL); max_queue_output(action, "read_fifo", outputData, sizeof(single_entry_t) * MAX_DEPTH); max_disable_reset(action); max_disable_validation(action); max_enable_partial_memory(action); max_run(engine, action); max_actions_free(action); printf("Comparing...\n"); fflush(stdout); uint8_t fail = 0; for (size_t entryIx=0; entryIx < MAX_DEPTH; entryIx++) { uint64_t *output = (uint64_t *)outputData[entryIx].data; size_t quadsPerEntry = sizeof(single_entry_t) / sizeof(uint64_t); uint64_t expected = (configBase + entryIx); if (expected != output[0]) { fail = 1; printf("[Entry: %zd, Quad: %zd] Mismatch: input 0x%lx, output 0x%lx\n", entryIx, 0L, expected, output[0]); } for (size_t q = 1; !fail && q < quadsPerEntry; q++) { if (0 != output[q]) { fail = 1; printf("[Entry: %zd, Quad: %zd] Mismatch: input 0x%lx, output 0x%lx\n", entryIx, q, 0L, output[q]); } } } printf("%s\n", fail ? "FAILED!" : "Success"); return fail; }