Halide Tutorial 03
halideのデバッグ手法についてのチュートリアル。 C++オブジェクトは自身の名前を持たないので、Func gradient("gradient")とかをつけておく。 パイプラインの疑似コードが生成される。
#include "Halide.h" #include <stdio.h> using namespace Halide; int main(int argc, char **argv) { Func gradient("gradient"); Var x("x"), y("y"); gradient(x, y) = x + y; // Halide will also output an HTML version of this output, which // supports syntax highlighting and code-folding, so it can be // nicer to read for large pipelines. Open gradient.html with your // browser after running this tutorial. gradient.compile_to_lowered_stmt("gradient.html", {}, HTML); printf("Success!\n"); return 0; }
Halide Tutorial 02
概要
libpngを用いて入力した画像に対して処理を実行するチュートリアル。 入力した画像の輝度を1.5倍する。 Algorithm部分を分割(ワンラインではなく)してかけることを紹介している。
// Halide tutorial lesson 2: Processing images // The only Halide header file you need is Halide.h. It includes all of Halide. #include "Halide.h" // Include some support code for loading pngs. #include "halide_image_io.h" using namespace Halide::Tools; int main(int argc, char **argv) { // First we'll load the input image we wish to brighten. Halide::Buffer<uint8_t> input = load_image("images/rgb.png"); // Next we define our Func object that represents our one pipeline // stage. Halide::Func brighter; // Our Func will have three arguments, representing the position // in the image and the color channel. Halide treats color // channels as an extra dimension of the image. Halide::Var x, y, c; // Normally we'd probably write the whole function definition on // one line. Here we'll break it apart so we can explain what // we're doing at every step. // 1行で書くならこうだが、分割OK // brighter(x, y, c) = Halide::cast<uint8_t>(min(input(x, y, c) * 1.5f, 255)); // For each pixel of the input image. Halide::Expr value = input(x, y, c); // Cast it to a floating point value. value = Halide::cast<float>(value); // Multiply it by 1.5 to brighten it. Halide represents real // numbers as floats, not doubles, so we stick an 'f' on the end // of our constant. value = value * 1.5f; // Clamp it to be less than 255, so we don't get overflow when we // cast it back to an 8-bit unsigned int. value = Halide::min(value, 255.0f); // Cast it back to an 8-bit unsigned integer. value = Halide::cast<uint8_t>(value); // Define the function. brighter(x, y, c) = value; Halide::Buffer<uint8_t> output = brighter.realize(input.width(), input.height(), input.channels()); // Save the output for inspection. It should look like a bright parrot. save_image(output, "brighter.png"); // See figures/lesson_02_output.jpg for a small version of the output. printf("Success!\n"); return 0; }
実行コマンド
g++ lesson_02*.cpp -g -I ../include -I ../tools -L ../bin -lHalide `libpng-config --cflags --ldflags` -lpthread -ldl -o lesson_02 -std=c++11 -ljpeg LD_LIBRARY_PATH=../bin ./lesson_02
Halide Tutorial 01
x+yの加算関数と、画像のx座標とy座標のindexを加算するテストを作成するチュートリアル。 リポジトリの中のtutorialのコードにはわかりやすいコメントがいっぱい乗っているが、見返しやすいように最低限動く部分を抜き出してみた。 演算を定義してFuncに登録して解像度を指定する。 Hardware依存の部分の記述は今後のチュートリアルかな?
#include "Halide.h" #include <stdio.h> int main(int argc, char **argv) { Halide::Func gradient; Halide::Var x, y; Halide::Expr e = x + y; gradient(x, y) = e; Halide::Buffer<int32_t> output = gradient.realize(800, 600); // Let's check everything worked, and we got the output we were // expecting: for (int j = 0; j < output.height(); j++) { for (int i = 0; i < output.width(); i++) { // We can access a pixel of an Buffer object using similar // syntax to defining and using functions. if (output(i, j) != i + j) { printf("Something went wrong!\n" "Pixel %d, %d was supposed to be %d, but instead it's %d\n", i, j, i+j, output(i, j)); return -1; } } } printf("Success!\n"); return 0; }
g++ lesson_01*.cpp -g -I ../include -L ../bin -lHalide -lpthread -ldl -o lesson_01 -std=c++11 LD_LIBRARY_PATH=../bin ./lesson_01
Halide(release_2017_05_03) install @ubuntu16.04
参考url
https://github.com/halide/Halide/tree/release_2017_05_03
Halideのフォルダの直下でllvmとclangをビルドしてからhalideをビルドするらしい。 (Halideのgithubとかにそう書いてあるが別に直下におかなくてもいいのでは?) /opt/Halideにもろもろインストールしていく。
git clone https://github.com/halide/Halide.git cd Halide git checkout release_2017_05_03 #このフォルダ上でllvmとかclangビルド
build llvm and clang
私の環境では下記のものが追加で必要でした。
sudo apt install opam libxml2-dev
svn co https://llvm.org/svn/llvm-project/llvm/branches/release_37 llvm3.7 svn co https://llvm.org/svn/llvm-project/cfe/branches/release_37 llvm3.7/tools/clang cd llvm3.7 mkdir build cd build cmake -DLLVM_ENABLE_TERMINFO=OFF -DLLVM_TARGETS_TO_BUILD="X86;ARM;NVPTX;AArch64;Mips;PowerPC" -DLLVM_ENABLE_ASSERTIONS=ON -DCMAKE_BUILD_TYPE=Release .. make -j8
環境変数を.bashrcとかに追加しておく。
export LLVM_CONFIG=/opt/Halide/llvm3.7/build/bin/llvm-config export CLANG=/opt/Halide/llvm3.7/build/bin/clang
Halide build
cd .. #halide root directoryに移動 make -j8
環境変数を諸々追加
export HALIDE_ROOT=/opt/Halide export LD_LIBRARY_PATH="/opt/Halide/include:/opt/Halide/bin:$LD_LIBRARY_PATH"
インストール成功確認
# 環境変数読み込んでldconfigとかしておく(tutorial実行だけならいらない) cd tutorial g++ lesson_01*.cpp -g -I ../include -L ../bin -lHalide -lpthread -ldl -o lesson_01 -std=c++11 LD_LIBRATY_PATH=../bin ./lesson_01
上記を実行してSuccess!とでればOK
tmuxのキー操作をvim風にする設定
# prefixキーをC-aに変更する set -g prefix C-a # C-bのキーバインドを解除する unbind C-b # キーストロークのディレイを減らす set -sg escape-time 1 # ウィンドウのインデックスを1から始める set -g base-index 1 # ペインのインデックスを1から始める setw -g pane-base-index 1 # 設定ファイルをリロードする #bind r source-file ~/.tmux.conf \; display "Reloaded!" # C-a*2でtmux内のプログラムにC-aを送る bind C-a send-prefix # | でペインを縦に分割する bind | split-window -h # - でペインを横に分割する bind - split-window -v # Vimのキーバインドでペインを移動する bind h select-pane -L bind j select-pane -D bind k select-pane -U bind l select-pane -R bind -r C-h select-window -t :- bind -r C-l select-window -t :+ # Vimのキーバインドでペインをリサイズする bind -r H resize-pane -L 5 bind -r J resize-pane -D 5 bind -r K resize-pane -U 5 bind -r L resize-pane -R 5 # マウス操作を有効にする setw -g mouse on # 256色端末を使用する set-option -g default-terminal "screen-256color" # ステータスバーの色を設定する #set -g status-fg white #set -g status-bg black
ssh先のサーバでFlaskを実行しローカル環境ブラウザで閲覧
最近、多量のデータを取扱う事が多くなってきたので、DataBaseや可視化するためにWeb系の勉強を始めようと思います。 まずPythonのWebフレームワークのFlaskをSSHで接続しているサーバで使えるような設定を見つけたいと思います。 FlaskはPythonをAnacondaでインストールしているとデフォルトで入っているかつ軽量でかんたんに使えるらしいのでまずはこれでやってみます。
# app.py from flask import Flask app = Flask(__name__) @app.route("/") def index(): return "Hello World!" if __name__ == "__main__": app.run(host="0.0.0.0", port=8088)
ローカルの開発環境のブラウザでhttp://{ssh先のip address}:8088
でHello Worldと表示されます。
しかしこの方法では同一のローカルに入っている人全員にみえてしまうということか。。。 見られたくない場合は対策が必要!?
Centos7にRedmineをインストール
参考URL :
Centos インストール
bitnami インストール
https://cloudpack.media/10562
http://ossfan.net/setup/redmine-03.html
mysqlのインストール付近でエラーになるので以下のパッケージをインストールしておきます。
yum install -y perl-Data-Dumper
bitnamiを参考URLに従ってインストール
/opt/redmine
にインストール
ファイアウォール設定
firewall-cmd --permanent --add-service=http firewall-cmd --permanent --add-service=https firewall-cmd --reload
redmineを自動起動
systemctl list-unit-files -t service | grep redmine systemctl enable redmine.service
redmineテーマ変更
http://kuttsun.blogspot.jp/2015/10/bitnami-redmine-farendfancy.html
https://www.redminecrm.com/pages/a1-theme
/opt/redmine/apps/redmine/htdocs/public/themes
にテーマフォルダをおきます。