UPGRADE YOUR BROWSER

We have detected your current browser version is not the latest one. Xilinx.com uses the latest web technologies to bring you the best online experience possible. Please upgrade to a Xilinx.com supported browser:Chrome, Firefox, Internet Explorer 11, Safari. Thank you!

cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Scholar xilinxacct
Scholar
131 Views
Registered: ‎10-23-2018

HLS Optimization Challenge

Jump to solution

I propose a simple challenge. Since people are busy, I suggest we start with a trivial problem that can be implemented in minutes and is well understood by all. To speed things up, I will supply the testbench.

The challenge will be to create the fastest implementation of a string length function.

You may optimize the solution by using any pragma(s) you choose, and implement the function in any way you choose that satisfies the constraints.


The problem will be constrained in the following ways…

1) The prototype of the function shall be … short my_strlen(char str[32]);

2) The solution will be timed against the target device: xczu3eg-sbva484-1-e using the Verilog co-simulation times using Vivado HLS 2018.3.

3) The solution must pass Verilog co-simulation using the provided testbench (but not limiting the character set, to the specific cases in the test set; e.g. you are not allowed to tune the solution to consider the specific character sequences in the testbench. A true solution will allow any/all permutations of the 32 character input sequence)

4) If there is no ‘\0’ character within the buffer, the result shall be 32


The winner be the solution with the fastest timing. If there is a tie with the fastest time, the smaller utilization will be considered the winner. If that also results in a tie, the earliest submission will be deemed the winner.

As part of the goal, is to see alternate solutions, even if your submission is not the best, a Kudo will be awarded by me for novelty (e.g. you are using pragma not used yet, or an algorithm not yet seen.) Of course, I would like to ‘win’ :-), but learning another alternative is also valuable to me.

Of course the submission that wins, will be awarded as solution accepted by me (and if others want to passively play along, and reward the participants/winner, they can ‘subscribe’ to the post (see the ‘subscribe’ option in the menu marked by the 3 dots at the upper right corner of this post.) and once a solution has been marked as accepted, they can give a Kudo as they see fit.

Good Luck (or shall I say Good Skill)


----- TEST BENCH BELOW ---

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

extern short my_strlen(char s[32]);

const char *testCase[] = {
		"",
		"1",
		"12",
		"123",
		"1234",
		"12345",
		"123456",
		"1234567",
		"12345678",
		"123456789",
		"1234567890",
		"12345678901",
		"123456789012",
		"1234567890123",
		"12345678901234",
		"123456789012345",
		"1234567890123456",
		"12345678901234567",
		"123456789012345678",
		"1234567890123456789",
		"12345678901234567890",
		"123456789012345678901",
		"1234567890123456789012",
		"12345678901234567890123",
		"123456789012345678901234",
		"1234567890123456789012345",
		"12345678901234567890123456",
		"123456789012345678901234567",
		"1234567890123456789012345678",
		"12345678901234567890123456789",
		"123456789012345678901234567890",
		"1234567890123456789012345678901",
		"12345678901234567890123456789012",
		NULL
};

int main() {
	char str[33];
	int ret = 0;
	for(int i=0; testCase[i]; i++) {
		strcpy(str, testCase[i]);
		short len = my_strlen(str);
		if (len != (short)strlen(str)) {
			printf("len(%hd) != strlen=%hd\n", len, strlen(str));
			ret = -1;
		}
	}

	exit(ret);
}

 

0 Kudos
1 Solution

Accepted Solutions
Scholar xilinxacct
Scholar
122 Views
Registered: ‎10-23-2018

Re: HLS Optimization Challenge

Jump to solution

Let me seed the pool, just to get things started... (not the best)

short my_strlen(char s[32]) {
#pragma HLS array_partition variable=s cyclic factor=32
#pragma HLS interface ap_memory port=s
	for(short i=0; i<32; i++) {
#pragma HLS unroll
		if (!s[i]) {
			return i;
		}
	}
	return 32;
}
0 Kudos
2 Replies
Scholar xilinxacct
Scholar
123 Views
Registered: ‎10-23-2018

Re: HLS Optimization Challenge

Jump to solution

Let me seed the pool, just to get things started... (not the best)

short my_strlen(char s[32]) {
#pragma HLS array_partition variable=s cyclic factor=32
#pragma HLS interface ap_memory port=s
	for(short i=0; i<32; i++) {
#pragma HLS unroll
		if (!s[i]) {
			return i;
		}
	}
	return 32;
}
0 Kudos
Scholar xilinxacct
Scholar
45 Views
Registered: ‎10-23-2018

Re: HLS Optimization Challenge

Jump to solution

Although the solution is not the best, I will accept it... Thanks for those who commented... some saying the challenge was not complex enoiugh to give a lot of variety in results, and others that said my seed response made it too hard to improve upon easily.

When/if I do another challenge in the future. I will make it a bit harder, and not post the long hanging fruit solution. :-)

0 Kudos