Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unexpected numerical results with LLVM Native but not with the Interpreter #40

Open
1 of 3 tasks
tsoernes opened this issue Oct 22, 2018 · 2 comments
Open
1 of 3 tasks

Comments

@tsoernes
Copy link

tsoernes commented Oct 22, 2018

I am submitting a...

  • bug report
  • feature request
  • support request => you might also like to ask your question on the mailing list or gitter chat.

Description

Using LLVM as backend gives different results than using the Interpreter.

From a high-level view, ignoring everything thought irrelevant, I have a simulator executing an iterated function x' = f(x), where f adds or subtracts at most 1 from a subset of elements of x. Domain rules dictate that no element will ever leave the inclusive integer bound [0, 70], which holds true when running with the interpreter. When using LLVM, this does not hold true.

I am inclined to believe that this might be a bug outside of my program for the following reasons:

  • The simulator checks every iteration (given run-time flags below) if any element of x exceeds 70, and if so,
    prints out previous x (where no element should exceed the bounds, lest the simulator would have quit). x here refers to the slice of elements with depth 70 (which is maximum depth) for any spatial position in the 3D array freps, that is, in numpy notation, freps[:, :, -1].
  • Elements of x are only ever changed by f in increments or decrements of 1
  • Example observed value 283480585120

Steps to reproduce (for bugs)

  1. Clone
    https://github.com/tsoernes/haskelldca/tree/070ee164250fe1668392d18075de864107f3fde5
  2. Build
    stack build

Compare
stack exec dca-exe -- --backend interp --log_iter 1
against
stack exec dca-exe -- --backend cpu --log_iter 1

The interpreter runs without error and yields expected results.

The second, which uses LLVM, always quits due to previously mentioned check on "out of bounds" values, at a non-deterministic time (usually 200-1000 iterations which takes a minute or 2 on a laptop) despite there being no inherent randomness in the program (random seed is fixed). On exit, it will print (amongst other things), x and x', named Prev frep and Current frep respectively. "Prev" will be the last input without out-of-bounds values, while "Current" will have large values.

Your environment

  • Version used:
  • Backend(s) used and version:
  • accelerate-1.2.0.0
  • accelerate-llvm-1.2.0.0
  • accelerate-llvm-native-1.2.0.0
  • accelerate-blas-0.2.0.0
  • llvm-hs-6.0.0
  • llvm-hs-pure-6.0.0
  • GHC version: 8.4.3
  • Operating system and version: Linux Fedora 28
  • Link to your project: https://github.com/tsoernes/haskelldca/tree/overflow

Tell me if you need more information about or explanation of the code.

@tsoernes tsoernes changed the title Unexpected numerical results with LLVM but not with the Interpreter Unexpected numerical results with LLVM Native but not with the Interpreter Oct 22, 2018
@tsoernes
Copy link
Author

tsoernes commented Oct 22, 2018

As I just found out, both LLVM and the Interpreter gives the correct results when run with a different stack-yaml and .stack.work, that is, switching from this stack-yaml to this stack-yaml, and building with:
stack build --stack-yaml stack-release.yaml.

Do note that the two yamls uses different .stack-work directory, which might point to the problem being corruption of temporary files, however I have tried both stack clean and ./myprog +ACC -fflush-cache -fforce-recomp -ACC without effect.

@tmcdonell
Copy link
Member

Uh, that is very strange. I never use ghc-options in the stack.yaml files, so not sure if those are doing something unexpected, though I doubt it? That looks like the only difference between the two files, right?

I wonder if this bug is still lurking somewhere, or if this really was a strange incremental build problem... |:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants