- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi all,
I have been battling now for several weeks on a getting a simple Algorithm to work using C2H. The function is below:
void HWIntFunc(unsignedint* InData, unsignedint* OutData)
{
int i,j,k;
unsignedint AvgVal =0;
for (i=0; i < 100; i++)
{
for (j=0;j<100;j++)
{
for (k=0;k <100; k++)
{
AvgVal += *InData;
InData += 1;
}
//Set Avg data as ImgData
*OutData = AvgVal / 100;
OutData += 1;
AvgVal = 0;
}
}
}
Now the function above works in a Software only version. I am using the NEEK and have a simple design based on the "altera_avalon_checksum_de" layout with the Checksum HW blocks removed. Now after extensive trial and error i can use the CLI to get the C2H makefiles etc then can build. Although this generally doesnt work completely. I always have to re-generate and re-compile from SOPC builder and Quartus (with some connecting for new C2H component) Then i can re-generate the BSP and build and run. However at this point it never seems to actually run. Any ideas i could chase? Is there an issue in the routine above? As stated in Software the routine works correctly suggesting its the C2H side that is failing. Cheers Tim
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You probably are not meeting timing due to the division by 100. Right now C2H uses lpm_divide for that and doesn't add much pipelining. I'm guessing your Fmax if targeting Cyclone III is probably around 16MHz. There are a few ways around this:
1) Maybe your algorithm can be changed to avoid the division 2) Try using these serial dividers: http://www.altera.com/literature/hb/nios2/edh_c2h_optimization_design_files.zip 3) Make a divider component that you can write data into and read results back out and access it like a memory .... there might be others, I haven't had enough coffee to think of them. As a heads up option# 2 will become blocking for around 33 clock cycles since you are performing a 32-bit division. You might find that you don't need a lot of accuracy and can break down this division into a bunch of shifts and adds/subtracts. I wrote down how you can do that somewhere but can't remember for the life of me where I put it but if you google for it I'm sure you find it. The algorithm works by breaking the division down into fractions that have powers of 2 in the denominator (which you can use >> to divide).- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
For 'divide by constant' you should be able to use a 'multiply by reciprocal' algorithm (C2H probably ought to be able to generate one of these iteself - but may not).
The 'magic' number isn't hard to determine, but gcc for nios2 probably uses the multiply by reciprocal and yoy could steal the values from some generated code.- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks for the replies.
I managed to get it to work by rebuilding a number of times until it worked. Here is my next question, I am using the SBT to do all this. First i create my project and test it without any C2H etc in the SBT. Then i use the shell (legacy shell as the latest has some installation issues with perl and aways give a Strict.pm error @INC) and re-create the makefile. Then rebuild and all is well. Then add the --C2H extension, and create my C2H.mk using the shell with --enable_quartus=1 --accelerator=MyFunc,MyCFile.c,1,0. Do a build and all looks good but then if i try to re-generate the BSP its now corrupt. I can look in the SOPC builder and it doesnt seem to have added the C2H component. I can resolve this and then re-generate and re-compile. Then the BSP is OK and i can build and it will sometimes work. Am i doing something stupid here? Is there something i am missing? As you can see i have got to a working point but can't see why its so inconsistent and why the BSP gets corrupted. Cheers Tim- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Yes make sure to use the old shell since I'm not sure if C2H is supposed to work with gcc 4.
When you say the BSP is corrupt you just mean it is out of date right? This is expected since you are using software tools that modify your system. It's just like if you generated a BSP and then regenerated your SOPC Builder system with an extra component that you manually added. Using the IDE flow this change to the syslib will be automatically detected and the syslib will get regenerated for you. The SBT tools doesn't perform this automated step (and for good reasons).- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Sadly not just out of date, if i try to use the BSP editor or Generate BSP i get an error message to do with ensemble report being incorrect or similar. This means i have to go back to the SOPC builder and quartus and re-generate and compile. Whilst this then works it doubles my build time which is frustrating and adds concerns that it hasnt created the component correctly. As i said in many instances the first time the component isnt even added to the SOPC design but is added to the components list.
Onwards and downwards!!
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page