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

pythonPackages.chainer: init at 3.2.0 #33123

Merged
merged 6 commits into from Dec 28, 2017
Merged

Conversation

hyphon81
Copy link
Contributor

cupy: init at 2.2.0

nccl: init at 1.3.4

filelock: init at 2.0.13

fastrlock: init at 0.3

Motivation for this change

Adding the chainer and related packages.
The chainer is a python framework for writing neural networks codes.

Things done
  • Tested using sandboxing (nix.useSandbox on NixOS, or option build-use-sandbox in nix.conf on non-NixOS)
  • 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 nox --run "nox-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • Fits CONTRIBUTING.md.

}:

with pkgs;
with python.pkgs;
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of using python.pkgs, it is preferred to list the python dependencies as arguments to the derivation.

name = "cudatoolkit-${cudatoolkit.majorVersion}-nccl-${version}";
version = "1.3.4-1";

src = fetchurl {
Copy link
Contributor

Choose a reason for hiding this comment

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

fetchFromGitHub should be used instead https://nixos.org/nixpkgs/manual/#sec-sources

@@ -0,0 +1,43 @@
{ stdenv, pkgs, fetchurl, cudatoolkit }:
Copy link
Contributor

Choose a reason for hiding this comment

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

Dependencies should be listed explicitly, instead of using pkgs.

NVIDIA Collective Communications Library.
Multi-GPU and multi-node collective communication primitives.
'';
homepage = "https://developer.nvidia.com/nccl";
Copy link
Contributor

Choose a reason for hiding this comment

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

When possible, unquoted URLs are preferred.


CUDA_PATH = "${cudatoolkit}";
CFLAGS = "-I ${cudnn}/include -I ${nccl}/include";
LDFLAGS = "-L ${cudnn}/lib -L ${nccl}/lib";
Copy link
Contributor

Choose a reason for hiding this comment

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

Are these three lines necessary? It builds fine for me without them.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

According to cupy's official install guide document, we need set environment values when cupy will be installed with cuda, cudnn, nccl.
https://docs-cupy.chainer.org/en/stable/install.html#install-cupy-with-cuda
https://docs-cupy.chainer.org/en/stable/install.html#install-cupy-with-cudnn-and-nccl

Copy link
Contributor

Choose a reason for hiding this comment

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

If I understand the note correctly, it should not be necessary. Nix will add ${cudatoolkit}/bin/nvcc to PATH, as well as set the appropriate CFLAGS and LDFLAGS.

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 official document prefers to use pip installing and set envs with 'export'.
I'm worrying those environment values are needed in python phase.
I think Nix will not add CFLAGS and LDFLAGS to python.

Actually, those checks are in python.
https://github.com/cupy/cupy/blob/06e84b561aeba2d4abc5342fe5a7c1da894a436b/install/build.py#L33
https://github.com/cupy/cupy/blob/df93794d685560ac6f44b23528e81eb501e7871c/cupy_setup_build.py#L250

Copy link
Contributor

Choose a reason for hiding this comment

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

Nix sets those variables in python since it is based on mkDerivation.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry.
You are right, those settings are unnecessary.
I delete those.

I found out CUDA_PATH is unnecessary when PATH has ${cudatoolkit}/bin.
And I attempted building after delete those environment variables settings, and
chainer could find cudnn.

>>> import chainer
>>> chainer.cuda.available
True
>>> chainer.cuda.cudnn_enabled
True
>>> 

src = fetchFromGitHub {
owner = "NVIDIA";
repo = "nccl";
rev = "649f04d07711440ec2699ce7ec1af4ab71d6dbf9";
Copy link
Contributor

Choose a reason for hiding this comment

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

You can use rev = "v${version}";

cudatoolkit
];

BUILDDIR = "./";
Copy link
Contributor

@jtojnar jtojnar Dec 28, 2017

Choose a reason for hiding this comment

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

This should not be needed, the default build/ directory should be fine.

BUILDDIR = "./";
PREFIX = "$out";
CUDA_HOME = "${cudatoolkit}";
CUDA_LIB = "${cudatoolkit.lib}/lib";
Copy link
Contributor

Choose a reason for hiding this comment

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

These three variables should be in makeFlags:

  makeFlags = [
    "PREFIX=$(out)"
    "CUDA_HOME=${cudatoolkit}"
    "CUDA_LIB=${cudatoolkit.lib}/lib"
  ];

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks!

];

