Code Monkey home page Code Monkey logo

futhark-book's Introduction

Parallel Programming in Futhark

This material aims at introducing the reader to data-parallel functional programming using the Futhark language. It is work-in-progress, but probably constitutes the best introduction to Futhark programming.

Reading the Book

The book is readable in HTML form and PDF form at the following location:

http://futhark-book.readthedocs.io

Writing the Book

The book is written using Sphinx, which must be installed. You may also need to run this command to install further necessary dependencies:

pip install -r requirements.txt --user

The document is compiled by typing make html and the embedded Futhark code is compiled, executed, and tested by typing make test.

Generating a PDF version yourself

Simply type make latexpdf.

futhark-book's People

Contributors

acmiyaguchi avatar ahovgaard avatar athas avatar crclark avatar einar-io avatar izimbra avatar jasondavies avatar keesterbrugge avatar melsman avatar munksgaard avatar npn avatar pepijndevos avatar person142 avatar philass avatar snhl avatar titouanc avatar zfnmxt avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

futhark-book's Issues

Retargeting the Futhark Book

Martin and I have decided that it would be more useful for the book to be written primarily with browser-based access in mind, rather than the current setup which produces a PDF. While we may want to publish a traditional book eventually, it is clear that the vast majority of readers currently do not print the book. Since LaTeX is not useful for producing nice browser-readable output, we have to decide on a new formatting system. I have looked at some of the options.

Gitbook

GitBook is a command line tool (and Node.js library) for building beautiful books using GitHub/Git and Markdown (or AsciiDoc).

The Rust Programming Language is personally my main inspiration for what I would like the Futhark Book to be, and it is written with Gitbook (specifically, a reimplementation written in Rust). Gitbook supports LaTeX math via MathJax, but I am not certain that is enough for our needs.

Sphinx

Sphinx was originally designed as a documentation writing tool for Python projects, but has grown into a flexible and extensible system. It supports both Markdown and ReStructuredText (RST) as the formatting language. We already use Sphinx with RST for the Futhark reference manual, for which it works quite well, and my plan is for futhark-doc to also interpret documentation comments as RST. There may be value in using the same formatting system everywhere. Sphinx supports LaTeX math fairly well, rendering it to SVG or PNG during compilation. In fact, I found a textbook on theoretical physics written with Sphinx.

I will say Sphinx is the strongest contender, but we should ensure that I have not missed some crucial flaw that motivated Gitbook. I am also open to other options (but not Texinfo - I wasted enough of my youth on that mess).

Come up with some scheme for testing the code snippets in the book

We use futhark-test to test the larger examples in the src/ directory, but it's unfortunate that we don't have something similar for the smaller in-line snippets, since they occasionally break.

Breaking changes to the language are slowing down, so it probably won't happen as often in the future, but it would still be nice to have that extra safety.

4.2. Calling Futhark from C - Possible Error in Example Code

For the code in the example to run with the previously compiled shared library. I had to change line in luser.c from futhark_entry_dotprod(ctx, &res, x_arr, y_arr) to futhark_entry_main(ctx, &res, x_arr, y_arr).

#include <stdio.h>

#include "dotprod.h"
int main() {
  int x[] = { 1, 2, 3, 4 };
  int y[] = { 2, 3, 4, 1 };
  struct futhark_context_config *cfg = futhark_context_config_new();
  struct futhark_context *ctx = futhark_context_new(cfg);
  struct futhark_i32_1d *x_arr = futhark_new_i32_1d(ctx, x, 4);
  struct futhark_i32_1d *y_arr = futhark_new_i32_1d(ctx, y, 4);
  int res;
  futhark_entry_dotprod(ctx, &res, x_arr, y_arr); -- THIS LINE
 -- Should be 
 -- futhark_entry_main(ctx, &res, x_arr, y_arr);
  futhark_context_sync(ctx);
  printf("Result: %d\n", res);
  futhark_free_i32_1d(ctx, x_arr);
  futhark_free_i32_1d(ctx, y_arr);
  futhark_context_free(ctx);
  futhark_context_config_free(cfg);
}

I was using the C backend but I believe this would still be an issue with OpenCL backend compilation.

Escaping for underscores showing up in equations

If you check e.g.

https://futhark-book.readthedocs.io/en/latest/parallel-cost-model.html#futhark-the-language

you see ๐š›๐šŽ๐š๐šž๐šŒ๐šŽ\_๐šŒ๐š˜๐š–๐š–. The reason is that in the source that is done as (roughly)

\texttt{reduce\_comm}

and Mathjax doesn't handle text mode macros; see e.g.

https://docs.mathjax.org/en/latest/input/tex/differences.html

in particular:

First and foremost, the TeX input processor implements only the math-mode macros of TeX and LaTeX, not the text-mode macros.

You could fix it in the HTML by just removing the \, but it will then be incorrect in the LaTeX version (not sure if that's a concern). More involved solutions seem to involve things like putting

\usepackage{underscore}
\usepackage[T1]{fontenc}

into the preamble so that the bare _ works in LaTeX too. (Suggested here mathjax/MathJax#1770).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.