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

librealsense: refactor to allow use of cuda, and prepare for python integration #92997

Merged
merged 1 commit into from Aug 14, 2020

Conversation

freezeboy
Copy link
Contributor

@freezeboy freezeboy commented Jul 12, 2020

Motivation for this change

librealsense can be compiled to use CUDA to improve some algorithms.
This patch adds two conditional parametes to add python support and cuda
support

also adds two variations (like tensorflow does):

  • pkgs.librealsense (original, uses config.cudaSupport dynamically)
  • pkgs.librealsenseWithCuda - forces cudaSupport
  • pkgs.librealsenseWithoutCuda - forces no cudaSupport

and for python:

  • pkgs.python3Packages.pyrealsense2
  • pkgs.python3Packages.pyrealsense2WithCuda
  • pkgs.python3Packages.pyrealsense2WithoutCuda
Things done
  • Tested using sandboxing (nix.useSandbox on NixOS, or option sandbox in nix.conf on non-NixOS linux)
  • Built on platform(s)
    • NixOS
    • macOS
    • other Linux distributions
  • Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests)
  • Tested compilation of all pkgs that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • Determined the impact on package closure size (by running nix path-info -S before and after)
  • Ensured that relevant documentation is up to date
  • Fits CONTRIBUTING.md.

@freezeboy
Copy link
Contributor Author

Cuda versions are currently subject to this bug: IntelRealSense/librealsense#6573 (comment)
I don't plan to apply the patch as another PR is proposing an update to 2.36

Copy link
Member

@brian-dawn brian-dawn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have an easy way to test these changes but it looks good to me!

@brian-dawn
Copy link
Member

brian-dawn commented Jul 13, 2020

@freezeboy thanks for the changes. Since I don't use cuda with librealsense would you be interested in becoming a maintainer for the librealsense package?

@freezeboy
Copy link
Contributor Author

Yeah, no problem on my side even if I don't use it a lot either I can help you

cudaSupport = true;
};

librealsenseWithoutCuda = callPackage ../development/libraries/librealsense {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe the current convention is just to have no suffix

Suggested change
librealsenseWithoutCuda = callPackage ../development/libraries/librealsense {
librealsense = callPackage ../development/libraries/librealsense {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the "default" version uses config to switch, whereas this one forces to always "not" use cuda

pkgs/development/libraries/librealsense/default.nix Outdated Show resolved Hide resolved
pkgs/development/libraries/librealsense/default.nix Outdated Show resolved Hide resolved
pkgs/development/libraries/librealsense/default.nix Outdated Show resolved Hide resolved
pkgs/top-level/python-packages.nix Show resolved Hide resolved
pkgs/top-level/python-packages.nix Show resolved Hide resolved
pythonPackages = self;
});

pyrealsense2WithoutCuda = toPythonModule (pkgs.librealsenseWithoutCuda.override {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
pyrealsense2WithoutCuda = toPythonModule (pkgs.librealsenseWithoutCuda.override {
pyrealsense2 = toPythonModule (pkgs.librealsenseWithoutCuda.override {

pkgs/top-level/python-packages.nix Show resolved Hide resolved
@ofborg ofborg bot requested a review from brian-dawn July 14, 2020 08:20
@tpwrules
Copy link
Contributor

I made my own pyrealsense2 PR (mentioned above) without knowing this one existed.

Unfortunately, Intel changed the way they install the Python bindings with 2.36.0. Now that nixpkgs has moved to that version, this PR no longer builds using nixpkgs-review -pr 92997. You are welcome to take the patches I made in my PR to make yours work with 2.36.0. I don't have a way to test with CUDA, so it doesn't make sense to do it the other way.

I have a further patch to enable T265 support that will require consultation with the maintainers due to licensing issues. Not sure the best way to do that, but regardless I was going to wait until Python support was merged.

@freezeboy
Copy link
Contributor Author

I'll look at your method as I didn't check this update problem

@freezeboy
Copy link
Contributor Author

About the examples, I don't particularly care about building them as I don't need them, aren't they big ? should I add a flag to let the user remove them or it is not worth it ?

@freezeboy
Copy link
Contributor Author

rs-color, rs-depth and rs-distance cannot find some symbols from stdcpp library, e.g. :
librealsense2.so.2.36: undefined symbol: _ZNSt7__cxx1119basic_ostringstreamIcSt11char_traitsIcESaIcEEC1Ev

Do you know how this package is named in nix ?

@tpwrules
Copy link
Contributor

Following up on our conversation on IRC:

  1. You said you got the undefined symbol error resolved?

  2. The compiled command line example binaries sum to under 2 megabytes and are useful for testing and troubleshooting. I think they should be unconditionally built as there's no real penalty.

  3. Regarding the required Python packages, I believe you are correct, only python is required. Both setuptools and wheel can be removed. They were remnants of earlier experiments.

@freezeboy
Copy link
Contributor Author

  1. I added gcc.cc.lib as a buildInput to see if it is better

  2. No problem then

  3. Ok I cleanup

@ofborg ofborg bot requested a review from brian-dawn July 21, 2020 16:28
@tpwrules
Copy link
Contributor

I reviewed the latest commit with nixpkgs-review and the examples build and run fine. The Python module is built fine, but it doesn't appear to Python. I believe this is because python should be moved to propagatedBuildInputs so toPythonModule picks the module up.

After doing nix-shell -p nixpkgs-review --run "nixpkgs-review pr 92997 -p python38Packages.pyrealsense2", you should be able to print out any attached RealSense devices using the examples with results/python38Packages.pyrealsense2/bin/rs-enumerate-devices or with Python using python3 -c 'import pyrealsense2 as rs; print(list(rs.context().query_devices()))' (if there are no attached devices but it otherwise worked correctly, it will just print an empty list []).

@freezeboy
Copy link
Contributor Author

freezeboy commented Jul 21, 2020

what do you mean it doesn't appear to python, it looks like it is ok on my side ..

I usually use :
nix-shell -p nixpkgs-review --run "nixpkgs-review pr 92997 -p 'python38.withPackages (ps: with ps; [ pyrealsense2])'"

@tpwrules
Copy link
Contributor

We discussed on IRC and there was a misunderstanding on my end.

I'm happy with this PR and think it should be merged. I'll close mine out.

Copy link
Contributor

@jonringer jonringer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

diff LGTM, but only did a quick glance:

https://github.com/NixOS/nixpkgs/pull/92997
8 packages built:
librealsense librealsenseWithCuda python27Packages.pyrealsense2 python27Packages.pyrealsense2WithCuda python37Packages.pyrealsense2 python37Packages.pyrealsense2WithCuda python38Packages.pyrealsense2 python38Packages.pyrealsense2WithCuda

@jonringer
Copy link
Contributor

ping me tomorrow if no one merges

@nixos-discourse
Copy link

This pull request has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/prs-already-reviewed/2617/202

@freezeboy
Copy link
Contributor Author

well ping @jonringer

Copy link
Contributor

@jonringer jonringer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://github.com/NixOS/nixpkgs/pull/92997
8 packages built:
librealsense librealsenseWithCuda python27Packages.pyrealsense2 python27Packages.pyrealsense2WithCuda python37Packages.pyrealsense2 python37Packages.pyrealsense2WithCuda python38Packages.pyrealsense2 python38Packages.pyrealsense2WithCuda

@jonringer jonringer merged commit ff8e182 into NixOS:master Aug 14, 2020
@freezeboy freezeboy deleted the realsense-cuda branch August 20, 2020 07:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants