summaryrefslogtreecommitdiff
path: root/var/spack/repos/builtin/packages/nccl-fastsocket/package.py
blob: f25862b2ebd3f2ed0c1d31450e0ac73794c4001b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# Copyright 2013-2023 Lawrence Livermore National Security, LLC and other
# Spack Project Developers. See the top-level COPYRIGHT file for details.
#
# SPDX-License-Identifier: (Apache-2.0 OR MIT)

import tempfile

from spack.package import *


class NcclFastsocket(Package):
    """NCCL Fast Socket GCP Net plugin for NCCL"""

    homepage = "https://github.com/google/nccl-fastsocket"
    git = "https://github.com/google/nccl-fastsocket.git"

    version("master", preferred=True)

    depends_on("bazel", type="build")
    depends_on("nccl", type=["build", "run"])

    maintainers("danielahlin")

    def setup_build_environment(self, env):
        spec = self.spec
        tmp_path = tempfile.mkdtemp(prefix="spack")
        env.set("TEST_TMPDIR", tmp_path)
        env.set("NCCL_INSTALL_PATH", spec["nccl"].prefix)
        env.set("NCCL_HDR_PATH", spec["nccl"].prefix.include)

    def install(self, spec, prefix):
        tmp_path = env["TEST_TMPDIR"]
        # Copied of py-tensorflow
        args = [
            # Don't allow user or system .bazelrc to override build settings
            "--nohome_rc",
            "--nosystem_rc",
            # Bazel does not work properly on NFS, switch to /tmp
            "--output_user_root=" + tmp_path,
            "build",
            "libnccl-net.so",
            # Spack logs don't handle colored output well
            "--color=no",
            "--jobs={0}".format(make_jobs),
            # Enable verbose output for failures
            "--verbose_failures",
            # Show (formatted) subcommands being executed
            "--subcommands=pretty_print",
            # Ask bazel to explain what it's up to
            # Needs a filename as argument
            "--explain=explainlogfile.txt",
            # Increase verbosity of explanation,
            "--verbose_explanations",
        ]
        bazel(*args)
        install_tree("bazel-bin", prefix.lib)

    def setup_run_environment(self, env):
        # The current plugin pickup method of NCCL is to scan for libraries with certain
        # names in the standard library search paths. Consequently, to make nccl-fastsocket
        # discoverable to NCCL it is necessary to add it to the LD_LIBRARY_PATH.
        env.prepend_path("LD_LIBRARY_PATH", self.prefix.lib)
        # NCCL_NET_PLUGIN can be used to change part of the library-name NCCL is looking
        # for. This is not necessary for this plugin so it is set to the empty string.
        env.set("NCCL_NET_PLUGIN", "")