Numerical Effects on Execution Time: Different Times for Different Data

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Berni27
Level 1
Level 1
5 sign-ins First reply posted First question asked

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.

0 Likes
1 Solution
RodolfoGL
Employee
Employee
250 solutions authored 250 sign-ins 5 comments on KBA

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.

View solution in original post

7 Replies
ncbs
Moderator
Moderator
Moderator
500 replies posted 50 likes received 250 sign-ins

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

0 Likes
Berni27
Level 1
Level 1
5 sign-ins First reply posted First question asked

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:

for (i = 0, l = current_features; i < l; i++) {
                prob += coefficients[i] * *(features+i);
                //printf("i:%d\n", i);
            }
            if (prob + intercepts > 0) {
                label = 1;
            }
            else label = 0;


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

0 Likes
RodolfoGL
Employee
Employee
250 solutions authored 250 sign-ins 5 comments on KBA

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?

0 Likes
lock attach
Attachments are accessible only for community members.
Berni27
Level 1
Level 1
5 sign-ins First reply posted First question asked

Hello,

I didn use any compiler optimization. I attached my project below.

The only thing I changed it the lines 16-21 and lines 45-50 to include or exclude the different datasets.

Thanks again.

0 Likes
RodolfoGL
Employee
Employee
250 solutions authored 250 sign-ins 5 comments on KBA

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.

0 Likes
Berni27
Level 1
Level 1
5 sign-ins First reply posted First question asked

@RodolfoGL thank you very much for your answer. Is there any explanation why operations with negative numbers are handeled differently?

 

0 Likes
RodolfoGL
Employee
Employee
250 solutions authored 250 sign-ins 5 comments on KBA

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.