Geany for CUDA

Dari PaloDozen

Geany adalah integrated development environment (IDE) yang ringan, namun cukup canggih. Artikel ini membahas bagaimana mengkonfigurasi Geany agar dapat digunakan untuk mengkompilasi CUDA.

Daftar isi

Instalasi CUDA

Untuk pemasangan CUDA, silahkan lihat di:

Setelah selesai pastikan untuk membuat symbolic link ke folder CUDA sbb

cd $HOME
ln -sf CUDA-3.2 CUDA

Instalasi Geany

Instalasi Geany di Ubuntu adalah sebagai berikut:

sudo apt-get install geany geany-plugins

Skrip Persiapan

Buat scrip mkcuda berikut di $HOME/CUDA/C/src

#!/bin/sh
# make a new cuda project from template
 
PROJECT=$1
if [ ! -d template ]; then
   echo "Folder template does not exist."
   echo "Must call this program from the CUDA/C/src folder"
   exit 1
fi
 
echo Making project $PROJECT
 
cp -r template $PROJECT
 
cd $PROJECT
PE="s/template/$PROJECT/"
#echo $PE
rename  $PE template*
sed -i "s/template/$PROJECT/g" Makefile
for F in $PROJECT*; do
   sed -i "s/template/$PROJECT/g" $F
done
 
make
 
../../bin/linux/release/$PROJECT
 
echo A new project has been created at $PWD
echo You may use Geany to:
echo "- Create a new project $PROJECT"
echo "- Save the the project as project/$PROJECT.geany"
echo "- Set the base path to CUDA/C/src/$PROJECT"
echo "- Tick the Make in base path"
echo "- Set the run command to ../../bin/linux/release/$PROJECT"

Lalu ubah mode file agar bisa dieksekusi

[src]$ chmod a+c mkcuda

Persiapan Proyek

Misalkan kita ingin membuat proyek baru dengan nama cuda01. Maka mulailah membuat proyek dengan cara:

cd $HOME/CUDA/C/src
./mkcuda cuda01

Setelah selesai dan sukses, akan ada folder cuda01 dengan isi sebagai berikut:

[src]$ ls cuda01
Makefile  cuda01.cu  cuda01_gold.cpp  cuda01_kernel.cu	doc  obj

Proyek di Geany

Jalankan Geany, lalu:

  • Pilih menu Project - New. Isikan data "Name" dan "Base Path", lalu klik Create.

Berkas:Geany_CUDA_01.png

  • Pilih menu Peoject - Properties. Centang "Make ini base path", dan isikan "Run command".

Berkas:Geany_CUDA_02.png

  • Pada panel file, browse ke HOME/CUDA/C/src/cuda01, bukalah file "cuda01.cu", dan "cuda01_kernel.cu". Keduanya sudah berisi kode minimal program CUDA, silahkan di edit sesuai keperluan.
  • Jalankan proyek dengan memilih menu "Build - Make All", atau "Build - Execute".

CUDA Syntax Highlight

# For complete documentation of this file, please see Geany's main documentation

[styling]
# foreground;background;bold;italic
default=default
comment=comment
commentline=comment
commentdoc=commentdoc
number=number
word=keyword
word2=keyword2
string=string
character=string
uuid=extra
preprocessor=preprocessor
operator=operator
identifier=default
stringeol=stringeol
# @"verbatim"
verbatim=extra
# (/regex/)
regex=extra
commentlinedoc=commentdoc,bold
commentdockeyword=commentdoc,bold,italic
commentdockeyworderror=commentdoc
globalclass=type

[keywords]
# all items must be in one line
primary=and and_eq asm auto bitand bitor bool break case catch char class compl const const_cast continue default delete do double dynamic_cast else enum explicit export extern false float for friend goto if inline int long mutable namespace new not not_eq operator or or_eq private protected public register reinterpret_cast return short signed sizeof static static_cast struct switch template this throw true try typedef typeid typename union unsigned using virtual void volatile wchar_t while xor xor_eq __global__ __host__ __device__ __constant__ __shared__ gridDim blockIdx blockDim threadIdx int1 uint1 int2 uint2 int3 uint3 int4 uint4 float1 float2 float3 float4 char1 char2 char3 char4 uchar1 uchar2 uchar3 uchar4 short1 short2 short3 short4 dim1 dim2 dim3 dim4 tex1D tex1Dfetch tex2D __float_as_int __int_as_float __float2int_rn __float2int_rz __float2int_ru __float2int_rd __float2uint_rn __float2uint_rz __float2uint_ru __float2uint_rd __int2float_rn __int2float_rz __int2float_ru __int2float_rd __uint2float_rn __uint2float_rz __uint2float_ru __uint2float_rd __fadd_rz __fmul_rz __fdividef __mul24 __umul24 __mulhi __umulhi __mul64hi __umul64hi min umin fminf fmin max umax fmaxf fmax abs fabsf fabs sqrtf sqrt sinf __sinf sin cosf __cosf cos sincosf __sincosf expf __expf exp logf __logf log __syncthreads cudaFree
secondary=cudaGetDeviceCount cudaSetDevice cudaGetErrorString cudaMalloc cudaMemset cudaMemcpy cudaThreadSynchronize cudaEventCreate cudaEventRecord cudaEventSynchronize cudaEventElapsedTime stderr cudaError_t cudaSuccess cudaMemcpyDeviceToHost cudaMemcpyHostToDevice cudaEvent_t
# these are some doxygen keywords (incomplete)
docComment=attention author brief bug class code date def enum example exception file fn namespace note param remarks return see since struct throw todo typedef var version warning union

[lexer_properties]
styling.within.preprocessor=1
preprocessor.symbol.$(file.patterns.cu)=#
preprocessor.start.$(file.patterns.cu)=if ifdef ifndef
preprocessor.middle.$(file.patterns.cu)=else elif
preprocessor.end.$(file.patterns.cu)=endif

[settings]
tag_parser=C
lexer_filetype=C

# default extension used when saving files
extension=cu

# the following characters are these which a "word" can contains, see documentation
#wordchars=_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789

# if only single comment char is supported like # in this file, leave comment_close blank
comment_open=// 
comment_close=
# this is an alternative way, so multiline comments are used
#comment_open=/*
#comment_close=*/

# set to false if a comment character/string should start at column 0 of a line, true uses any
# indentation of the line, e.g. setting to true causes the following on pressing CTRL+d
	#command_example();
# setting to false would generate this
#	command_example();
# This setting works only for single line comments
comment_use_indent=true

# context action command (please see Geany's main documentation for details)
context_action_cmd=

# The following section doesn't work with geany > 0.19
[build_settings]
# %f will be replaced by the complete filename
# %e will be replaced by the filename without extension
# (use only one of it at one time)
compiler=nvcc -c "%f"
linker=nvcc "%f"
run_cmd="./%e"

# For those who use device emulation mode: just add -deviceemu after nvcc
[build-menu]
FT_00_LB=Compila con nvcc
FT_00_CM=nvcc -o "%e" %f
FT_00_WD=

FT_01_LB=Genera oggetto con nvcc
FT_01_CM=nvcc -o "%e.o" %f
FT_01_WD=

Pustaka


Kontributor: Mursito