Skip to content

Commit

Permalink
Merge pull request #1 from dan-zheng/tutorial-edits
Browse files Browse the repository at this point in the history
Edit tutorial by @srush.
  • Loading branch information
srush authored Jan 9, 2021
2 parents 3bcda85 + 1288790 commit 0a5358d
Show file tree
Hide file tree
Showing 136 changed files with 5,338 additions and 5,329 deletions.
6 changes: 5 additions & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,12 @@ jobs:
run: rm -rf ~/.stack/setup-exe-cache
if: runner.os == 'macOS'

- name: Build, treating warnings as errors
run: make build-ci
if: runner.os == 'Linux'

- name: Build
run: make
run: make build

- name: Run tests
run: make tests
2 changes: 2 additions & 0 deletions .hlint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- arguments: [--color]
- ignore: {name: "Use fmap"}
36 changes: 22 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,33 @@ To learn more, check out our
or these example programs:

* [Dex prelude](https://google-research.github.io/dex-lang/prelude.html)
* [Mandelbrot set](https://google-research.github.io/dex-lang/mandelbrot.html)
* [Ray tracer](https://google-research.github.io/dex-lang/raytrace.html)
* [Estimating pi](https://google-research.github.io/dex-lang/pi.html)
* [Hamiltonian Monte Carlo](https://google-research.github.io/dex-lang/mcmc.html)
* [ODE integrator](https://google-research.github.io/dex-lang/ode-integrator.html)
* [Sierpinski triangle](https://google-research.github.io/dex-lang/sierpinski.html)
* [Basis function regression](https://google-research.github.io/dex-lang/regression.html)
* [Brownian bridge](https://google-research.github.io/dex-lang/brownian_motion.html)

Please note that Dex is an experimental research project at an early stage of
development. Contributions welcome!
* [Mandelbrot set](https://google-research.github.io/dex-lang/examples/mandelbrot.html)
* [Ray tracer](https://google-research.github.io/dex-lang/examples/raytrace.html)
* [Estimating pi](https://google-research.github.io/dex-lang/examples/pi.html)
* [Hamiltonian Monte Carlo](https://google-research.github.io/dex-lang/examples/mcmc.html)
* [ODE integrator](https://google-research.github.io/dex-lang/oexamples/de-integrator.html)
* [Sierpinski triangle](https://google-research.github.io/dex-lang/examples/sierpinski.html)
* [Basis function regression](https://google-research.github.io/dex-lang/examples/regression.html)
* [Brownian bridge](https://google-research.github.io/dex-lang/examples/brownian_motion.html)

🚨 **Dex is an experimental research project at an early stage of
development. Expect monstrous bugs and razor-sharp edges!**

🤝 **Contributions welcome!** See our issue tracker for [good first issues](https://github.com/google-research/dex-lang/labels/good%20first%20issue), or browse by [thematic labels](https://github.com/google-research/dex-lang/labels).

## Dependencies

* Install [stack](https://www.haskellstack.org)
* Install LLVM 9
* `apt-get install llvm-9-dev` on Ubuntu/Debian,
* `brew install llvm@9` on macOS, and ensure it is on your `PATH` e.g. via `export PATH="$(brew --prefix llvm@9)/bin:$PATH"` before building.
* Install libpng (often included by default in *nix)
* Ubuntu/Debian: `apt-get install llvm-9-dev`
* macOS: `brew install llvm@9`
* Make sure `llvm@9` is on your `PATH` before building. Example: `export PATH="$(brew --prefix llvm@9)/bin:$PATH"`
* Install clang (may be installed together with llvm)
* Ubuntu/Debian: `apt-get install clang`
* macOS: installs with llvm
* Install libpng (often included by default in *nix platforms)
* Ubuntu/Debian: `apt-get install libpng-dev`
* macOS: `brew install libpng`

## Building

Expand Down
6 changes: 3 additions & 3 deletions benchmarks/dexbench.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,15 @@ def restore_machine():
def run_benches(lang, backend):
if lang == "dex":
if backend == "CPU":
backend_args = ["--backend", "LLVM-MC"]
backend_args = ["--backend", "llvm-mc"]
env = {}
elif backend == "GPU":
backend_args = ["--backend", "LLVM-CUDA"]
backend_args = ["--backend", "llvm-cuda"]
env = {"CUDA_LAUNCH_BLOCKING":"1"}
else:
raise Exception
command = (["stack", "exec", "dex", "--"] + backend_args +
["script", "--outfmt", "JSON", dex_microbench_file])
["script", "--outfmt", "json", dex_microbench_file])
elif lang == "jax":
if backend == "CPU":
env = {"CUDA_VISIBLE_DEVICES":""}
Expand Down
13 changes: 13 additions & 0 deletions cabal.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
packages: dex.cabal

source-repository-package
type: git
location: https://github.com/llvm-hs/llvm-hs
tag: llvm-9
subdir: llvm-hs

source-repository-package
type: git
location: https://github.com/llvm-hs/llvm-hs
tag: llvm-9
subdir: llvm-hs-pure
66 changes: 32 additions & 34 deletions dex.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ name: dex
version: 0.1.0.0
author: Dougal Maclaurin
maintainer: [email protected]
license-file: LICENSE
build-type: Simple

flag cuda
Expand All @@ -32,17 +33,22 @@ library
exposed-modules: Env, Syntax, Type, Inference, JIT, LLVMExec,
Parser, Util, Imp, Imp.Embed, Imp.Optimize,
PPrint, Algebra, Parallelize, Optimize, Serialize
Actor, Cat, Flops, Embed,
Actor, Cat, Embed, Export,
RenderHtml, LiveOutput, Simplify, TopLevel,
Autodiff, Interpreter, Logging, PipeRPC, CUDA,
Autodiff, Interpreter, Logging, CUDA,
LLVM.JIT, LLVM.Shims
build-depends: base, containers, mtl, binary, bytestring,
time, tf-random, llvm-hs-pure ==9.*, llvm-hs ==9.*,
aeson, megaparsec >=8.0, warp, wai, filepath,
parser-combinators, http-types, prettyprinter, text,
blaze-html, cmark, diagrams-lib, ansi-terminal,
transformers, directory, mmap, unix,
process, primitive, store, dex-resources, temporary,
build-depends: base, containers, mtl, bytestring,
llvm-hs-pure, llvm-hs,
-- Parsing
megaparsec, parser-combinators,
-- Text output
prettyprinter, text,
-- Portable system utilities
filepath, directory, ansi-terminal, process, temporary,
-- Serialization
store,
-- Notebook support
warp, wai, blaze-html, aeson, http-types, cmark, binary
if !os(darwin)
exposed-modules: Resources
hs-source-dirs: src/resources
Expand All @@ -51,11 +57,12 @@ library
build-depends: dex-resources
default-language: Haskell2010
hs-source-dirs: src/lib
ghc-options: -Wall -fPIC
ghc-options: -Wall -fPIC -threaded -optP-Wno-nonportable-include-path
cxx-sources: src/lib/dexrt.cpp
cxx-options: -std=c++11 -fPIC
default-extensions: CPP, DeriveTraversable, TypeApplications, OverloadedStrings,
TupleSections, ScopedTypeVariables, LambdaCase, PatternSynonyms
TupleSections, ScopedTypeVariables, LambdaCase, PatternSynonyms,
BlockArguments
pkgconfig-depends: libpng
if flag(cuda)
include-dirs: /usr/local/cuda/include
Expand All @@ -71,42 +78,33 @@ executable dex
main-is: dex.hs
other-extensions: OverloadedStrings
build-depends: dex, base, haskeline, prettyprinter, mtl,
optparse-applicative, unix, store, bytestring, directory
optparse-applicative, ansi-wl-pprint,
unix, store, bytestring, directory
if os(darwin)
build-depends: dex-resources
default-language: Haskell2010
hs-source-dirs: src
default-extensions: CPP, LambdaCase
default-extensions: CPP, LambdaCase, BlockArguments
ghc-options: -optP-Wno-nonportable-include-path
if flag(optimized)
ghc-options: -O3
else
ghc-options: -O0

foreign-library Dex
type: native-shared
other-modules: API
build-depends: base, dex, dex-resources, mtl
hs-source-dirs: src/foreign
c-sources: src/foreign/rts.c
other-modules: Dex.Foreign.API, Dex.Foreign.Util, Dex.Foreign.JIT
, Dex.Foreign.Context, Dex.Foreign.Serialize
build-depends: base, mtl, containers, llvm-hs, dex, dex-resources
if os(darwin)
build-depends: dex-resources
hs-source-dirs: src/
c-sources: src/Dex/Foreign/rts.c
cc-options: -std=c11 -fPIC
ghc-options: -Wall -fPIC
default-language: Haskell2010
default-extensions: TypeApplications, ScopedTypeVariables, LambdaCase
if flag(optimized)
ghc-options: -O3
else
ghc-options: -O0

Test-Suite test-dex
type: exitcode-stdio-1.0
main-is: PropTests.hs
build-depends: dex, base, prettyprinter, containers,
hedgehog, microlens-platform, mtl
other-modules: GenExpr, TestPass
ghc-options: -Wall -fPIC -optP-Wno-nonportable-include-path
default-language: Haskell2010
hs-source-dirs: tests
ghc-options: cbits/libdex.so
-Wall
default-extensions: TypeApplications, ScopedTypeVariables, LambdaCase,
BlockArguments
if flag(optimized)
ghc-options: -O3
else
Expand Down
56 changes: 0 additions & 56 deletions examples/ad-tests-interp.dx

This file was deleted.

48 changes: 0 additions & 48 deletions examples/aspirational.dx

This file was deleted.

3 changes: 0 additions & 3 deletions examples/bad-binary-file.dxbo

This file was deleted.

26 changes: 13 additions & 13 deletions examples/brownian_motion.dx
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@

include "plot.dx"

UnitInterval = Float

bmIter : (Key & Float & Float & UnitInterval) -> (Key & Float & Float & UnitInterval) =
\(key, y, sigma, t).
(kDraw, kL, kR) = splitKey3 key
t' = abs (t - 0.5)
y' = sigma * randn kDraw * (0.5 - t')
key' = select (t > 0.5) kL kR
(key', y + y', sigma / sqrt 2.0, t' * 2.0)
def bmIter ((key, y, sigma, t):(Key & Float & Float & UnitInterval)) :
(Key & Float & Float & UnitInterval) =
[kDraw, kL, kR] = splitKey key
t' = abs (t - 0.5)
y' = sigma * randn kDraw * (0.5 - t')
key' = select (t > 0.5) kL kR
(key', y + y', sigma / sqrt 2.0, t' * 2.0)

sampleBM : Key -> UnitInterval -> Float =
\key t.
(_, y, _, _) = fold (key, 0.0, 1.0, t) \i:(Fin 10). bmIter
y
def sampleBM (key:Key) (t:UnitInterval) : Float =
(_, y, _, _) = fold (key, 0.0, 1.0, t) \i:(Fin 10). bmIter
y

xs = linspace (Fin 1000) 0.0 1.0
ys = map (sampleBM (newKey 0)) xs

-- :plot zip xs ys
-- > <html output>
:html showPlot $ xyPlot xs ys
> <html output>
35 changes: 0 additions & 35 deletions examples/bugs.dx

This file was deleted.

Loading

0 comments on commit 0a5358d

Please sign in to comment.