<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: connecting ArcPy and CUDA in Geoprocessing Questions</title>
    <link>https://community.esri.com/t5/geoprocessing-questions/connecting-arcpy-and-cuda/m-p/339062#M11896</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Thanks for this post, I'm sure this information will come in handy for quite a few people. For those wishing to get started with less hassle, there are pre-built binaries already available at &lt;A href="http://www.lfd.uci.edu/~gohlke/pythonlibs/#pycuda"&gt;http://www.lfd.uci.edu/~gohlke/pythonlibs/#pycuda&lt;/A&gt;&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Yep - I referenced that link up top.&amp;nbsp; In fact, when I had a purely 32bit configuration on another machine, the precompiled binary from that site worked great.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 19 Apr 2011 18:01:54 GMT</pubDate>
    <dc:creator>MikeTischler</dc:creator>
    <dc:date>2011-04-19T18:01:54Z</dc:date>
    <item>
      <title>connecting ArcPy and CUDA</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/connecting-arcpy-and-cuda/m-p/339060#M11894</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I've been working on creating a geoprocessing environment that links ArcPy with NVIDIA CUDA GPU capabilities for the past couple weeks, and didn't want my lessons learned to go to waste.&amp;nbsp; I'm really enjoying development in python in ArcGIS 10, and I came across the PyCUDA library which allows python integration into the CUDA API.&amp;nbsp; This takes a lot of patience, and still requires some serious development to create GPU code.&amp;nbsp; But, for those who like a challenge, here's how I got things to work.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;My system specs, the important parts:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Windows Server 2008 rc2 x64&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;TESLA S2050 GPU&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;64bit TESLA Driver&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;64bit CUDA Toolkit&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Microsoft Visual Studio 2008 64bit (the C++ parts especially)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;There are several issues that needed to be resolved, mostly dealing with the 32bit/64bit divide.&amp;nbsp; ArcGIS, and therefore ArcPy, are 32bit programs only, but need to communicate with 64bit CUDA drivers and toolkits, on a 64bit OS.&amp;nbsp; (Note: If you have a different configuration, you might be able to use one of the precompiled PyCuda binaries available here &lt;/SPAN&gt;&lt;A href="http://www.lfd.uci.edu/~gohlke/pythonlibs/#pycuda" rel="nofollow noopener noreferrer" target="_blank"&gt;http://www.lfd.uci.edu/~gohlke/pythonlibs/#pycuda&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;To start, I installed in this order&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;1.&amp;nbsp; Tesla Driver 263.06 winserv2008 rc2&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;2.&amp;nbsp; CUDA Toolkit 3.2.16 win64&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;3.&amp;nbsp; ArcGIS (and Python 2.6.5, 32bit)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;now comes the tricky part.&amp;nbsp; PyCuda (&lt;/SPAN&gt;&lt;A href="http://mathema.tician.de/software/pycuda" rel="nofollow noopener noreferrer" target="_blank"&gt;http://mathema.tician.de/software/pycuda&lt;/A&gt;&lt;SPAN&gt;) relies on a subset of a series of C++ libraries, the whole of which is called Boost.&amp;nbsp; Specifically, PyCuda needs 3 boost libraries...date_time, python, and thread.&amp;nbsp; In order to get everything to be friendly, I had to compile both PyCuda and the necessary boost libraries from source.&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;So...where to start?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;1.&amp;nbsp; Download Boost source&amp;nbsp; &lt;/SPAN&gt;&lt;A href="http://sourceforge.net/projects/boost/files/boost/1.46.1/boost_1_46_1.zip/download" rel="nofollow noopener noreferrer" target="_blank"&gt;http://sourceforge.net/projects/boost/files/boost/1.46.1/boost_1_46_1.zip/download&lt;/A&gt;&lt;BR /&gt;&lt;SPAN&gt;2.&amp;nbsp; Download PyCuda source &lt;/SPAN&gt;&lt;A href="http://pypi.python.org/packages/source/p/pycuda/pycuda-0.94.2.tar.gz#md5=d4651a015f1cc2b5702d969ff1519844" rel="nofollow noopener noreferrer" target="_blank"&gt;http://pypi.python.org/packages/source/p/pycuda/pycuda-0.94.2.tar.gz#md5=d4651a015f1cc2b5702d969ff1519844&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Let's say you're putting these in C:\working .&amp;nbsp; I created a directory called boost_src into which I copied and then unzipped the boost source code.&amp;nbsp; I extracted the PyCuda source into pycuda-0.94-2, which is the default extract directory. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Open a command line prompt and&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;cd c:\working\boost_src\boost_1_46_1&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;then &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;bootstrap&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;bootstrap will create the bjam.exe program, which is a compiler for the boost libraries.&amp;nbsp; Now, if you were to build and compile ALL the boost libraries, it would take quite a while.&amp;nbsp; So, we need to do just the few we're interested in: date_time, python, and thread.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;from the same command line prompt:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;/bjam python toolset=msvc link=shared threading=multi runtime-link=shared architecture=x86 address-model=32 stage&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;don't forget the slash at the beginning.&amp;nbsp; This tells the boost compiler to build .dll's that will work across the 32bit/64bit divide.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This command will take a few minutes.&amp;nbsp; The compiler is building not only the boost.python library (designated by the 'python' argument in the command), but the necessary dependency libraries.&amp;nbsp; Building the next two libraries will be quicker, as many of the dependency libraries are the same as the first. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;To build the 2nd and 3rd libraries, issue the same command, changing 'python' to 'date_time' and hit enter.&amp;nbsp; When that's done, change it one more time to 'thread' and hit enter.&amp;nbsp; That will create the necessary .dll's in the /stage directory in your boost root directory.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Ok - now to build PyCuda.&amp;nbsp; At this point, you may need to create an environmental variable called "PATH" (right click Computer, Properties,Advanced System Settings,Environment Variables, New) and add C:\Python26\ArcGIS10.0.&amp;nbsp; This will tell windows where to find the python.exe file.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;From the command line, :&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;cd c:\working\pycuda-0.94.2&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;and then:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;python configure.py&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;this will configure PyCuda for building and install.&amp;nbsp; A configuration file that can be opened and edited in wordpad is created called siteconf.py.&amp;nbsp; Several things will need to be edited here.&amp;nbsp; A working siteconf.py file may look like:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;BOOST_INC_DIR = ['C:/working/boost_src/boost_1_46_1']
