{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Getting Started with DaCe\n", "\n", "DaCe is a Python library that enables optimizing code with ease, from running on a single core to a full supercomputer. With the power of data-centric transformations, it can automatically map code for CPUs, GPUs, and FPGAs.\n", "\n", "Let's get started with DaCe by importing it:" ] }, { "cell_type": "code", "execution_count": 16, "metadata": {}, "outputs": [], "source": [ "import dace" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "A data-centric program can be generated from several general-purpose and domain-specific languages. Our main frontend, however, is Python/numpy. To define a program, we take an existing function on numpy arrays and decorate it with `@dace.program`:" ] }, { "cell_type": "code", "execution_count": 17, "metadata": {}, "outputs": [], "source": [ "@dace.program\n", "def getstarted(A):\n", " return A + A" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Running our dace program, we will see several outputs and a prompt. These are the available transformations we can apply. For the first step, we opt to apply none (press Enter) and proceed with compilation and running:" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([[0.02638476, 0.15801766, 0.60640768],\n", " [0.75281897, 0.02027034, 0.92066681]])" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "import numpy as np\n", "a = np.random.rand(2, 3)\n", "a" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([[0.05276951, 0.31603533, 1.21281536],\n", " [1.50563794, 0.04054068, 1.84133362]])" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "getstarted(a)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The results are, as expected, `2*A`.\n", "\n", "Now, let's inspect the intermediate representation of the data-centric program, its Stateful Dataflow Multigraph (SDFG):" ] }, { "cell_type": "code", "execution_count": 18, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "