{"id":1052,"date":"2011-02-12T01:11:10","date_gmt":"2011-02-12T08:11:10","guid":{"rendered":"http:\/\/mcclanahoochie.com\/blog\/?p=1052"},"modified":"2015-04-26T20:50:42","modified_gmt":"2015-04-27T03:50:42","slug":"automake-and-cuda","status":"publish","type":"post","link":"https:\/\/mcclanahoochie.com\/blog\/2011\/02\/automake-and-cuda\/","title":{"rendered":"CUDA and Automake"},"content":{"rendered":"<p><em>Note:<\/em> I am by far no expert on this &#8211; (I only spent the past few days trying to wrap my head around automake, and before that, never opened a\u00a0<em>configure.ac<\/em> file before) &#8211; just wanted to share my experiences.<\/p>\n<p>Below is an excerpt from <em>configure.ac<\/em> and <em>Makefile.am<\/em> files I modified to add CUDA to an existing automake\/autoconf setup (the .. .. implies other unmodified\/existing lines).<\/p>\n<pre class=\"brush:bash\">#                     -*- configure.ac -*-\n# Process this file with autoconf to produce a configure script.\n..\n..\nAM_INIT_AUTOMAKE(no-dependencies)\nAC_CONFIG_HEADER([config.h])\n..\n..\n# initialize array index\nN=\"0\"\n..\n..\n\n#=================================================\n\n# Setup default CUDA paths\nCUDA_INSTALL_PATH=\"\/usr\/local\/cuda\"\nCUDA_SDK_INSTALL_PATH=\"\/usr\/local\/NVIDIA_GPU_Computing_SDK\"\n\n# Check: enable CUDA?\nAC_MSG_CHECKING([whether to use CUDA library])\nAC_ARG_ENABLE(cuda,\n    [AS_HELP_STRING(--enable-cuda,enable CUDA support)],\n    cudaval=\"yes\",\n    cudaval=\"no\")\nAC_MSG_RESULT([$cudaval])\n\n# check to see if CUDA been selected\nif test \"$cudaval\" == \"no\"; then\n    AC_MSG_WARN([Not using CUDA!])\nfi\n\n# Setup custom CUDA paths\nAC_ARG_WITH([cuda],\n   [AS_HELP_STRING(\n        [--with-cuda=PATH],\n        [prefix where CUDA is installed @&lt;:@default=auto@:&gt;@])],\n   [CUDA_INSTALL_PATH=$withval],\n   [with_cuda=auto])\nAC_ARG_WITH([cuda-sdk],\n   [AS_HELP_STRING(\n        [--with-cuda-sdk=PATH],\n        [prefix where CUDA SDK is installed @&lt;:@default=auto@:&gt;@])],\n   [CUDA_SDK_INSTALL_PATH=$withval],\n   [with_cuda_sdk=auto])\n\n# Setup nvcc flags\nif test  \"$cudaval\" = \"yes\"; then\n    NVCCFLAGS=\"$NVCCFLAGS\"\n    CUDA_CFLAGS=\"$CUDA_CFLAGS\"\n    CUDA_CFLAGS=\"$CUDA_CFLAGS -I$CUDA_SDK_INSTALL_PATH\/C\/common\/inc\/\"\n    CUDA_CFLAGS=\"$CUDA_CFLAGS -I$CUDA_INSTALL_PATH\/include\"\n    CUDA_LDFLAGS=\"-L$CUDA_INSTALL_PATH\/lib64\"\n    CUDA_LIBS=\"-lcuda -lcudart -lcufft\"\n    NVCCFLAGS=\"$NVCCFLAGS $CUDA_CFLAGS $CUDA_LDFLAGS $CUDA_LIBS\"\n    NVCC=\"nvcc\"\n    AC_SUBST(NVCC)\n    AC_SUBST(NVCCFLAGS)\n    AC_DEFINE([_CUDA],[1],[Defined if CUDA should be used])\n    eval \"ARRAY${N}='-D_CUDA'\"\n    N=`expr $N + 1`\nfi\n\n#=================================================\n..\n..\n# construct compiler flags\nN=`expr $N - 1`\nTMP0=\neval TMP0=\"\\$ARRAY0\"\nfor i in $(seq 1 $N)\ndo\n    eval TMP0=\"\\$TMP0' '\\$ARRAY${i}\"\ndone\n\n# set C compiler flags\nAC_SUBST(CDFLAGS, $TMP0)\n..\n..\n..<\/pre>\n<p>When <code><span style=\"color: #000000;\">--enable-cuda<\/span><\/code> is set, the above configure.ac will generate the variables <code><span style=\"color: #000000;\">NVCC<\/span><\/code> and <code><span style=\"color: #000000;\">NVCCFLAGS<\/span><\/code> for use in an Makefile.am, for example:<\/p>\n<pre class=\"brush:bash\">#\n#           -*- Makefile.am -*-\n\n..\n..\n\n.cu.o:\n    $(NVCC) $(NVCCFLAGS)  -c -o $@ $&lt;\n\n..\n..<\/pre>\n<p>In addition, a <code><span style=\"color: #000000;\">_CUDA<\/span><\/code> variable gets defined (<code><span style=\"color: #000000;\">#define _CUDA 1<\/span><\/code>), for use in any file getting compiled with the above Makefile.am\/configure.ac setup.<\/p>\n<p>Hopefully, this can save at least someone <em>else<\/em> time (as I&#8217;ve wasted enough on this), and give a nice pointer in the right direction to anyone interested in adding CUDA to an existing <code><span style=\"color: #000000;\">.\/configure<\/span><\/code> setup.<\/p>\n<p>Enjoy!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Note: I am by far no expert on this &#8211; (I only spent the past few days trying to wrap my head around automake, and before that, never opened a\u00a0configure.ac file before) &#8211; just wanted to share my experiences. Below is an excerpt from configure.ac and Makefile.am files I modified to add CUDA to an &#8230; <a title=\"CUDA and Automake\" class=\"read-more\" href=\"https:\/\/mcclanahoochie.com\/blog\/2011\/02\/automake-and-cuda\/\" aria-label=\"Read more about CUDA and Automake\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"advanced_seo_description":"","jetpack_seo_html_title":"","jetpack_seo_noindex":false,"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[1],"tags":[207,110,101],"class_list":["post-1052","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-automake","tag-cuda","tag-programming"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/pZdXI-gY","jetpack-related-posts":[{"id":881,"url":"https:\/\/mcclanahoochie.com\/blog\/2011\/01\/cuda-opencv-sobel\/","url_meta":{"origin":1052,"position":0},"title":"Misc CUDA + OpenCV Fun : Sobel Filter","author":"mcclanahoochie","date":"January 1, 2011","format":false,"excerpt":"March 2010 I recently started playing with the\u00a0Nvidia CUDA SDK Samples involving image processing. I extracted the\u00a0SobelFilter kernel and made\u00a0it run off my USB webcam using\u00a0OpenCV - the two live modes\u00a0are\u00a0single-channel-gray and\u00a0three-channel-rgb. I wrote two different basic kernels on my own that did\u00a0binary thresholding and found the most\u00a0dominant RGB value.\u2026","rel":"","context":"In \"cuda\"","block_context":{"text":"cuda","link":"https:\/\/mcclanahoochie.com\/blog\/tag\/cuda\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/mcclanahoochie.com\/blog\/wp-content\/uploads\/2011\/01\/cuda-fun.jpg?resize=350%2C200","width":350,"height":200},"classes":[]},{"id":929,"url":"https:\/\/mcclanahoochie.com\/blog\/2011\/01\/p3dfft-cuda-gpu-3d-fft\/","url_meta":{"origin":1052,"position":1},"title":"P3DFFT + CUDA (GPU 3D FFT)","author":"mcclanahoochie","date":"January 1, 2011","format":false,"excerpt":"December 2010 My first project as a GRA under Rich Vuduc involved accelerating 3D Fast Fourier Transforms (3D FFT) with GPUs. The project was basically porting the open-source P3DFFT code\u00a0(written in FORTRAN) to run on GPU(instead of CPU)\u00a0clusters using CUFFT. \u00a0 Update: 04\/16\/2011 - This project has morphed into a\u2026","rel":"","context":"In \"cuda\"","block_context":{"text":"cuda","link":"https:\/\/mcclanahoochie.com\/blog\/tag\/cuda\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/mcclanahoochie.com\/blog\/wp-content\/uploads\/2011\/01\/pencil-decomp.png?resize=350%2C200","width":350,"height":200},"classes":[]},{"id":611,"url":"https:\/\/mcclanahoochie.com\/blog\/2010\/09\/gtc-2010-trip\/","url_meta":{"origin":1052,"position":2},"title":"GTC 2010 Trip","author":"mcclanahoochie","date":"September 26, 2010","format":false,"excerpt":"I just got back from Nvidia's 2010 GPU Technology Conference in San Jose California. I had an amazing trip, and am thankful that I got to go, as it was my first visit to California as well as my first trade show attendance. [Side Note: The afternoon before the conference,\u2026","rel":"","context":"In \"arrayfire\"","block_context":{"text":"arrayfire","link":"https:\/\/mcclanahoochie.com\/blog\/tag\/arrayfire\/"},"img":{"alt_text":"Arriving at the 2010 GPU Tech Conference","src":"https:\/\/i0.wp.com\/mcclanahoochie.com\/blog\/wp-content\/uploads\/2010\/09\/2010-09-20_09-39-29_568-1024x577.jpg?resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/mcclanahoochie.com\/blog\/wp-content\/uploads\/2010\/09\/2010-09-20_09-39-29_568-1024x577.jpg?resize=350%2C200 1x, https:\/\/i0.wp.com\/mcclanahoochie.com\/blog\/wp-content\/uploads\/2010\/09\/2010-09-20_09-39-29_568-1024x577.jpg?resize=525%2C300 1.5x"},"classes":[]},{"id":1663,"url":"https:\/\/mcclanahoochie.com\/blog\/2011\/08\/cuda-connected-component-labeling\/","url_meta":{"origin":1052,"position":3},"title":"GPU Connected Component Labeling","author":"mcclanahoochie","date":"August 6, 2011","format":false,"excerpt":"Connected Component Labeling (CCL): \"is used in computer vision to detect connected regions in binary digital images\", and sometimes referred to as blob coloring. Motivation: To keep AccelerEyes'\u00a0ever expanding GPU library growing, over a few weeks of this summer\u00a0I took on the project of writing a CUDA version of connected\u2026","rel":"","context":"In \"arrayfire\"","block_context":{"text":"arrayfire","link":"https:\/\/mcclanahoochie.com\/blog\/tag\/arrayfire\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/mcclanahoochie.com\/blog\/wp-content\/uploads\/2011\/08\/coins-bwlabel-300x122.png?resize=350%2C200","width":350,"height":200},"classes":[]},{"id":886,"url":"https:\/\/mcclanahoochie.com\/blog\/2011\/01\/mtimes-gpu-matrix-multiplication\/","url_meta":{"origin":1052,"position":4},"title":"MTIMES &#8211; GPU Matrix Multiplication","author":"mcclanahoochie","date":"January 1, 2011","format":false,"excerpt":"July 2010 OK, it's not really a project, but I did learn a lot about GPU matrix multiplication over the summer, working\u00a0at AccelerEyes. I\u00a0re-worked the back-end CUDA code for\u00a0the MTIMES Jacket function. I also modified it to accelerate SUM, MIN, and\u00a0MAX. Checkout my MTIMES wiki page!","rel":"","context":"In \"arrayfire\"","block_context":{"text":"arrayfire","link":"https:\/\/mcclanahoochie.com\/blog\/tag\/arrayfire\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/mcclanahoochie.com\/blog\/wp-content\/uploads\/2011\/01\/fermi_gflops_single.jpg?resize=350%2C200","width":350,"height":200},"classes":[]},{"id":473,"url":"https:\/\/mcclanahoochie.com\/blog\/2010\/08\/yet-another-fresh-ubuntu-install-setup-script\/","url_meta":{"origin":1052,"position":5},"title":"Yet Another Fresh Install of Ubuntu Setup Script","author":"mcclanahoochie","date":"August 16, 2010","format":false,"excerpt":"Over the years of installing, updating, re-installing Ubuntu, I have slowly crafted a decent \"fresh install\" bash script to help setup and configure Ubuntu after a clean install. This script is ever evolving, and still doesn't capture everything I want it to, but it does knock out a giant chunk\u2026","rel":"","context":"In \"install\"","block_context":{"text":"install","link":"https:\/\/mcclanahoochie.com\/blog\/tag\/install\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"jetpack_likes_enabled":false,"_links":{"self":[{"href":"https:\/\/mcclanahoochie.com\/blog\/wp-json\/wp\/v2\/posts\/1052","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mcclanahoochie.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mcclanahoochie.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mcclanahoochie.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mcclanahoochie.com\/blog\/wp-json\/wp\/v2\/comments?post=1052"}],"version-history":[{"count":0,"href":"https:\/\/mcclanahoochie.com\/blog\/wp-json\/wp\/v2\/posts\/1052\/revisions"}],"wp:attachment":[{"href":"https:\/\/mcclanahoochie.com\/blog\/wp-json\/wp\/v2\/media?parent=1052"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mcclanahoochie.com\/blog\/wp-json\/wp\/v2\/categories?post=1052"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mcclanahoochie.com\/blog\/wp-json\/wp\/v2\/tags?post=1052"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}