BOOST_LIB_DIR = ['C:/working/boost_src/boost_1_46_1/stage/lib']
BOOST_COMPILER = 'msvc9'
USE_SHIPPED_BOOST = False
BOOST_PYTHON_LIBNAME = ['boost_python-vc90-mt-1_46_1']
BOOST_THREAD_LIBNAME = ['boost_thread-vc90-mt-1_46_1']
CUDA_TRACE = False
CUDA_ENABLE_GL = False
CUDA_ROOT = 'C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v3.2'
CUDADRV_LIB_DIR = ['C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v3.2/lib/Win32']
CUDADRV_LIBNAME = ['cuda']
CXXFLAGS = ['/EHsc','/DBOOST_ALL_NO_LIB']
LDFLAGS = ['/FORCE']&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This will tell pycuda where to find the right boost libraries, which compiler to use, as well as the CUDA toolkit and driver.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Now, you should be able to build and install pycuda.&amp;nbsp; Again, from the command line:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;python setup.py build&lt;/PRE&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;python setup.py install&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If all goes well, you should get a new directory in your C:\Python26\ArcGIS10.0\Lib\site-packages directory that's something like pycuda-0.94.2-py2.6-win32.egg.&amp;nbsp; There are a few things that SHOULD happen here automatically, but may not.&amp;nbsp; For example, the python libraries 'setuptools' and 'pytools' should automatically be downloaded, installed, and used for the PyCuda install.&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Now - you can check to see if things are working ok so far by issuing a few python commands.&amp;nbsp; Open a new command prompt, and make sure you're not in the pycuda directory where you issued the install command.&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;python&lt;/PRE&gt;&lt;SPAN&gt; to open a python prompt&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import pycuda.autoinit&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;pycuda.autoinit is the initialization procedure for PyCuda that connects to the GPU.&amp;nbsp; This is the most basic, most fundamental command and is usually the first command issued.&amp;nbsp; If you don't get any errors, GREAT!&amp;nbsp; You're almost home.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The last part deals with actually writing and compiling scripts.&amp;nbsp; PyCuda will work with the NVIDIA GPU compiler program 'nvcc' to compile code to run on the GPU.&amp;nbsp; But, nvcc has to be told to compile 32bit code, since we'll be using 32bit python to leverage ArcPy.&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Open C:\Python26\ArcGIS10.0\Lib\site-packages\pycuda-0.94.2-py2.6-win32.egg\pycuda\compiler.py and go all the way to the bottom.&amp;nbsp; You'll see a class called SourceModule that starts like:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;class SourceModule(object):
&amp;nbsp;&amp;nbsp;&amp;nbsp; def __init__(self, source, nvcc="nvcc", options=[], keep=False,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; no_extern_c=False, arch=None, code=None, cache_dir=None,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; include_dirs=[]):&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;You need to change the &lt;/SPAN&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;options[]&lt;/PRE&gt;&lt;SPAN&gt; to look like &lt;/SPAN&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;options=['-m32']&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;(the PyCuda development team is aware of this bug, which will be fixed in upcoming versions of PyCuda)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This tells nvcc to compile 32bit code.&amp;nbsp; Now, you should be able to run some test scripts using pycuda, similar to the one on the PyCuda documentation website &lt;/SPAN&gt;&lt;A href="http://documen.tician.de/pycuda/" rel="nofollow noopener noreferrer" target="_blank"&gt;http://documen.tician.de/pycuda/&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This worked for me, and it took me quite a while to figure out how to glue everything together.&amp;nbsp; But, now I am able to leverage all the ArcPy geoprocessing tasks with my custom GPU kernels.&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Now, don't get the wrong idea - you &lt;/SPAN&gt;&lt;STRONG style=": ; font-style: italic; text-decoration: underline;"&gt;WILL NOT&lt;/STRONG&gt;&lt;SPAN&gt; be able to run ArcGIS tools on a GPU.&amp;nbsp; That's up to ESRI.&amp;nbsp; But, this will allow you to build geoprocessing tasks that can be extended to work on a GPU.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;A few more things.&amp;nbsp; You will likely have to add more directories to your PATH environment variable.&amp;nbsp; Mine looks like this&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;C:\Python26\ArcGIS10.0;
C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC;
C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\bin;
C:\Program Files (x86)\Microsoft Visual Studio 9.0\Common7\IDE;
C:\working\boost_src\boost_1_46_1\stage\lib;
C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include&lt;/PRE&gt;&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Also, you'll see a few system variables (below the environment variables) related to the CUDA toolkit.&amp;nbsp; Specifically, you'll probably need to change &lt;/SPAN&gt;&lt;STRONG&gt;CUDA_LIB_PATH&lt;/STRONG&gt;&lt;SPAN&gt; to &lt;/SPAN&gt;&lt;STRONG&gt;%CUDA_PATH%\lib\Win32&lt;/STRONG&gt;&lt;SPAN&gt; instead of &lt;/SPAN&gt;&lt;STRONG&gt;%CUDA_PATH%\lib\x64&lt;/STRONG&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Hope this helps!&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Mike&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 16:02:29 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/connecting-arcpy-and-cuda/m-p/339060#M11894</guid>
      <dc:creator>MikeTischler</dc:creator>
      <dc:date>2021-12-11T16:02:29Z</dc:date>
    </item>
    <item>
      <title>Re: connecting ArcPy and CUDA</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/connecting-arcpy-and-cuda/m-p/339061#M11895</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thanks for this post, I'm sure this information will come in handy for quite a few people. For those wishing to get started with less hassle, there are pre-built binaries already available at &lt;/SPAN&gt;&lt;A href="http://www.lfd.uci.edu/~gohlke/pythonlibs/#pycuda"&gt;http://www.lfd.uci.edu/~gohlke/pythonlibs/#pycuda&lt;/A&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 19 Apr 2011 17:57:23 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/connecting-arcpy-and-cuda/m-p/339061#M11895</guid>
      <dc:creator>JasonScheirer</dc:creator>
      <dc:date>2011-04-19T17:57:23Z</dc:date>
    </item>
    <item>
      <title>Re: connecting ArcPy and CUDA</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/connecting-arcpy-and-cuda/m-p/339062#M11896</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Thanks for this post, I'm sure this information will come in handy for quite a few people. For those wishing to get started with less hassle, there are pre-built binaries already available at &lt;A href="http://www.lfd.uci.edu/~gohlke/pythonlibs/#pycuda"&gt;http://www.lfd.uci.edu/~gohlke/pythonlibs/#pycuda&lt;/A&gt;&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Yep - I referenced that link up top.&amp;nbsp; In fact, when I had a purely 32bit configuration on another machine, the precompiled binary from that site worked great.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 19 Apr 2011 18:01:54 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/connecting-arcpy-and-cuda/m-p/339062#M11896</guid>
      <dc:creator>MikeTischler</dc:creator>
      <dc:date>2011-04-19T18:01:54Z</dc:date>
    </item>
    <item>
      <title>Re: connecting ArcPy and CUDA</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/connecting-arcpy-and-cuda/m-p/339063#M11897</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thanks for this helpful post. but is there any examples to run a geoprocessing in this ArcPy &amp;amp;&amp;amp; CUDA environment ?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 20 May 2011 12:41:34 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/connecting-arcpy-and-cuda/m-p/339063#M11897</guid>
      <dc:creator>DINGXIANFENG</dc:creator>
      <dc:date>2011-05-20T12:41:34Z</dc:date>
    </item>
    <item>
      <title>Re: connecting ArcPy and CUDA</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/connecting-arcpy-and-cuda/m-p/339064#M11898</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Goodmanding - I've been working on an application that does preprocessing via ArcPy and additional geoprocessing through custom non-arcpy code via GPU, but it's not very solid yet.&amp;nbsp; Also, keep in mind that any gpu solution will change based on the GPU hardware (this is much different than CPU computing) and data configuration of your geoprocessing problem.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 20 May 2011 12:50:18 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/connecting-arcpy-and-cuda/m-p/339064#M11898</guid>
      <dc:creator>MikeTischler</dc:creator>
      <dc:date>2011-05-20T12:50:18Z</dc:date>
    </item>
  </channel>
</rss>

