ll_stream<T>::ll_stream(dataflow_engine const& dfe, std::string name, int slot_length, int slot_count)
	: slot_length_(slot_length), slot_count_(slot_count), buffer_(0), stream_(0)
{
	std::cerr << "Setting up stream " << name << std::endl;

	slot_length_ = slot_length;
	slot_count_ = slot_count;
	int ret = posix_memalign(&buffer_, alignment, slot_count * slot_length * sizeof(T));
	if(ret != 0) {
		throw std::runtime_error(std::string("posix_memalign: ") + strerror(ret));
	}

	stream_ = max_llstream_setup(dfe.handle(), name.c_str(), slot_count, slot_length * sizeof(T), buffer_);
}
Ejemplo n.º 2
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;

}
Ejemplo n.º 3
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;
}
Ejemplo n.º 4
0
	LowLatencyStream(max_engine_t* engine, const std::string& name, size_t numSlots, size_t slotSize)
	: numSlots(numSlots), slotSize(slotSize), buf(numSlots*slotSize),
	  ll(max_llstream_setup(engine, name.c_str(), numSlots, slotSize, buf), max_llstream_release)
	{
		if (!ll) throw std::runtime_error("Failed to instantiate llstream");
	}