BUILDDIR = "./";
PREFIX = "$out";
Copy link
Contributor

Choose a reason for hiding this comment

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

This will set the PREFIX variable to literal $out string. The out variable needs to be interpolated somewhere, either by shell using preInstall = ''export PREFIX="$out"'';, or by make as suggested below. Correctly setting the variable will also allow you to get rid of the postInstall section.

@jtojnar
Copy link
Contributor

jtojnar commented Dec 28, 2017

@GrahamcOfBorg build nccl python2Packages.chainer python2Packages.cupy python3Packages.chainer python3Packages.cupy

Copy link

@GrahamcOfBorg GrahamcOfBorg left a comment

Choose a reason for hiding this comment

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

Failure for system: aarch64-linux

Package ‘cudatoolkit-8.0.61’ in /var/lib/gc-of-borg/nix-test-rs-1/repo/38dca4e3aa6bca43ea96d2fcc04e8229/builder/grahamc-aarch64-community-1/pkgs/development/compilers/cudatoolkit/default.nix:128 has an unfree license (‘unfree’), refusing to evaluate.

a) For `nixos-rebuild` you can set
  { nixpkgs.config.allowUnfree = true; }
in configuration.nix to override this.

b) For `nix-env`, `nix-build`, `nix-shell` or any other Nix command you can add
  { allowUnfree = true; }
to ~/.config/nixpkgs/config.nix.

Copy link

@GrahamcOfBorg GrahamcOfBorg left a comment

Choose a reason for hiding this comment

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

Failure for system: x86_64-darwin

Package ‘cudatoolkit-8.0.61’ in /Users/graham/nix-borg/repo/38dca4e3aa6bca43ea96d2fcc04e8229/builder/grahamc-zoidberg/pkgs/development/compilers/cudatoolkit/default.nix:128 has an unfree license (‘unfree’), refusing to evaluate.

a) For `nixos-rebuild` you can set
  { nixpkgs.config.allowUnfree = true; }
in configuration.nix to override this.

b) For `nix-env`, `nix-build`, `nix-shell` or any other Nix command you can add
  { allowUnfree = true; }
to ~/.config/nixpkgs/config.nix.

Copy link

@GrahamcOfBorg GrahamcOfBorg left a comment

Choose a reason for hiding this comment

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

Failure for system: x86_64-linux

Package ‘cudatoolkit-8.0.61’ in /var/lib/gc-of-borg/.nix-test-rs/repo/38dca4e3aa6bca43ea96d2fcc04e8229/builder/grahamc-zoidberg/pkgs/development/compilers/cudatoolkit/default.nix:128 has an unfree license (‘unfree’), refusing to evaluate.

a) For `nixos-rebuild` you can set
  { nixpkgs.config.allowUnfree = true; }
in configuration.nix to override this.

b) For `nix-env`, `nix-build`, `nix-shell` or any other Nix command you can add
  { allowUnfree = true; }
to ~/.config/nixpkgs/config.nix.

@jtojnar
Copy link
Contributor

jtojnar commented Dec 28, 2017

LGTM, could you please squash the fix-up commits?

@jtojnar jtojnar changed the title chainer: init at 3.2.0 pythonPackages.chainer: init at 3.2.0 Dec 28, 2017
}:

buildPythonPackage rec {
name = "${pname}-${version}";
Copy link
Member

Choose a reason for hiding this comment

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

name can be removed from buildPython* expressions

@jtojnar
Copy link
Contributor

jtojnar commented Dec 28, 2017

Thanks for your work.

@jtojnar jtojnar merged commit 7ccceea into NixOS:master Dec 28, 2017
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