- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello, I currently benchmark a linear support vector machine on the PSOC63. I trained the model offline and stored the model coefficients directly in the C code. Now I examined the follwing behaviour:
When executing the prediction on the PSOC I can record different execution times for different model data (but still same dimensions). The differences are about 2% of the execution time.
How is this possible? Are there any numerical effects that are important?
Thanks in advance.
Solved! Go to Solution.
- Labels:
-
PSoC 6 MCU
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I think it comes to how the compiler generates the assembly code to handle double precision point operations. The CPU only supports single floating-point operations, so it needs to combine multiple instructions to operate at double precision, which might take in consideration the number's signal.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi @Berni27,
Could you let us know the following:
- What is the model data that is being worked on? Could you specify finer details such as dimensions, etc?
- What kind of testing is being performed?
Could you share the project so that analyzing the same would be easier?
Best regards,
Nikhil
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi @ncbs , thanks for the quick answer.
I use a linear binary SVM with 500 feautres. Data is stored using 2 double arrays with 500 values each (one for the coefficients of the SVM, one for the data/features to perform the prediction on). Furthermore, there is one double values that represents the bias.
I measure the execution time of the SVM prediction, which baisically is just this code snippet:
The behaviour I can measure is that as soon as I change the data and coefficients to other values, then the execution time changes. I do not understand why as always the same mathematical operations are involved.
Kind regards,
Bernhard
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Can you try to disable the compiler optimization? Perhaps the compiler some how is able to optimize the code based on a given set of coefficients/bias.
If you are still seeing a difference, would you mind to share the project?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
It seems the double operation execution time is affected when dealing with negative numbers. By simply changing the equation:
prob += coefficients[i] * *(features+i);
to
prob -= coefficients[i] * *(features+i);
You would get a different execution time.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
@RodolfoGL thank you very much for your answer. Is there any explanation why operations with negative numbers are handeled differently?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I think it comes to how the compiler generates the assembly code to handle double precision point operations. The CPU only supports single floating-point operations, so it needs to combine multiple instructions to operate at double precision, which might take in consideration the number's signal.