-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit ffa5ef5
Showing
17 changed files
with
626 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
.ghc.environment* | ||
cabal.project.local | ||
cabal.project.freeze | ||
.stack-work/ | ||
dist-newstyle/ | ||
result* | ||
*.swp | ||
*.lock | ||
**/.DS_Store | ||
*.pt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# Changelog | ||
|
||
`library-example` uses [PVP Versioning][1]. | ||
|
||
## 0.0.0.0 | ||
|
||
* Initially created. | ||
|
||
[1]: https://pvp.haskell.org |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2020 hasktorch | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Hasktorch Skeleton | ||
|
||
Similar to the [Cardano Skeleton](https://github.com/input-output-hk/cardano-skeleton), | ||
this repository serves as an example of how a downstream user of both Nix and Hasktorch | ||
can set up a development environment. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
packages: | ||
*.cabal | ||
|
||
source-repository-package | ||
type: git | ||
location: https://github.com/hasktorch/hasktorch | ||
tag: 291539b82cf23ca246fb67e55bf3689d94258b22 | ||
--sha256: 0hpk51q2zf3ccv90jlpiqy2g2mld8pimxjkk95rf8xil1piag4kl | ||
subdir: libtorch-ffi-helper | ||
|
||
source-repository-package | ||
type: git | ||
location: https://github.com/hasktorch/hasktorch | ||
tag: 291539b82cf23ca246fb67e55bf3689d94258b22 | ||
--sha256: 0hpk51q2zf3ccv90jlpiqy2g2mld8pimxjkk95rf8xil1piag4kl | ||
subdir: libtorch-ffi | ||
|
||
source-repository-package | ||
type: git | ||
location: https://github.com/hasktorch/hasktorch | ||
tag: 291539b82cf23ca246fb67e55bf3689d94258b22 | ||
--sha256: 0hpk51q2zf3ccv90jlpiqy2g2mld8pimxjkk95rf8xil1piag4kl | ||
subdir: hasktorch |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
############################################################################ | ||
# hasktorch-skeleton Nix build | ||
############################################################################ | ||
|
||
{ system ? builtins.currentSystem | ||
, crossSystem ? null | ||
# allows to customize ghc and profiling (see ./nix/haskell.nix): | ||
, config ? {} | ||
# allows to override dependencies of the hasktorch-skeleton project without modifications | ||
, sourcesOverride ? {} | ||
# If true, activates CUDA support | ||
, cudaSupport ? false | ||
# If cudaSupport is true, this needs to be set to a valid CUDA major version number, e.g. 10: | ||
# nix-build --arg cudaSupport true --argstr cudaMajorVersion 10 | ||
, cudaMajorVersion ? null | ||
# pinned version of nixpkgs augmented with various overlays including hasktorch | ||
, pkgs ? import ./nix/default.nix { | ||
inherit system crossSystem config sourcesOverride cudaSupport cudaMajorVersion; | ||
} | ||
}: | ||
|
||
# commonLib include iohk-nix utilities, our util.nix and nixpkgs lib. | ||
with pkgs; with commonLib; | ||
|
||
let | ||
|
||
haskellPackages = recRecurseIntoAttrs | ||
# the Haskell.nix package set, reduced to local packages. | ||
(selectProjectPackages hasktorchSkeletonHaskellPackages); | ||
|
||
libs = collectComponents' "library" haskellPackages; | ||
exes = collectComponents' "exes" haskellPackages; | ||
|
||
self = { | ||
inherit haskellPackages; | ||
|
||
inherit (haskellPackages.hasktorch-skeleton.identifier) version; | ||
|
||
# Grab library components of this package. | ||
inherit (libs) | ||
hasktorch-skeleton | ||
; | ||
|
||
# Grab executable components of this package. | ||
inherit (exes); | ||
|
||
# `tests` are the test suites which have been built. | ||
tests = collectComponents' "tests" haskellPackages; | ||
# `benchmarks` (only built, not run). | ||
benchmarks = collectComponents' "benchmarks" haskellPackages; | ||
|
||
checks = recurseIntoAttrs { | ||
# `checks.tests` collect results of executing the tests: | ||
tests = collectChecks haskellPackages; | ||
}; | ||
|
||
shell = import ./shell.nix { | ||
inherit pkgs; | ||
withHoogle = true; | ||
}; | ||
|
||
# Building the stack shell doesn't work in the sandbox. Pass `--option sandbox relaxed` or | ||
# `--option sandbox false` to be able to build this. You have to be root in order to that. | ||
# stackShell = import ./nix/stack-shell.nix { | ||
# inherit pkgs; | ||
# }; | ||
}; | ||
in | ||
self |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
cabal-version: 2.1 | ||
name: hasktorch-skeleton | ||
version: 0.0.0.0 | ||
synopsis: See README for more info | ||
description: See README for more info | ||
license: MIT | ||
license-file: LICENSE | ||
author: The Hasktorch Team | ||
maintainer: [email protected] | ||
copyright: 2020 The Hasktorch Team | ||
category: Tensors, Machine Learning, AI | ||
build-type: Simple | ||
extra-doc-files: README.md | ||
, CHANGELOG.md | ||
tested-with: GHC == 8.8.3 | ||
|
||
library | ||
hs-source-dirs: src | ||
exposed-modules: HasktorchSkeleton | ||
|
||
build-depends: base >= 4.7 && < 5 | ||
, hasktorch >= 0.2 && < 0.3 | ||
|
||
ghc-options: -Wall | ||
|
||
default-language: Haskell2010 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
{ system ? builtins.currentSystem | ||
, crossSystem ? null | ||
# Lets you customise ghc and profiling (see ./haskell.nix): | ||
, config ? {} | ||
# Lets you override niv dependencies of the project without modifications to the source. | ||
, sourcesOverride ? {} | ||
, cudaSupport ? false | ||
, cudaMajorVersion ? null | ||
}: | ||
|
||
# assert that the correct cuda versions are used | ||
assert cudaSupport -> (cudaMajorVersion == "9" || cudaMajorVersion == "10"); | ||
|
||
let | ||
sources = import ./sources.nix { inherit pkgs; } | ||
// sourcesOverride; | ||
iohKNix = import sources.iohk-nix {}; | ||
haskellNix = import sources.haskell-nix; | ||
# use our own nixpkgs if it exist in our sources, | ||
# otherwise use iohkNix default nixpkgs. | ||
nixpkgs = sources.nixpkgs-2003 or | ||
(builtins.trace "Using IOHK default nixpkgs" iohKNix.nixpkgs); | ||
|
||
# for inclusion in pkgs: | ||
overlays = | ||
# Haskell.nix (https://github.com/input-output-hk/haskell.nix) | ||
haskellNix.overlays | ||
# the haskell-nix.haskellLib.extra overlay contains some useful extra utility functions for haskell.nix | ||
++ iohKNix.overlays.haskell-nix-extra | ||
# the iohkNix overlay contains nix utilities and niv | ||
++ iohKNix.overlays.iohkNix | ||
# libtorch overlays from pytorch-world | ||
# TODO: pull in libGL_driver and cudatoolkit as done in https://github.com/NixOS/nixpkgs/blob/master/pkgs/games/katago/default.nix | ||
++ [ | ||
(pkgs: _: with pkgs; | ||
let libtorchSrc = callPackage "${sources.pytorch-world}/libtorch/release.nix" { }; in | ||
if cudaSupport && cudaMajorVersion == "9" then | ||
let libtorch = libtorchSrc.libtorch_cudatoolkit_9_2; in | ||
{ | ||
c10 = libtorch; | ||
torch = libtorch; | ||
torch_cpu = libtorch; | ||
torch_cuda = libtorch; | ||
} | ||
else if cudaSupport && cudaMajorVersion == "10" then | ||
let libtorch = libtorchSrc.libtorch_cudatoolkit_10_2; in | ||
{ | ||
c10 = libtorch; | ||
torch = libtorch; | ||
torch_cpu = libtorch; | ||
torch_cuda = libtorch; | ||
} | ||
else | ||
let libtorch = libtorchSrc.libtorch_cpu; in | ||
{ | ||
c10 = libtorch; | ||
torch = libtorch; | ||
torch_cpu = libtorch; | ||
} | ||
) | ||
] | ||
# our own overlays: | ||
++ [ | ||
(pkgs: _: with pkgs; { | ||
# commonLib: mix pkgs.lib with iohk-nix utils and sources: | ||
commonLib = lib // iohkNix | ||
// import ./util.nix { inherit haskell-nix; } | ||
# also expose sources, nixpkgs, and overlays | ||
// { inherit overlays sources nixpkgs; }; | ||
}) | ||
# haskell-nix-ified hasktorch-skeleton cabal project: | ||
(import ./pkgs.nix) | ||
]; | ||
|
||
pkgs = import nixpkgs { | ||
inherit system crossSystem overlays; | ||
config = haskellNix.config // config; | ||
}; | ||
|
||
in pkgs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
{ lib | ||
, stdenv | ||
, pkgs | ||
, haskell-nix | ||
, buildPackages | ||
, config ? {} | ||
# GHC attribute name | ||
, compiler ? config.haskellNix.compiler or "ghc883" | ||
# Enable profiling | ||
, profiling ? config.haskellNix.profiling or false | ||
# Enable CUDA support | ||
, cudaSupport ? false | ||
}: | ||
|
||
let | ||
|
||
src = haskell-nix.haskellLib.cleanGit { | ||
name = "hasktorch-skeleton"; | ||
src = ../.; | ||
}; | ||
|
||
# This creates the Haskell package set. | ||
# https://input-output-hk.github.io/haskell.nix/user-guide/projects/ | ||
pkgSet = haskell-nix.cabalProject { | ||
inherit src; | ||
|
||
compiler-nix-name = compiler; | ||
|
||
# these extras will provide additional packages | ||
# ontop of the package set derived from cabal resolution. | ||
pkg-def-extras = [ ]; | ||
|
||
modules = [ | ||
# Fixes for libtorch-ffi | ||
{ | ||
packages.libtorch-ffi = { | ||
configureFlags = [ | ||
"--extra-lib-dirs=${pkgs.torch}/lib" | ||
"--extra-include-dirs=${pkgs.torch}/include" | ||
"--extra-include-dirs=${pkgs.torch}/include/torch/csrc/api/include" | ||
]; | ||
flags = { | ||
cuda = cudaSupport; | ||
gcc = !cudaSupport && pkgs.stdenv.hostPlatform.isDarwin; | ||
}; | ||
}; | ||
} | ||
]; | ||
}; | ||
|
||
in | ||
pkgSet |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
pkgs: _: with pkgs; { | ||
hasktorchSkeletonHaskellPackages = import ./haskell.nix { | ||
inherit | ||
lib | ||
stdenv | ||
pkgs | ||
haskell-nix | ||
buildPackages | ||
config | ||
; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
{ | ||
"haskell-nix": { | ||
"branch": "master", | ||
"description": "Alternative Haskell Infrastructure for Nixpkgs", | ||
"homepage": "https://input-output-hk.github.io/haskell.nix", | ||
"owner": "input-output-hk", | ||
"repo": "haskell.nix", | ||
"rev": "794acb7b013e8b1508b0ab3aa28ac7c57344f4ea", | ||
"sha256": "1lnhmjwil5pc9r674ghh3iljcpa63gysj1shlmn23dnx83ish7v9", | ||
"type": "tarball", | ||
"url": "https://github.com/input-output-hk/haskell.nix/archive/794acb7b013e8b1508b0ab3aa28ac7c57344f4ea.tar.gz", | ||
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz" | ||
}, | ||
"iohk-nix": { | ||
"branch": "master", | ||
"description": "nix scripts shared across projects", | ||
"homepage": null, | ||
"owner": "input-output-hk", | ||
"repo": "iohk-nix", | ||
"rev": "ccad0bf9ceb3a68a837886f8032da0e70529d183", | ||
"sha256": "0hyzqbws8j1bvkb4m0ngck7mgs41p2wp9gy6ncvx1pf2svwz9916", | ||
"type": "tarball", | ||
"url": "https://github.com/input-output-hk/iohk-nix/archive/ccad0bf9ceb3a68a837886f8032da0e70529d183.tar.gz", | ||
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz" | ||
}, | ||
"niv": { | ||
"branch": "master", | ||
"description": "Easy dependency management for Nix projects", | ||
"homepage": "https://github.com/nmattia/niv", | ||
"owner": "nmattia", | ||
"repo": "niv", | ||
"rev": "f73bf8d584148677b01859677a63191c31911eae", | ||
"sha256": "0jlmrx633jvqrqlyhlzpvdrnim128gc81q5psz2lpp2af8p8q9qs", | ||
"type": "tarball", | ||
"url": "https://github.com/nmattia/niv/archive/f73bf8d584148677b01859677a63191c31911eae.tar.gz", | ||
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz" | ||
}, | ||
"nixpkgs-2003": { | ||
"branch": "nixpkgs-20.03-darwin", | ||
"description": "Nix Packages collection", | ||
"homepage": null, | ||
"owner": "NixOS", | ||
"repo": "nixpkgs", | ||
"rev": "cac363c661817666e43d047addfaa722610d425f", | ||
"sha256": "0fi8hgddy8qh2jrsa40jw7jxnr5lrhq2ji6a2xbndllivhzc31kf", | ||
"type": "tarball", | ||
"url": "https://github.com/NixOS/nixpkgs/archive/cac363c661817666e43d047addfaa722610d425f.tar.gz", | ||
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz" | ||
}, | ||
"pytorch-world": { | ||
"branch": "unstable", | ||
"description": "nix scripts for pytorch-related libraries", | ||
"homepage": "https://pytorch.org/", | ||
"owner": "stites", | ||
"repo": "pytorch-world", | ||
"rev": "5c6f66ec567b72c7ab053b3dbe2daef672d8849d", | ||
"sha256": "140a2l1l1qnf7v2s1lblrr02mc0knsqpi06f25xj3qchpawbjd4c", | ||
"type": "tarball", | ||
"url": "https://github.com/stites/pytorch-world/archive/5c6f66ec567b72c7ab053b3dbe2daef672d8849d.tar.gz", | ||
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz" | ||
} | ||
} |
Oops, something went wrong.