Skip to main content
QUICK REVIEW

[Paper Review] DeepDSL: A Compilation-based Domain-Specific Language for Deep Learning

Tian Zhao, Xiao Bing Huang|arXiv (Cornell University)|Jan 9, 2017
Multimodal Machine Learning Applications3 citations
TL;DR

DeepDSL is a Scala-embedded domain-specific language that compiles deep neural networks into efficient, portable, and customizable Java source code via a two-phase optimization pipeline. It enables symbolic gradient derivation, static memory analysis, and code generation targeting CUDA through JNI, achieving competitive runtime performance and superior memory efficiency compared to Caffe and TensorFlow, especially under GPU memory constraints.

ABSTRACT

In recent years, Deep Learning (DL) has found great success in domains such as multimedia understanding. However, the complex nature of multimedia data makes it difficult to develop DL-based software. The state-of-the art tools, such as Caffe, TensorFlow, Torch7, and CNTK, while are successful in their applicable domains, are programming libraries with fixed user interface, internal representation, and execution environment. This makes it difficult to implement portable and customized DL applications. In this paper, we present DeepDSL, a domain specific language (DSL) embedded in Scala, that compiles deep networks written in DeepDSL to Java source code. Deep DSL provides (1) intuitive constructs to support compact encoding of deep networks; (2) symbolic gradient derivation of the networks; (3) static analysis for memory consumption and error detection; and (4) DSL-level optimization to improve memory and runtime efficiency. DeepDSL programs are compiled into compact, efficient, customizable, and portable Java source code, which operates the CUDA and CUDNN interfaces running on Nvidia GPU via a Java Native Interface (JNI) library. We evaluated DeepDSL with a number of popular DL networks. Our experiments show that the compiled programs have very competitive runtime performance and memory efficiency compared to the existing libraries.

Motivation & Objective

  • Address the limitations of existing deep learning libraries, which are fixed in interface, representation, and execution environment, restricting portability and customization.
  • Enable developers to define deep networks as high-level tensor functions in a strongly-typed language (Scala), improving code safety and maintainability.
  • Provide static analysis for early error detection and memory consumption estimation to prevent runtime failures such as out-of-memory exceptions.
  • Generate compact, human-readable, and customizable Java source code that can run on any platform with CUDA support via JNI.
  • Improve memory efficiency through static scheduling of tensor deallocation and runtime optimization, allowing larger batch sizes than Caffe or TensorFlow on the same GPU.

Proposed method

  • Embed deep learning constructs as domain-specific abstractions in Scala, representing tensors as indexed scalar expressions to expose computation at the DSL level.
  • Perform symbolic gradient derivation on tensor functions to automatically generate backpropagation logic without runtime overhead.
  • Apply two-phase optimization: first at the expression level (simplification, loop merging, code motion, vectorization), then to static single assignment (SSA) form for common subexpression elimination and inlining.
  • Generate target Java source code in a single-pass, string-based code generator that produces readable, modular code independent of the DSL expressions.
  • Integrate with JCuda to call CUDA kernels via JNI, enabling GPU acceleration while maintaining platform independence through the JVM.
  • Implement static memory analysis to predict runtime memory usage per layer and reschedule tensor deallocation to minimize peak memory consumption.

Experimental results

Research questions

  • RQ1Can a domain-specific language embedded in a general-purpose language like Scala achieve competitive performance and memory efficiency in deep learning while enabling full customization?
  • RQ2How effective is static analysis in detecting design errors and estimating memory consumption before compilation in deep learning DSLs?
  • RQ3To what extent can a two-phase optimization pipeline improve memory efficiency and runtime performance compared to existing deep learning libraries?
  • RQ4Can a compilation-based DSL generate portable, human-readable, and customizable Java code that runs efficiently on GPUs across different platforms?
  • RQ5How does the separation of optimization and code generation enable extensibility and maintainability in deep learning DSLs?

Key findings

  • DeepDSL-generated Java code achieves competitive runtime performance and memory efficiency, outperforming Caffe and TensorFlow in memory-constrained scenarios.
  • The static memory analysis in DeepDSL successfully prevents out-of-memory errors by predicting and optimizing memory usage, allowing ResNet training with a batch size of 64 on a single GPU, where Caffe and TensorFlow fail.
  • The two-phase optimization pipeline—expression-level simplification and SSA-based optimization—enables effective code motion, common subexpression elimination, and inlining, improving both memory and runtime efficiency.
  • Generated Java code is compact, human-readable, and customizable, allowing developers to modify or extend the implementation using standard IDEs or text editors.
  • The separation of DSL expression manipulation from code generation enables independent evolution of optimization techniques and target language backends, enhancing maintainability and extensibility.
  • While compilation time for complex networks like ResNet can take several minutes, the resulting code is highly optimized and suitable for deployment and further tuning.

Better researchstarts right now

From reading papers to final review, dramatically reduce your research time.

No credit card · Free plan available

This review was created by AI and reviewed by human editors.