Skip to content

Compile certain source files in libtensor with no-fast-math #1318

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

Merged
merged 2 commits into from
Aug 6, 2023

Conversation

oleksandr-pavlyk
Copy link
Contributor

Closes gh-1314 by compiling Python binding code converting float('nan') to a floating-point number using -fno-fast-math.

  • Have you provided a meaningful PR description?
  • Have you added a test, reproducer or referred to an issue with a reproducer?
  • Have you tested your changes locally for CPU and GPU devices?
  • Have you made sure that new changes do not introduce compiler warnings?
  • Have you checked performance impact of proposed changes?
  • If this PR is a work in progress, are you opening the PR as a draft?

To see that this is the right solution, use

// filename: nan.cpp
#include "pybind11/pybind11.h"

double fp_id(double x) {
  return x;
}

PYBIND11_MODULE(_nan, m) {
  m.def("fp_id", &fp_id);
}

Compile it

icpx nan.cpp --shared -fPIC $(python -m pybind11 --includes) -o _nan.so

and test with

python -c "import _nan; print(_nan.fp_id(float('nan')))"

With default compilation option -1 comes out, signaling an uncaught exception. It takes -fno-fast-math for it to round-trip correctly.

```
Python 3.9.12 (main, Jun  1 2022, 11:38:51)
Type 'copyright', 'credits' or 'license' for more information
IPython 8.4.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]: import dpctl.tensor as dpt, numpy as np

In [2]: dpt.full(10, fill_value=float('nan'), device='cpu', dtype=dpt.float64)
Out[2]: usm_ndarray([nan, nan, nan, nan, nan, nan, nan, nan, nan, nan])

In [3]: dpt.full(10, fill_value=float('nan'), device='cpu', dtype=dpt.float64)
Out[3]: usm_ndarray([nan, nan, nan, nan, nan, nan, nan, nan, nan, nan])

In [4]: dpt.full(10, fill_value=float('nan'), device='cpu', dtype=dpt.float32)
Out[4]: usm_ndarray([nan, nan, nan, nan, nan, nan, nan, nan, nan, nan], dtype=float32)

In [5]: quit
```
@github-actions
Copy link

github-actions bot commented Aug 1, 2023

@coveralls
Copy link
Collaborator

Coverage Status

coverage: 84.795%. remained the same when pulling 3baa622 on fix-gh-1314 into dcca136 on master.

@oleksandr-pavlyk oleksandr-pavlyk changed the title Compile certain files with Compile certain source files in libtensor with no-fast-math Aug 1, 2023
@github-actions
Copy link

github-actions bot commented Aug 1, 2023

Array API standard conformance tests for dpctl=0.14.6dev0=py310h7bf5fec_70 ran successfully.
Passed: 595
Failed: 405
Skipped: 119

@oleksandr-pavlyk oleksandr-pavlyk merged commit a1dd350 into master Aug 6, 2023
@oleksandr-pavlyk oleksandr-pavlyk deleted the fix-gh-1314 branch August 6, 2023 22:36
@github-actions
Copy link

github-actions bot commented Aug 6, 2023

Deleted rendered PR docs from intelpython.github.com/dpctl, latest should be updated shortly. 🤞

@github-actions
Copy link

github-actions bot commented Aug 6, 2023

Array API standard conformance tests for dpctl=0.14.6dev0=py310h7bf5fec_90 ran successfully.
Passed: 639
Failed: 361
Skipped: 119

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

Successfully merging this pull request may close these issues.

full and full_like do not work for fill_value=dpt.nan
3 participants