void writeDataToLMem(uint64_t *dataIn, int size, int sizeBytes, int burstLengthInBytes, max_engine_t *engine, max_file_t *maxfile) { printf("size=%d, sizeBytes=%d, burstLengthInBytes=%d\n", size, sizeBytes, burstLengthInBytes); printf("Performing max_actions_init()\n"); max_actions_t *actions = max_actions_init(maxfile, NULL); printf("Done\n"); max_set_ticks(actions, "KernelLMem_Write_CommandAndDataStream", size); max_set_uint64t(actions, "KernelLMem_Write_CommandAndDataStream", "totalBursts", size * 8 / burstLengthInBytes); max_set_uint64t(actions, "KernelLMem_Write_CommandAndDataStream", "wordsPerBurst", burstLengthInBytes / 8); max_set_ticks(actions, "KernelLMem_Read_CommandAndDataStream", 0); max_set_uint64t(actions, "KernelLMem_Read_CommandAndDataStream", "totalBursts", size * 8 / burstLengthInBytes); max_set_uint64t(actions, "KernelLMem_Read_CommandAndDataStream", "wordsPerBurst", burstLengthInBytes / 8); max_run(engine, actions); max_reset_engine(engine); max_queue_input(actions, "fromCpu", dataIn, sizeBytes); max_lmem_set_interrupt_on(actions, "toLmem"); printf("Performing max_run()\n"); max_run(engine, actions); printf("Done\n"); max_actions_free(actions); }
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; }
void readDataFromLMem(uint64_t *dataOut, int size, int sizeBytes, int burstLengthInBytes, max_engine_t *engine, max_file_t *maxfile) { max_actions_t *actions = max_actions_init(maxfile, NULL); max_set_ticks(actions, "KernelLMem_Write_CommandAndDataStream", 0); max_set_uint64t(actions, "KernelLMem_Write_CommandAndDataStream", "totalBursts", size * 8 / burstLengthInBytes); max_set_uint64t(actions, "KernelLMem_Write_CommandAndDataStream", "wordsPerBurst", burstLengthInBytes / 8); max_set_ticks(actions, "KernelLMem_Read_CommandAndDataStream", size); max_set_uint64t(actions, "KernelLMem_Read_CommandAndDataStream", "totalBursts", size * 8 / burstLengthInBytes); max_set_uint64t(actions, "KernelLMem_Read_CommandAndDataStream", "wordsPerBurst", burstLengthInBytes / 8); max_run(engine, actions); max_reset_engine(engine); max_queue_output(actions, "toCpu", dataOut, sizeBytes); max_run(engine, actions); max_actions_free(actions); }
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; }
/** * Runs the main action to compute a predictor or corrector step */ void AirfoilDFEInterface::runMainAction(int k, double cfl, double gam, double gm1, double eps, double *rms) { int cpuresind = 0; int schedind = 0; for (int d = 1; d < (*domain).ndomain; d++){ for (int res_edge_iter = 0; res_edge_iter < (*domain).nedge[d]; res_edge_iter++){ int thispart = d; int thisind = res_edge_iter; for (int i = 0; i < 2; i++){ int thiscellpart = (*domain).ecellpart[thispart][thisind*2+i]; int thiscellind = (*domain).ecellind[thispart][thisind*2+i]; if (reads[7*schedind+3] == 1){ for (int j = 0; j < 4; j++) { cpu_res_qpadt[cpuresind*5+j] = (*domain).q[thiscellpart][4*thiscellind+j]; } cpu_res_qpadt[cpuresind*5+4] = (*domain).adt[thiscellpart][thiscellind]; cpuresind ++; } schedind ++ ; } } } max_actions_t * act = max_actions_init(maxfile, NULL); max_set_ticks(act, "AirfoilDFEAdtKernel", (*domain).ncellcomputedfe); max_set_uint64t(act, "AirfoilDFEAdtKernel", "numTicks", (*domain).ncellcomputedfe); max_set_double(act, "AirfoilDFEAdtKernel", "cfl", cfl); max_set_double(act, "AirfoilDFEAdtKernel", "gam", gam); max_set_double(act, "AirfoilDFEAdtKernel", "gm1", gm1); max_lmem_linear(act, "adtQ", memAddresses[q], memAddresses[q+1] - memAddresses[q]); max_lmem_linear(act, "adtDxRead", memAddresses[adtDx], adtDxDatSize); max_set_ticks(act, "AirfoilDFEResKernel", resFlushTicks); max_set_double(act, "AirfoilDFEResKernel", "gm1", gm1); max_set_double(act, "AirfoilDFEResKernel", "eps", eps); max_set_uint64t(act, "AirfoilDFEResKernel", "nTicks", resFlushTicks); max_queue_input(act, "cpu_qpadt_to_res", cpu_res_qpadt, cpuQpadtSize); max_lmem_linear(act, "resReadOnly", memAddresses[resReadOnly], resReadOnlyDatSize); max_queue_output(act,"cpu_res_from_res", dfe_res_res, passtorescount*sizeof(double)*4); double * rmsOut = (double *) malloc(16*sizeof(double)); max_set_ticks(act,"AirfoilDFEUpdateKernel", (*domain).ncellcomputedfe); max_set_uint64t(act, "AirfoilDFEUpdateKernel", "numCells", (*domain).ncellcomputedfe); max_set_uint64t(act, "AirfoilDFEUpdateKernel", "doSaveQold", k==1); max_lmem_linear(act, "updateQ", memAddresses[q], memAddresses[q+1] - memAddresses[q]); max_lmem_linear(act, "updateQold", memAddresses[qold], memAddresses[qold+1] - memAddresses[qold]); max_queue_output(act,"rmsOut", rmsOut, 16*sizeof(double)); if (k == 0) { max_ignore_lmem(act, "updateSaveQold"); } else { max_lmem_linear(act, "updateSaveQold", memAddresses[qold], memAddresses[qold+1] - memAddresses[qold]); } max_ignore_lmem(act, "setupWrite"); max_ignore_lmem(act, "qRead"); max_run(engine, act); max_actions_free(act); for (int i = 0; i < 16; i++) (*rms) += rmsOut[i]; cpuresind = 0; schedind = 0; for (int d = 1; d < (*domain).ndomain; d++){ for (int res_edge_iter = 0; res_edge_iter < (*domain).nedge[d]; res_edge_iter++){ int thispart = d; int thisind = res_edge_iter; for (int i = 0; i < 2; i++){ int thiscellpart = (*domain).ecellpart[thispart][thisind*2+i]; int thiscellind = (*domain).ecellind[thispart][thisind*2+i]; if (reads[7*schedind+3] == 1){ for (int j = 0; j < 4; j++) { (*domain).res[thiscellpart][4*thiscellind+j] += dfe_res_res[cpuresind*4+j]; } cpuresind ++; } schedind ++ ; } } } }