Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 4D87F200BFF for ; Tue, 17 Jan 2017 20:20:00 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id 4C5BA160B46; Tue, 17 Jan 2017 19:20:00 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 715AE160B30 for ; Tue, 17 Jan 2017 20:19:59 +0100 (CET) Received: (qmail 71889 invoked by uid 500); 17 Jan 2017 19:19:58 -0000 Mailing-List: contact dev-help@systemml.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@systemml.incubator.apache.org Delivered-To: mailing list dev@systemml.incubator.apache.org Received: (qmail 71877 invoked by uid 99); 17 Jan 2017 19:19:58 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd3-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 17 Jan 2017 19:19:58 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd3-us-west.apache.org (ASF Mail Server at spamd3-us-west.apache.org) with ESMTP id B814918066C for ; Tue, 17 Jan 2017 19:19:57 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd3-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 2.381 X-Spam-Level: ** X-Spam-Status: No, score=2.381 tagged_above=-999 required=6.31 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, HTML_MESSAGE=2, HTML_OBFUSCATE_05_10=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, RCVD_IN_SORBS_SPAM=0.5] autolearn=disabled Authentication-Results: spamd3-us-west.apache.org (amavisd-new); dkim=pass (1024-bit key) header.d=cs.washington.edu Received: from mx1-lw-us.apache.org ([10.40.0.8]) by localhost (spamd3-us-west.apache.org [10.40.0.10]) (amavisd-new, port 10024) with ESMTP id SSVdnNBlqCSs for ; Tue, 17 Jan 2017 19:19:55 +0000 (UTC) Received: from mail-oi0-f42.google.com (mail-oi0-f42.google.com [209.85.218.42]) by mx1-lw-us.apache.org (ASF Mail Server at mx1-lw-us.apache.org) with ESMTPS id AE0375F576 for ; Tue, 17 Jan 2017 19:19:54 +0000 (UTC) Received: by mail-oi0-f42.google.com with SMTP id u143so126200978oif.3 for ; Tue, 17 Jan 2017 11:19:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cs.washington.edu; s=goo201206; h=mime-version:in-reply-to:references:from:date:message-id:subject:to; bh=2aFk5ALo/A8ynykVRGumr9ucffp9RB9SGPjX6WeB3Bs=; b=c4snBbcmwXp4v7fDxy1iUnmJLMmYcIEskYRbaiIdq8bCrI5fENZoMEB4pEawyRiBJU 7Y8Jt8oV8vavZ2jg4owYTf3g1i2wPWSvsh/kZJUAWfDpsBJbdHin+B9u9WzvmbOX4nbN OT5J+rMlofbBzMzJx30/1+jOU3YS0aYu9DTHM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to; bh=2aFk5ALo/A8ynykVRGumr9ucffp9RB9SGPjX6WeB3Bs=; b=G+C+YmkD2qiwDSrak5eNwOX4TAiiy1yl1LB3Y+7ClcjlGreVvQcDY/5vq3nSomuGff 3tgW076Y6AFdAz0+uCmtymlOC7pCMuvB1NvBP/3u1Bvp3y7sY20M9mw+Ul7nI910z948 poM/V1PbqJbmqXruVMasqBs9SBbYfyp9uBJq0KQuWKTfBrS90UE9+Yi4xzPlPraW8HeZ zGpr0645gwuJbHw2HZoAjrMR+U+UxKp5Gyo1/pMHVILa05D2wGso3iuamiHO5AwSydBN SOhBOdxJr6j5OqTEYMR326vHKQFCJFdRaBNLa/MsqZDODoLNx0cRJGkoq8DrPvnKzkpd P5TA== X-Gm-Message-State: AIkVDXIwQYzjUDxOe7M42zrJHhSGyWci5nGDyBLbKM84OPrJnlQIrLAZ/PAYOFDXUcHbF1datf5s3pBPayJ4rQ== X-Received: by 10.202.52.212 with SMTP id b203mr17233562oia.99.1484680787465; Tue, 17 Jan 2017 11:19:47 -0800 (PST) MIME-Version: 1.0 Received: by 10.202.96.139 with HTTP; Tue, 17 Jan 2017 11:19:46 -0800 (PST) Received: by 10.202.96.139 with HTTP; Tue, 17 Jan 2017 11:19:46 -0800 (PST) In-Reply-To: <9d953ee8-5d88-bef6-f0bf-a0ec26fd4c7b@gmail.com> References: <9d953ee8-5d88-bef6-f0bf-a0ec26fd4c7b@gmail.com> From: Dylan Hutchison Date: Tue, 17 Jan 2017 11:19:46 -0800 Message-ID: Subject: Re: SystemML optimizer design To: dev@systemml.incubator.apache.org Content-Type: multipart/alternative; boundary=001a113cc9fef124d205464f2e1b archived-at: Tue, 17 Jan 2017 19:20:00 -0000 --001a113cc9fef124d205464f2e1b Content-Type: text/plain; charset=UTF-8 Wonderful explanations Matthias! Thank you for the history. On Jan 17, 2017 7:04 AM, "Matthias Boehm" wrote: Hi Dylan, these are very interesting questions - let me answer them one by one: 0. SPOOF: We developed the SPOOF compiler framework in a separate fork that will be integrated back into SystemML master soon. Initially, we will add the code generation part as an experimental feature, likely in our SystemML 1.0 release. The sum-product part will follow later because it's still in a very early stage. 1a. Rewrites: At a high-level, there are two types of rewrites: static and dynamic. Static rewrites are size-independent while dynamic rewrites depend on sizes in terms of constraints or costs. During initial compilation, intra- and inter-procedural analysis only propagates sizes that are valid over the entire program lifetime. The rewrites are then indeed applied in an in-place manner (i.e., "destructively"), which is ok because sizes are guaranteed not to change. However, during dynamic recompilation, we use exact sizes and recompile HOP DAGs very aggressively. In order to allow for non-reversible rewrites, we keep the original HOP DAG, create a deep copy, rewrite the copied HOP DAG and finally generate LOPs and executable instructions. You'll find the details here: https://github.com/apache/incubator-systemml/blob/master/ src/main/java/org/apache/sysml/hops/recompile/Recompiler.java 1b. Rewrite Phase Ordering: Determining the order or rewrites, which is often called phase ordering in compilers, is currently done manually with the context-knowledge of side effects between individual rewrites. This usually works very well in SystemML but gets more complicated as we add more rewrites and we've already seen a couple of cases were phase ordering problems led to suboptimal plans. As far as I know, there doesn't exist a principled approach to phase ordering in other compilers like GCC or LLVM either. 1c. Cost-based Optimization: Right now, different components use different cost functions and heuristics. For example, matrix multiplication chain optimization uses the number of floating point operations, operator selection of distributed matrix multiplications uses the I/O and shuffle costs weighted by the degree of parallelism, other decisions use simply the estimated size, and our resource optimizer uses a full-fledged time-based cost model regarding generated runtime plans (see https://github.com/apache/incubator-systemml/blob/master/ src/main/java/org/apache/sysml/hops/cost/CostEstimatorStaticRuntime.java). For SPOOF, we extended this time-based cost model. 2. Explain: Yes partially, we provide a flag -explain that allows investigating the generated plans at HOP level (-explain hops), at runtime level (-explain runtime), and during dynamic recompilation (-explain recompile_hops, -explain recompile_runtime). However, the HOP explain already shows the rewritten plans. As workarounds, you can (1) set the optimization level in SystemML-config.xml to 1 in order to see the initial plans without rewrites, or (2) set ProgramRewriter.LDEBUG=true (and rebuild SystemML) to see the applied rewrites. Furthermore, for task-parallel parfor programs you can add log=DEBUG in the parfor header to see the the plan before recompilation, after recompilation, and after rewrites along with some details on the individually applied rewrites. 3. Relationship to Apache Calcite: Well, Calcite is a cost-based optimizer for relational algebra. As mentioned in (0), our sum-product optimization is still in a very early stage. In SystemML master, we purely focus on linear algebra and statistical functions - hence, there is not much similarity. However, it is indeed an interesting question to build our sum-product optimizer on top of an existing rewrite framework such as Calcite, Spark's Catalyst optimizer, or the Columbia optimizer, etc. So far we tend to build it from scratch as our restricted linear algebra actually simplifies a couple of rewrites. I hope this gives a general overview - if you have further questions with regard to a specific topic, please just ask. Regards, Matthias On 1/17/2017 4:05 AM, Dylan Hutchison wrote: > Hi there, > > I learned about SystemML and its optimizer from the recent SPOOF paper > . The gist I > > absorbed is that SystemML translates linear algebra expressions given by > its DML to relational algebra, then applies standard relational algebra > optimizations, and then re-recognizes the result in linear algebra kernels, > with an attempt to fuse them. > > I think I found the SystemML rewrite rules here > src/main/java/org/apache/sysml/hops/rewrite>. > A couple questions: > > 1. It appears that SystemML rewrites HOP expressions destructively, > > i.e., by throwing away the old expression. In this case, how does > SystemML > determine the order of rewrites to apply? Where does cost-based > optimization come into play? > > 2. Is there a way to "debug/visualize" the optimization process? That > > is, when I start with a DML program, can I view (a) the DML program > parsed > into HOPs; (b) what rules fire and where in the plan, as well as the > plan > after each rule fires; and (c) the lowering and fusing of operators to > LOPs? > > I know this is a lot to ask for; I'm curious how far SystemML has gone > in this direction. > > 3. Is there any relationship between the SystemML optimizer and Apache > Calcite ? If not, I'd love to understand > > the design decisions that differentiate the two. > > Thanks, Dylan Hutchison > > --001a113cc9fef124d205464f2e1b--