svd C lib ultibo does not match RaspBian

General discussion about anything related to Ultibo.
develone
Posts: 308
Joined: Wed Dec 28, 2016 7:40 pm
Location: El Paso Tx USA

svd C lib ultibo does not match RaspBian

Postby develone » Tue Jun 18, 2019 5:31 pm

Hello All,
https://github.com/develone/Ultibo_Projects in svd /RPi2 folder.
I have C code that executes on Raspbian and the same code executes on Ultibo calling a libsvd.a test_svd().
This code performs a SVD on an image. The library is created with "buildlib.sh 0" and with
"fpc -vi -B -Tultibo -Parm -CpARMV7A -WpRPI2B @/home/pi/ultibo/core/fpc/bin/RPI2.CFG -O4 SVD_RPi2.lpr" or with
Lazarus using the "svd_FS_RPi2.lpi". This code executes on Ultibo reads red.bin and creates S.bin & reconst.bin.
The Raspbian code is created with "build_svd.sh 0" and executes with the command "img_svd" reads red.bin and creates S.bin & reconst.bin.
Using octave with c.m the images that are reconstructed are not correct with Ultibo.
Any idea why the Ultibo version does not match the Rasp ver?

pi@mypi3-1:~/Ultibo_Projects/svd/RPi2 $ tftp 192.168.1.202
tftp> binary
tftp> get reconst.bin
Error code 5: 60863
Received 65536 bytes in 5.3 seconds
tftp> get S.bin
Error code 5: 53184
Received 1024 bytes in 5.1 seconds
tftp> quit
let me know if I can provide additional information.
Attachments
ultibo.png
ultibo.png (99.74 KiB) Viewed 331 times
rasp.png
rasp.png (111.61 KiB) Viewed 331 times
User avatar
Ultibo
Site Admin
Posts: 2257
Joined: Sat Dec 19, 2015 3:49 am
Location: Australia

Re: svd C lib ultibo does not match RaspBian

Postby Ultibo » Thu Jun 20, 2019 12:19 am

develone wrote:Any idea why the Ultibo version does not match the Rasp ver?

I'm not exactly familiar with SVD but a quick look at the code shows it makes heavy use of floating point arithmetic.

From that my first thought would be that there are two potential places where the difference could originate,

1. The FPU settings that Ultibo configures during startup could be different enough to produce some variation in results.

2. The code produced by gcc for the two different versions could also be different because of the compiler options used by each.

It would be interesting if you could determine more precisely what the difference is, visually it looks like the Ultibo result contains a higher level of Blue (the other colors appear consistent) while the graph looks identical for both. If you have any way to do further analysis on the result and determine what colors differ (and by what degree) that might point to a cause.

The other thing that you could experiment with is to change the -mfpu= option used to compile your Ultibo version to match what is used by Raspbian instead, exactly what that is might depend on the version of gcc and Raspbian etc. If you add -v to the command line when compiling under Raspbian it should give you a whole lot of information including (hopefully) the arch, tune and fpu settings used.

This would be a very interesting case to understand, let us know what you find if you do some more investigation.
Ultibo.org | Make something amazing
https://ultibo.org
develone
Posts: 308
Joined: Wed Dec 28, 2016 7:40 pm
Location: El Paso Tx USA

Re: svd C lib ultibo does not match RaspBian

Postby develone » Fri Jun 21, 2019 2:06 pm

Hello All,

https://github.com/develone/Ultibo_Projects/blob/master/svd/linearalgebra5_7-1.pdf is a good description of the SVD.
"./build_svd.sh 1" compiles test_svd.c and creates "test_svd".
"./buildlib.sh 1" compiles ultibo_svd.c and creates libsvd.a
The above is a 9 X 8 example of the SVD. In the ultibo version I used logging to obtain the output.

LoggingDeviceSetTarget(LoggingDeviceFindByType(LOGGING_TYPE_FILE),'c:\ultibologging.log');
LoggingDeviceSetDefault(LoggingDeviceFindByType(LOGGING_TYPE_FILE));
MyPLoggingDevice:=LoggingDeviceGetDefault;
LoggingDeviceRedirectOutput(MyPLoggingDevice);

I needed to copy ultibologging.log u.log to tftp.
On the Raspbian ./test_svd > xx.txt. The obtained out to 8 decimal places are very similar.
https://gist.github.com/develone/1c9b24de411295f5ebc8e7252a997ade
Adding to Raspbian gcc "-march=armv7-a -mfpu=vfpv3-d16 -mfloat-abi=hard" to match Ultibo arm-none-eabi-gcc options.
This did not change the Raspbian results. The RaspBian C "img_svd" results are the same as Octave results with
"testsvd.m".

Le t me know if I can provide additional information.
develone
Posts: 308
Joined: Wed Dec 28, 2016 7:40 pm
Location: El Paso Tx USA

Re: svd C lib ultibo does not match RaspBian

Postby develone » Mon Jun 24, 2019 12:03 pm

Hello All,
I was able to determine what pixel was the difference.

pi@mypi3-10wifi:~/Ultibo_Projects/svd/RPi2 $ export PATH=/home/pi/ultibo/core/fpc/bin:$PATH
pi@mypi3-10wifi:~/Ultibo_Projects/svd/RPi2 $ ./buildlib.sh 0 Creates libsvd.a to be linked with svd_FS_RPi2.lpr
Compiling example ultibo_img_svd
pi@mypi3-10wifi:~/Ultibo_Projects/svd/RPi2 $ fpc -vi -B -Tultibo -Parm -CpARMV7A -WpRPI2B @/home/pi/ultibo/core/fpc/bin/RPI2.CFG -O4 svd_FS_RPi2.lpr
Free Pascal Compiler version 3.1.1 [2019/05/15] for arm
Copyright (c) 1993-2015 by Florian Klaempfl and others
Target OS: Ultibo
Compiling svd_FS_RPi2.lpr
Compiling uTFTP.pas
Assembling utftp
svd_FS_RPi2.lpr(37,2) Note: Local variable "MyPLoggingDevice" not used
svd_FS_RPi2.lpr(39,2) Note: Local variable "Handle1" not used
svd_FS_RPi2.lpr(40,2) Note: Local variable "Handle3" not used
svd_FS_RPi2.lpr(42,2) Note: Local variable "Window" not used
Assembling svd_fs_rpi2
Linking svd_FS_RPi2
677 lines compiled, 4.4 sec, 2612340 bytes code, 87272 bytes data
4 note(s) issued
pi@mypi3-10wifi:~/Ultibo_Projects/svd/RPi2 $ tftp 192.168.1.202 < cmdstftp
tftp> tftp> Sent 2676120 bytes in 20.5 seconds Reads red.bin and creates reconst.bin & S.bin
pi@mypi3-10wifi:~/Ultibo_Projects/svd/RPi2 $ tftp 192.168.1.202 < pullit
tftp> tftp> tftp> Error code 5: 40189
Received 1024 bytes in 5.0 seconds
tftp> Error code 5: 39762
Received 262144 bytes in 6.1 seconds
pi@mypi3-10wifi:~/Ultibo_Projects/svd/RPi2 $ ./build_svd.sh 0
Compiling img_svd Reads red.bin and creates reconstrasp.bin & Srasp.bin
pi@mypi3-10wifi:~/Ultibo_Projects/svd/RPi2 $ ./img_svd
Octave reads the images created by RaspBian & Ultibo and looks at which pixels are different.
pi@mypi3-10wifi:~/Ultibo_Projects/svd/RPi2 $ octave
In the command window.
>> c_diff
Show that the pixel at 256 x 256 was different.
ans = 238
i = 256
j = 256
ans = 238
ans = 0
>> im4(256,256) = 0;
>> figure;
>> imagesc(im4);
>> colorbar
>> title "Ultibo"
Attachments
fix.png
fix.png (91.57 KiB) Viewed 256 times
diff.png
diff.png (179.99 KiB) Viewed 256 times
User avatar
Ultibo
Site Admin
Posts: 2257
Joined: Sat Dec 19, 2015 3:49 am
Location: Australia

