Mercurial > hg > Papers > 2021 > okud-thesis
view paper/chapter/chapter2.tex @ 15:82407e7fefd9
fix
author | okud |
---|---|
date | Sun, 14 Feb 2021 15:40:34 +0900 |
parents | 1236fa28ffdd |
children | e8a0f9380734 |
line wrap: on
line source
\chapter{Continuation based C(CbC)} \section{Continuation based C(CbC)} Continuation based C(CbC)\cite{CbC}は、当研究室で開発を行っているプログラミング言語である。 CbCは、C言語の下位言語であり、関数呼び出しではなく継続を導入している。 CbCでは、関数の代わりにCodeGearという単位でプログラミングを行う。 CodeGearは入力と出力を持ち、CbCでは引数が入出力になっている。 図\ref{CbC}の様にCodeGearから次のCodeGearへとgotoによる継続で遷移して処理を行い、引数として出力を与える。 \begin{figure}[H] \begin{center} \includegraphics[width=100mm]{fig/CbC.png} \end{center} \caption{CbCの遷移} \label{CbC} \end{figure} CbCには、GCC\cite{gcc}上に実装されたものとLLVM/Clang\cite{llvm}上に実装されたものがある。 GCCとLLVM/Clangで実装されたCbCをARMでCompileするにはCross Compileを行う必要がある。 GCCとLLVMではCbCを動かすのにGCCの方が安定しているのでCbCのGCCのCrossCompile環境を作成する。 このCross Compile環境はSingularityで作成した。 \subsection{GCC} GCCは GNU Compiler Collectionの略でGNUプロジェクトが開発及び配布している、 C/C++/Object-C などのプログラミング言語のコンパイラ集のことである。 \subsection{LLVM/Clang} LLVMとは、モジュラー構成及び再利用可能なコンパイラとツールチェーン技術などを開発するプロジェクトの名称である。 ClangはLLVMをバックエンドとして利用するC/C++/Object-Cのコンパイラである。 \subsection{CrossCompile} Cross Compileは、Compilerが動作している以外のプラットフォーム向けに実行ファイルを生成する機能を持ったCompile手法である。 Raspbery Piでいうと、Raspbian以外のOS環境であらかじめRaspberry PiでCbCが動くようにCross Compileを行う。 そこで生成されたコードをRaspberry Piに移すことで、実行できる様になる。 \subsection{Singularity} Singularity\cite{singularity}とは、ユーザーが自身の計算環境を完全再現し、保持できる様にしたLinuxコンテナである。 Singularityはマルチユーザーに対応していて、コンテナ内の権限は実行ユーザーの権限を引き継ぐ。 そのため、ユーザーに特別な権限の設定が必要ない。 また、複雑なアーキテクチャとワークフローをサポートできるよう設計されていて、ほぼ全ての環境に適応できる。 さらに、デフォルトで、HOME,/tmp,/proc,/sys,/devがコンテナにマウントされ、サーバー上のGPUを簡単に利用できる。 コンテナイメージはSingularity Image Format(sif)と呼ばれる単一ファイルベースなため、アーカイブや共有が容易である。 \section{CbC on GCC CrossCompile } Singularityで環境を作成するためにソースコード\ref{src:cbc_gcc_cross}を作成する。 \renewcommand{\lstlistingname}{ソースコード} \lstinputlisting[language=Bash, numbers=left, breaklines=true, basicstyle=\ttfamily\footnotesize, frame=single, caption=CbC\_gcc\_cross.def, label=src:cbc_gcc_cross]{file/cbc_gcc_cross.def} defファイルが作成できたらsingularity buildを下記のように行う。 \begin{lstlisting}[frame=lrbt,label=sif build,caption={singularity build}] $ singularity build --fakeroot cbc_gcc_cross.sif cbc_gcc_cross.def \end{lstlisting} buildで生成されたsifソースコード\ref{code:cbc_gcc_arm_cross}でCrossCompileを行う。 例としてソースコード\ref{src:hello_cbc}を動かす。 \begin{lstlisting}[frame=lrbt,label=code:cbc_gcc_arm_cross,caption={singularity上でCrossCompile}] singularity shell cbc_gcc_cross.sif Singularity> arm-linux-gnueabihf-gcc src/hello.cbc Singularity> file a.out a.out: ELF 32-bit LSB executable, ARM, EABI5 version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-armhf.so.3, for GNU/Linux 3.2.0, not stripped \end{lstlisting} CrossCompileにより生成されたa.outがARM PlatformのRaspberry Piで実行することができる。 \lstinputlisting[language=Bash, numbers=left, breaklines=true, basicstyle=\ttfamily\footnotesize, frame=single, caption=hello.cbc, label=src:hello_cbc]{file/hello.cbc}