Bug 92673 - Invalid typecast in expression
Summary: Invalid typecast in expression
Status: RESOLVED MOVED
Alias: None
Product: Beignet
Classification: Unclassified
Component: Beignet (show other bugs)
Version: unspecified
Hardware: Other All
: medium normal
Assignee: rongyang
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-10-26 10:28 UTC by ilia
Modified: 2018-10-12 21:22 UTC (History)
1 user (show)

See Also:
i915 platform:
i915 features:


Attachments
source code. (19.35 KB, text/plain)
2015-10-26 10:28 UTC, ilia
Details

Description ilia 2015-10-26 10:28:53 UTC
Created attachment 119196 [details]
source code.

Look at the lines 98 and 99 in attachment. Line 98 produces incorrect cosine result, line 99 produces correct - and it works this way only in beignet.

98(incorrect): sum += x[n] * cos((float)(M_PI * (n + .5) * k / N));
99  (correct): sum += x[n] * cos((float)(M_PI) * (float)((n + .5) * k) / (float)N);

(n, k, N are integers)

Seems like beignet first tries to evaluate 'k / N' as integer (or makes smth similar mistake).

To see it in action compile attachment with
gcc dcttest.c -O3 -ftree-loop-vectorize -ftree-loop-distribution -ftree-parallelize-loops=4  -floop-nest-optimize -floop-interchange  -floop-strip-mine -floop-block  -march=native -lOpenCL -lm -o dcttest

And run as
./dcttest platform device

(in my case './dcttest 0 0')
Comment 1 rongyang 2015-11-27 03:03:01 UTC
With beignet master(ec92544c387c5c2e3c7f6acfccddd353e7974e13), get correct result, please try again.

./dcttest 0 0
0.070000 seconds to calculate host values
Succeeded to create a device group!
        Device: 0
                Name:                           Intel(R) HD Graphics IvyBridge GT2
                Vendor:                         Intel
                Available:                      Yes
                Compute Units:                  16
                Clock Frequency:                1000 mHz
                Global Memory:                  2048 mb
                Max Allocateable Memory:        1536 mb
                Local Memory:                   65536 kb

Succeeded to create a compute context!
Succeeded to create a command commands!
Succeeded to create compute program!
Succeeded to create program executable!
Succeeded to create compute kernel!
Computed '8132/8192' correct values!
Computed '8132/8192' correct values!
Computed '8132/8192' correct values!
Computed '8132/8192' correct values!
Computed '8132/8192' correct values!
Computed '8132/8192' correct values!
Computed '8132/8192' correct values!
Computed '8132/8192' correct values!
Computed '8132/8192' correct values!
0.019000 average seconds to calculate gpu values

kernel is:
void dct_ii(int N, float *x, float *X) {
  float sum = 0.;
  for (int n = 0; n < N; ++n) {
    sum += x[n];
  }
  X[0] = sum;
  for (uint k = 1; k < N; ++k) {
    sum = 0.;
    for (int n = 0; n < N; ++n) {
      sum += x[n] * cos((float)(M_PI * (n + .5) * k / N));
      //sum += x[n] * cos((float)(M_PI) * (float)((n + .5) * k) / (float)N);
    }
    X[k] = sum;
  }
}
Comment 2 GitLab Migration User 2018-10-12 21:22:47 UTC
-- GitLab Migration Automatic Message --

This bug has been migrated to freedesktop.org's GitLab instance and has been closed from further activity.

You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.freedesktop.org/beignet/beignet/issues/9.


Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.