Re: svd C lib ultibo does not match RaspBian

Postby Ultibo » Tue Jun 25, 2019 12:33 am

Hi develone,

I'm not sure I understand what you mean, I did a diff of the log outputs from your previous post and they were identical (once the extra information had been removed) but I can see that many pixels in the two images are different.

What do you mean by the pixel at 256 x 256 is different?

Also I would expect Octave to obtain the same results as Raspbian, it is written in C and uses the exact same C library that your compiled SVD test will be using.
Ultibo.org | Make something amazing
https://ultibo.org
develone
Posts: 308
Joined: Wed Dec 28, 2016 7:40 pm
Location: El Paso Tx USA

Re: svd C lib ultibo does not match RaspBian

Postby develone » Tue Jun 25, 2019 12:59 am

Ultibo,
There was only 1 pixel different at the very end of the image 256,256 when I made the value 0 the images look the same. The ultibo reconst.bin was 238 and the raspbian was 0. I still don't understand why they are different the code is the same in C and libsvd.a Let me know if I can provide additional information. The top display is the same when I chg the value from 238 to 0 at pixel 256,256.
User avatar
Ultibo
Site Admin
Posts: 2257
Joined: Sat Dec 19, 2015 3:49 am
Location: Australia

Re: svd C lib ultibo does not match RaspBian

Postby Ultibo » Tue Jun 25, 2019 11:41 pm

develone wrote:There was only 1 pixel different at the very end of the image 256,256 when I made the value 0 the images look the same. The ultibo reconst.bin was 238 and the raspbian was 0.

Thanks develone, that makes sense now.

My initial thought is that this sounds more like either an uninitialized variable in the C code which is being written to disk with a random value (or not so random depending on the position of the stack etc) or an off by one type of coding error in the C code which is writing a byte to disk that was not actually written by the program. Both of those are just theories but if either of them are correct then the results from both platforms might actually be incorrect.

Am I correct in thinking that the byte that is different (256,256) is actually the very last byte of the reconst.bin file?
Ultibo.org | Make something amazing
https://ultibo.org
develone
Posts: 308
Joined: Wed Dec 28, 2016 7:40 pm
Location: El Paso Tx USA

Re: svd C lib ultibo does not match RaspBian

Postby develone » Sat Jul 06, 2019 3:08 pm

Hello All,
Documentation is found

https://github.com/develone/Ultibo_Proj ... svd_ex.pdf

Continued work on my svd application and now have a threaded version.

Creates thread that reads red, grn, and blu images and performs the Single Value Decomposition
SVD. The singular values and the reconstructed image are written in files
that can be read by octave to display the results.
The master or ultibo_th_svd use two structures (FILEs & th_var)
found in master_slave.h
to pass infomation to the thread.

The image is read into a 2 Dim array



The Ultibo version provides a remote shell using telnet, tftp, and webstatus webpage.
I am using an older version of uTFTP.pas I believe created by Paul pjde
viewtopic.php?f=10&t=279&p=1003&hilit=uTFTP.pas#p1003
This might be the source of some of errors in the transfer from Ultibo to RaspBian.

tftp 192.168.1.202 < svdtftp
tftp> tftp> Error code 5: 39029
Received 1024 bytes in 5.1 seconds
tftp> Error code 5: 40503
Received 1024 bytes in 5.0 seconds
tftp> Error code 5: 35009
Received 1024 bytes in 5.1 seconds
tftp> Error code 5: 50019
Received 262144 bytes in 11.3 seconds
tftp> Error code 5: 49451
Received 262144 bytes in 6.0 seconds
tftp> Error code 5: 34059
Received 262144 bytes in 6.3 seconds
Attachments
thread_ex.png
thread_ex.png (244.95 KiB) Viewed 122 times

Return to “Discussion”

Who is online

Users browsing this forum: No registered users and 2 guests