{"title":"Reconciling Abstraction with High Performance: A MetaOCaml approach","authors":"O. Kiselyov","doi":"10.1561/2500000038","DOIUrl":null,"url":null,"abstract":"A common application of generative programming is building highperformance computational kernels highly tuned to the problem at hand. A typical linear algebra kernel is specialized to the numerical domain (rational, float, double, etc.), loop unrolling factors, array layout and a priori knowledge (e.g., the matrix being positive definite). It is tedious and error prone to specialize by hand, writing numerous variations of the same algorithm. The widely used generators such as ATLAS and SPIRAL reliably produce highly tuned specialized code but are difficult to extend. In ATLAS, which generates code using printf, even balancing parentheses is a challenge. According to the ATLAS creator, debugging is nightmare. A typed staged programming language such as MetaOCaml lets us state a general, obviously correct algorithm and add layers of specializations in a modular way. By ensuring that the generated code always compiles and letting us quickly test it, MetaOCaml makes writing generators less daunting and more productive. The readers will see it for themselves in this hands-on tutorial. Assuming no prior knowledge of MetaOCaml and only a basic familiarity with functional programming, we will eventually implement a simple domain-specific language (DSL) for linear algebra, with layers of optimizations for sparsity and memory layout of matrices and vectors, and their algebraic properties. We will generate optimal BLAS kernels. We shall get the taste of the “Abstraction without guilt”. O. Kiselyov. Reconciling Abstraction with High Performance: A MetaOCaml approach. Foundations and Trends © in Programming Languages, vol. 5, no. 1, pp. 1–101, 2018. DOI: 10.1561/2500000038. Full text available at: http://dx.doi.org/10.1561/2500000038","PeriodicalId":376429,"journal":{"name":"Found. Trends Program. Lang.","volume":"76 1","pages":"0"},"PeriodicalIF":0.0000,"publicationDate":"2018-06-04","publicationTypes":"Journal Article","fieldsOfStudy":null,"isOpenAccess":false,"openAccessPdf":"","citationCount":"25","resultStr":null,"platform":"Semanticscholar","paperid":null,"PeriodicalName":"Found. Trends Program. Lang.","FirstCategoryId":"1085","ListUrlMain":"https://doi.org/10.1561/2500000038","RegionNum":0,"RegionCategory":null,"ArticlePicture":[],"TitleCN":null,"AbstractTextCN":null,"PMCID":null,"EPubDate":"","PubModel":"","JCR":"","JCRName":"","Score":null,"Total":0}
引用次数: 25
协调抽象与高性能:一种元ocaml方法
生成式编程的一个常见应用是构建针对当前问题高度调优的高性能计算内核。典型的线性代数核专门用于数值域(有理数,浮点数,双精度等),循环展开因子,数组布局和先验知识(例如,矩阵是正定的)。手工专门化编写相同算法的大量变体是乏味且容易出错的。广泛使用的生成器(如ATLAS和SPIRAL)可靠地生成高度调优的专用代码,但难以扩展。在使用printf生成代码的ATLAS中,即使是平衡括号也是一个挑战。根据ATLAS创建者的说法,调试是一场噩梦。类型化的分阶段编程语言(如MetaOCaml)允许我们声明一个通用的、明显正确的算法,并以模块化的方式添加专门化层。通过确保生成的代码总是可以编译,并允许我们快速测试它,MetaOCaml使编写生成器变得不那么令人生畏,而且更有效率。读者将在这个实践教程中看到它。假设没有MetaOCaml的先验知识,只对函数式编程有基本的了解,我们最终将实现一个简单的线性代数领域特定语言(DSL),其中包含对矩阵和向量的稀疏性和内存布局及其代数属性的优化层。我们将生成最优的BLAS核。我们将体会到“无罪抽象”的滋味。o·凯瑟列夫。协调抽象与高性能:一种元ocaml方法。基础与趋势©in Programming Languages, vol. 5, no. 5。1, pp. 1 - 101, 2018。DOI: 10.1561 / 2500000038。全文可在:http://dx.doi.org/10.1561/2500000038
本文章由计算机程序翻译,如有差异,请以英文原文为准。