(8553,18528,'2015-10-20 22:05:20','2015-10-20 22:05:20','Recently one of our interns completed his project ahead of schedule and asked if he could spend some time writing a particle filtering demo in ArrayFire for use at our upcoming trade shows. While learning the ins and outs of ArrayFire he posed several excellent questions which prompted us to start a series of blog posts entitled \"<a href=\"http://sandbox.arrayfire.com/tag/learning-arrayfire-from-scratch/\">Learning ArrayFire from scratch</a>\" that are geared to first-time users of our library.\r\n\r\nIn today\'s post I will cover the installation process on Windows, Mac, and Linux. Our next post will discuss the basics of setting up your first ArrayFire project.\r\n\r\n<!--more-->\r\n\r\nInstalling ArrayFire couldn\'t be easier. We ship installers for Windows, OSX, and Linux. Although you could <a href=\"https://github.com/arrayfire/arrayfire\">build ArrayFire from source</a>, we suggest using our pre-compiled binaries as they include the Intel Math Kernel Library to accelerate linear algebra functions.\r\n\r\nPlease note that although our download page requires a valid login, registration is free and downloading ArrayFire is also free. We request your contact information so that we may notify you of software updates and occasionally collect user feedback about our library.\r\n\r\nIn general, the installation process for ArrayFire looks like this:\r\n<ol type=\"1\">\r\n	<li>Install prerequisites</li>\r\n	<li><a href=\"http://sandbox.arrayfire.com/download/\">Download</a> the ArrayFire installer for your operating system</li>\r\n	<li>Install ArrayFire</li>\r\n	<li>Test the installation</li>\r\n	<li><a href=\"#GettingHelp\">Where to go for help?</a></li>\r\n</ol>\r\nBelow you will find instructions for\r\n<ul>\r\n	<li><a href=\"#Windows\">Windows</a></li>\r\n	<li>Linux including\r\n<ul>\r\n	<li><a href=\"#Debian\">Debian 8</a></li>\r\n	<li><a href=\"#Ubuntu\">Ubuntu 14.10 and later</a></li>\r\n	<li><a href=\"#Fedora\">Fedora 21</a></li>\r\n</ul>\r\n</li>\r\n	<li><a href=\"#OSX\">Mac OSX (.sh and brew)</a></li>\r\n</ul>\r\n<h3><a id=\"Windows\" class=\"anchor\"></a>Windows</h3>\r\nIf you wish to use CUDA or OpenCL please ensure that you have also installed support for these technologies from your video card vendor\'s website. After this, simply <a href=\"http://sandbox.arrayfire.com/download/\">download</a> and run the installer.\r\n<h3>Linux</h3>\r\n<h4><a id=\"Debian\" class=\"anchor\"></a>Debian 8</h4>\r\nFirst install the prerequisite packages:\r\n<pre class=\"fragment\"># Prerequisite packages:\r\napt-get install libfreeimage-dev libatlas3gf-base libfftw3-dev cmake\r\n\r\n# Enable GPU support (OpenCL):\r\napt-get install ocl-icd-libopencl1\r\n</pre>\r\nIf you wish to use CUDA, please <a href=\"https://developer.nvidia.com/cuda-zone\">download the latest version of CUDA</a> and install it on your system.\r\n\r\nNext <a href=\"http://sandbox.arrayfire.com/download/\">download</a> ArrayFire. After you have the file, run the installer.\r\n<pre class=\"fragment\">./arrayfire_*_Linux_x86_64.sh --exclude-subdir --prefix=/usr/local\r\n</pre>\r\n<h4><a id=\"Fedora\" class=\"anchor\"></a>Fedora 21</h4>\r\nFirst install the prerequisite packages:\r\n<pre class=\"fragment\"># Install prerequiste packages\r\nyum install freeimage atlas fftw cmake\r\n</pre>\r\nIf you wish to use CUDA, please <a href=\"https://developer.nvidia.com/cuda-downloads\">download the latest version of CUDA</a> and install it on your system.\r\n\r\nNext <a href=\"http://sandbox.arrayfire.com/download/\">download</a> ArrayFire. After you have the file, run the installer.\r\n<pre class=\"fragment\">./arrayfire_*_Linux_x86_64.sh --exclude-subdir --prefix=/usr/local\r\n</pre>\r\n<h4><a id=\"Ubuntu\" class=\"anchor\"></a>Ubuntu 14.10 and later</h4>\r\nFirst install the prerequisite packages:\r\n<pre class=\"fragment\"># Prerequisite packages:\r\nsudo apt-get install libfreeimage-dev libatlas3gf-base libfftw3-dev cmake\r\n</pre>\r\nIf you are using ArrayFire on the Tegra-K1 also install these packages:\r\n<pre class=\"fragment\">sudo apt-get install libatlas3gf-base libatlas-dev libfftw3-dev liblapacke-dev\r\n</pre>\r\nIf your system has a CUDA GPU, we suggest downloading the latest drivers from NVIDIA in the form of a Debian package and installing using the package manager. At present, CUDA downloads can be found on the <a href=\"https://developer.nvidia.com/cuda-downloads\">NVIDIA CUDA download page</a> Follow NVIDIA\'s instructions for getting CUDA set up.\r\n\r\nIf you wish to use OpenCL, simply install the OpenCL ICD loader along with any drivers required for your hardware.\r\n<pre class=\"fragment\"># Enable GPU support (OpenCL):\r\napt-get install ocl-icd-libopencl1\r\n</pre>\r\nFinally, <a href=\"http://sandbox.arrayfire.com/download/\">download</a> ArrayFire. After you have the file, run the installer using:\r\n<pre class=\"fragment\">./arrayfire_*_Linux_x86_64.sh --exclude-subdir --prefix=/usr/local\r\n</pre>\r\n<h3><a id=\"OSX\" class=\"anchor\"></a>Mac OSX</h3>\r\nOn OSX there are several dependencies that are not integrated into the operating system. The ArrayFire installer automatically satisfies these dependencies using <a href=\"http://brew.sh/\">Homebrew</a>. If you don\'t have Homebrew installed on your system, the ArrayFire installer will ask you do to so.\r\n\r\nSimply <a href=\"http://sandbox.arrayfire.com/download\">download</a> the ArrayFire installer and double-click it to carry out the installation.\r\n\r\nArrayFire can also be installed through Homebrew directly using <code>brew install arrayfire</code>; however, it will not include MKL acceleration of linear algebra functions.\r\n<h3><a id=\"Testing\" class=\"anchor\"></a>Testing the installation</h3>\r\nAfter ArrayFire is installed, you can build the example programs as follows:\r\n<pre class=\"fragment\">cp -r /usr/local/share/doc/arrayfire/examples .\r\ncd examples\r\nmkdir build\r\ncd build\r\ncmake ..\r\nmake\r\n</pre>\r\n<h3><a id=\"GettingHelp\" class=\"anchor\"></a>Getting help</h3>\r\n<ul>\r\n	<li>Google Groups: <a href=\"https://groups.google.com/forum/#!forum/arrayfire-users\">https://groups.google.com/forum/#!forum/arrayfire-users</a></li>\r\n	<li>ArrayFire Services: <a href=\"http://sandbox.arrayfire.com/consulting/\">Consulting</a> | <a href=\"http://sandbox.arrayfire.com/support/\">Support</a> | <a href=\"http://sandbox.arrayfire.com/training/\">Training</a></li>\r\n	<li>ArrayFire Blogs: <a href=\"http://sandbox.arrayfire.com/blog/\">http://sandbox.arrayfire.com/blog/</a></li>\r\n	<li>Email: <a href=\"#\">technical@arrayfire.com</a></li>\r\n</ul>\r\n&nbsp;','Learning ArrayFire from scratch: Installation','','inherit','open','closed','','8542-revision-v1','','','2015-10-20 22:05:20','2015-10-20 22:05:20','',8542,'http://sandbox.arrayfire.com/8542-revision-v1/',0,'revision','',0),(8555,18528,'2015-10-21 15:10:00','2015-10-21 15:10:00','Recently one of our interns completed his project ahead of schedule and asked if he could spend some time writing a particle filtering demo in ArrayFire for use at our upcoming trade shows. While learning the ins and outs of ArrayFire he posed several excellent questions which prompted us to start a series of blog posts entitled \"<a href=\"http://sandbox.arrayfire.com/tag/learning-arrayfire-from-scratch/\">Learning ArrayFire from scratch</a>\" that are geared to first-time users of our library.\r\n\r\nIn today\'s post I will cover the installation process on Windows, Mac, and Linux. Our next post will discuss the basics of setting up your first ArrayFire project.\r\n\r\n<!--more-->\r\n\r\nInstalling ArrayFire couldn\'t be easier. We ship installers for Windows, OSX, and Linux. Although you could <a href=\"https://github.com/arrayfire/arrayfire\">build ArrayFire from source</a>, we suggest using our pre-compiled binaries as they include the Intel Math Kernel Library to accelerate linear algebra functions.\r\n\r\nPlease note that although our download page requires a valid login, registration is free and downloading ArrayFire is also free. We request your contact information so that we may notify you of software updates and occasionally collect user feedback about our library.\r\n\r\nIn general, the installation process for ArrayFire looks like this:\r\n<ol type=\"1\">\r\n	<li>Install prerequisites</li>\r\n	<li><a href=\"http://sandbox.arrayfire.com/download/\">Download</a> the ArrayFire installer for your operating system</li>\r\n	<li>Install ArrayFire</li>\r\n	<li>Test the installation</li>\r\n	<li><a href=\"#GettingHelp\">Where to go for help?</a></li>\r\n</ol>\r\nBelow you will find instructions for\r\n<ul>\r\n	<li><a href=\"#Windows\">Windows</a></li>\r\n	<li>Linux including\r\n<ul>\r\n	<li><a href=\"#Debian\">Debian 8</a></li>\r\n	<li><a href=\"#Ubuntu\">Ubuntu 14.10 and later</a></li>\r\n	<li><a href=\"#Fedora\">Fedora 21</a></li>\r\n</ul>\r\n</li>\r\n	<li><a href=\"#OSX\">Mac OSX (.sh and brew)</a></li>\r\n</ul>\r\n<h3><a id=\"Windows\" class=\"anchor\"></a>Windows</h3>\r\nIf you wish to use CUDA or OpenCL please ensure that you have also installed\r\nsupport for these technologies from your video card vendor\'s website.\r\n\r\nNext <a href=\"http://sandbox.arrayfire.com/download/\">download</a> and run the ArrayFire installer.\r\nAfter it has completed, you need to add ArrayFire to the path for all users.\r\n<ol>\r\n	<li>Open Advanced System Settings:\r\n* Windows 8: Move the Mouse pointer to the bottom right corner of the screen, Right click, choose System. Then click \"Advanced System Settings\"\r\n* Windows 7: Open the Start Menu and Right Click on \"Computer\". Then choose Properties and click \"Advanced System Settings\"</li>\r\n	<li>In Advanced System Settings window, click on Advanced tab</li>\r\n	<li>Click on Environment Variables, then under System Variables, find PATH, and click on it.</li>\r\n	<li>In edit mode, append %AF_PATH%/lib. NOTE: Ensure that there is a semi-colon separating %AF_PATH%/lib from any existing content (e.g. EXISTING_PATHS;%AF_PATH%/lib;) otherwise other software may not function correctly.</li>\r\n</ol>\r\nFinally, verify that the path addition worked correctly. You can do this by:\r\n\r\n1. Open Visual Studio 2013. Open the HelloWorld solution which is located at \"AF_PATH/examples/helloworld/helloworld.sln.\"\r\n2. Build and run the helloworld example. Be sure to, select the platform/configuration of your choice using the platform drop-down (the options are CPU, CUDA, and OpenCL) and Solution Configuration drop down (options of Release and Debug) menus. Run the helloworld example.\r\n<h3>Linux</h3>\r\n<h4><a id=\"Debian\" class=\"anchor\"></a>Debian 8</h4>\r\nFirst install the prerequisite packages:\r\n<pre class=\"fragment\"># Prerequisite packages:\r\napt-get install libfreeimage-dev libatlas3gf-base libfftw3-dev cmake\r\n\r\n# Enable GPU support (OpenCL):\r\napt-get install ocl-icd-libopencl1\r\n</pre>\r\nIf you wish to use CUDA, please <a href=\"https://developer.nvidia.com/cuda-zone\">download the latest version of CUDA</a> and install it on your system.\r\n\r\nNext <a href=\"http://sandbox.arrayfire.com/download/\">download</a> ArrayFire. After you have the file, run the installer.\r\n<pre class=\"fragment\">./arrayfire_*_Linux_x86_64.sh --exclude-subdir --prefix=/usr/local\r\n</pre>\r\n<h4><a id=\"Fedora\" class=\"anchor\"></a>Fedora 21</h4>\r\nFirst install the prerequisite packages:\r\n<pre class=\"fragment\"># Install prerequiste packages\r\nyum install freeimage atlas fftw cmake\r\n</pre>\r\nIf you wish to use CUDA, please <a href=\"https://developer.nvidia.com/cuda-downloads\">download the latest version of CUDA</a> and install it on your system.\r\n\r\nNext <a href=\"http://sandbox.arrayfire.com/download/\">download</a> ArrayFire. After you have the file, run the installer.\r\n<pre class=\"fragment\">./arrayfire_*_Linux_x86_64.sh --exclude-subdir --prefix=/usr/local\r\n</pre>\r\n<h4><a id=\"Ubuntu\" class=\"anchor\"></a>Ubuntu 14.10 and later</h4>\r\nFirst install the prerequisite packages:\r\n<pre class=\"fragment\"># Prerequisite packages:\r\nsudo apt-get install libfreeimage-dev libatlas3gf-base libfftw3-dev cmake\r\n</pre>\r\nIf you are using ArrayFire on the Tegra-K1 also install these packages:\r\n<pre class=\"fragment\">sudo apt-get install libatlas3gf-base libatlas-dev libfftw3-dev liblapacke-dev\r\n</pre>\r\nIf your system has a CUDA GPU, we suggest downloading the latest drivers from NVIDIA in the form of a Debian package and installing using the package manager. At present, CUDA downloads can be found on the <a href=\"https://developer.nvidia.com/cuda-downloads\">NVIDIA CUDA download page</a> Follow NVIDIA\'s instructions for getting CUDA set up.\r\n\r\nIf you wish to use OpenCL, simply install the OpenCL ICD loader along with any drivers required for your hardware.\r\n<pre class=\"fragment\"># Enable GPU support (OpenCL):\r\napt-get install ocl-icd-libopencl1\r\n</pre>\r\nFinally, <a href=\"http://sandbox.arrayfire.com/download/\">download</a> ArrayFire. After you have the file, run the installer using:\r\n<pre class=\"fragment\">./arrayfire_*_Linux_x86_64.sh --exclude-subdir --prefix=/usr/local\r\n</pre>\r\n<h3><a id=\"OSX\" class=\"anchor\"></a>Mac OSX</h3>\r\nOn OSX there are several dependencies that are not integrated into the operating system. The ArrayFire installer automatically satisfies these dependencies using <a href=\"http://brew.sh/\">Homebrew</a>. If you don\'t have Homebrew installed on your system, the ArrayFire installer will ask you do to so.\r\n\r\nSimply <a href=\"http://sandbox.arrayfire.com/download\">download</a> the ArrayFire installer and double-click it to carry out the installation.\r\n\r\nArrayFire can also be installed through Homebrew directly using <code>brew install arrayfire</code>; however, it will not include MKL acceleration of linear algebra functions.\r\n<h3><a id=\"Testing\" class=\"anchor\"></a>Testing the installation</h3>\r\nAfter ArrayFire is installed, you can build the example programs as follows:\r\n<pre class=\"fragment\">cp -r /usr/local/share/doc/arrayfire/examples .\r\ncd examples\r\nmkdir build\r\ncd build\r\ncmake ..\r\nmake\r\n</pre>\r\n<h3><a id=\"GettingHelp\" class=\"anchor\"></a>Getting help</h3>\r\n<ul>\r\n	<li>Google Groups: <a href=\"https://groups.google.com/forum/#!forum/arrayfire-users\">https://groups.google.com/forum/#!forum/arrayfire-users</a></li>\r\n	<li>ArrayFire Services: <a href=\"http://sandbox.arrayfire.com/consulting/\">Consulting</a> | <a href=\"http://sandbox.arrayfire.com/support/\">Support</a> | <a href=\"http://sandbox.arrayfire.com/training/\">Training</a></li>\r\n	<li>ArrayFire Blogs: <a href=\"http://sandbox.arrayfire.com/blog/\">http://sandbox.arrayfire.com/blog/</a></li>\r\n	<li>Email: <a href=\"#\">technical@arrayfire.com</a></li>\r\n</ul>\r\n&nbsp;','Learning ArrayFire from scratch: Installation','','inherit','open','closed','','8542-revision-v1','','','2015-10-21 15:10:00','2015-10-21 15:10:00','',8542,'http://sandbox.arrayfire.com/8542-revision-v1/',0,'revision','',0),(8556,18528,'2015-10-21 15:13:45','2015-10-21 15:13:45','Recently one of our interns completed his project ahead of schedule and asked if he could spend some time writing a particle filtering demo in ArrayFire for use at our upcoming trade shows. While learning the ins and outs of ArrayFire he posed several excellent questions which prompted us to start a series of blog posts entitled \"<a href=\"http://sandbox.arrayfire.com/tag/learning-arrayfire-from-scratch/\">Learning ArrayFire from scratch</a>\" that are geared to first-time users of our library.\r\n\r\nIn today\'s post I will cover the installation process on Windows, Mac, and Linux. Our next post will discuss the basics of setting up your first ArrayFire project.\r\n\r\n<!--more-->\r\n\r\nInstalling ArrayFire couldn\'t be easier. We ship installers for Windows, OSX, and Linux. Although you could <a href=\"https://github.com/arrayfire/arrayfire\">build ArrayFire from source</a>, we suggest using our pre-compiled binaries as they include the Intel Math Kernel Library to accelerate linear algebra functions.\r\n\r\nPlease note that although our download page requires a valid login, registration is free and downloading ArrayFire is also free. We request your contact information so that we may notify you of software updates and occasionally collect user feedback about our library.\r\n\r\nIn general, the installation process for ArrayFire looks like this:\r\n<ol type=\"1\">\r\n	<li>Install prerequisites</li>\r\n	<li><a href=\"http://sandbox.arrayfire.com/download/\">Download</a> the ArrayFire installer for your operating system</li>\r\n	<li>Install ArrayFire</li>\r\n	<li>Test the installation</li>\r\n	<li><a href=\"#GettingHelp\">Where to go for help?</a></li>\r\n</ol>\r\nBelow you will find instructions for\r\n<ul>\r\n	<li><a href=\"#Windows\">Windows</a></li>\r\n	<li>Linux including\r\n<ul>\r\n	<li><a href=\"#Debian\">Debian 8</a></li>\r\n	<li><a href=\"#Ubuntu\">Ubuntu 14.10 and later</a></li>\r\n	<li><a href=\"#Fedora\">Fedora 21</a></li>\r\n</ul>\r\n</li>\r\n	<li><a href=\"#OSX\">Mac OSX (.sh and brew)</a></li>\r\n</ul>\r\n<h3><a id=\"Windows\" class=\"anchor\"></a>Windows</h3>\r\nIf you wish to use CUDA or OpenCL please ensure that you have also installed\r\nsupport for these technologies from your video card vendor\'s website.\r\n\r\nNext <a href=\"http://sandbox.arrayfire.com/download/\">download</a> and run the ArrayFire installer.\r\nAfter it has completed, you need to add ArrayFire to the path for all users.\r\n<ol>\r\n	<li>Open Advanced System Settings:\r\n* Windows 8: Move the Mouse pointer to the bottom right corner of the screen, Right click, choose System. Then click \"Advanced System Settings\"\r\n* Windows 7: Open the Start Menu and Right Click on \"Computer\". Then choose Properties and click \"Advanced System Settings\"</li>\r\n	<li>In Advanced System Settings window, click on Advanced tab</li>\r\n	<li>Click on Environment Variables, then under System Variables, find PATH, and click on it.</li>\r\n	<li>In edit mode, append %AF_PATH%/lib. NOTE: Ensure that there is a semi-colon separating %AF_PATH%/lib from any existing content (e.g. EXISTING_PATHS;%AF_PATH%/lib;) otherwise other software may not function correctly.</li>\r\n</ol>\r\nFinally, verify that the path addition worked correctly. You can do this by:\r\n<ol>\r\n	<li>Open Visual Studio 2013. Open the HelloWorld solution which is located at \"AF_PATH/examples/helloworld/helloworld.sln.\"</li>\r\n	<li>Build and run the helloworld example. Be sure to, select the platform/configuration of your choice using the platform drop-down (the options are CPU, CUDA, and OpenCL) and Solution Configuration drop down (options of Release and Debug) menus. Run the helloworld example.</li>\r\n</ol>\r\n<h3>Linux</h3>\r\n<h4><a id=\"Debian\" class=\"anchor\"></a>Debian 8</h4>\r\nFirst install the prerequisite packages:\r\n<pre class=\"fragment\"># Prerequisite packages:\r\napt-get install libfreeimage-dev libatlas3gf-base libfftw3-dev cmake\r\n\r\n# Enable GPU support (OpenCL):\r\napt-get install ocl-icd-libopencl1\r\n</pre>\r\nIf you wish to use CUDA, please <a href=\"https://developer.nvidia.com/cuda-zone\">download the latest version of CUDA</a> and install it on your system.\r\n\r\nNext <a href=\"http://sandbox.arrayfire.com/download/\">download</a> ArrayFire. After you have the file, run the installer.\r\n<pre class=\"fragment\">./arrayfire_*_Linux_x86_64.sh --exclude-subdir --prefix=/usr/local\r\n</pre>\r\n<h4><a id=\"Fedora\" class=\"anchor\"></a>Fedora 21</h4>\r\nFirst install the prerequisite packages:\r\n<pre class=\"fragment\"># Install prerequiste packages\r\nyum install freeimage atlas fftw cmake\r\n</pre>\r\nIf you wish to use CUDA, please <a href=\"https://developer.nvidia.com/cuda-downloads\">download the latest version of CUDA</a> and install it on your system.\r\n\r\nNext <a href=\"http://sandbox.arrayfire.com/download/\">download</a> ArrayFire. After you have the file, run the installer.\r\n<pre class=\"fragment\">./arrayfire_*_Linux_x86_64.sh --exclude-subdir --prefix=/usr/local\r\n</pre>\r\n<h4><a id=\"Ubuntu\" class=\"anchor\"></a>Ubuntu 14.10 and later</h4>\r\nFirst install the prerequisite packages:\r\n<pre class=\"fragment\"># Prerequisite packages:\r\nsudo apt-get install libfreeimage-dev libatlas3gf-base libfftw3-dev cmake\r\n</pre>\r\nIf you are using ArrayFire on the Tegra-K1 also install these packages:\r\n<pre class=\"fragment\">sudo apt-get install libatlas3gf-base libatlas-dev libfftw3-dev liblapacke-dev\r\n</pre>\r\nIf your system has a CUDA GPU, we suggest downloading the latest drivers from NVIDIA in the form of a Debian package and installing using the package manager. At present, CUDA downloads can be found on the <a href=\"https://developer.nvidia.com/cuda-downloads\">NVIDIA CUDA download page</a> Follow NVIDIA\'s instructions for getting CUDA set up.\r\n\r\nIf you wish to use OpenCL, simply install the OpenCL ICD loader along with any drivers required for your hardware.\r\n<pre class=\"fragment\"># Enable GPU support (OpenCL):\r\napt-get install ocl-icd-libopencl1\r\n</pre>\r\nFinally, <a href=\"http://sandbox.arrayfire.com/download/\">download</a> ArrayFire. After you have the file, run the installer using:\r\n<pre class=\"fragment\">./arrayfire_*_Linux_x86_64.sh --exclude-subdir --prefix=/usr/local\r\n</pre>\r\n<h3><a id=\"OSX\" class=\"anchor\"></a>Mac OSX</h3>\r\nOn OSX there are several dependencies that are not integrated into the operating system. The ArrayFire installer automatically satisfies these dependencies using <a href=\"http://brew.sh/\">Homebrew</a>. If you don\'t have Homebrew installed on your system, the ArrayFire installer will ask you do to so.\r\n\r\nSimply <a href=\"http://sandbox.arrayfire.com/download\">download</a> the ArrayFire installer and double-click it to carry out the installation.\r\n\r\nArrayFire can also be installed through Homebrew directly using <code>brew install arrayfire</code>; however, it will not include MKL acceleration of linear algebra functions.\r\n<h3><a id=\"Testing\" class=\"anchor\"></a>Testing the installation</h3>\r\nAfter ArrayFire is installed, you can build the example programs as follows:\r\n<pre class=\"fragment\">cp -r /usr/local/share/doc/arrayfire/examples .\r\ncd examples\r\nmkdir build\r\ncd build\r\ncmake ..\r\nmake\r\n</pre>\r\n<h3><a id=\"GettingHelp\" class=\"anchor\"></a>Getting help</h3>\r\n<ul>\r\n	<li>Google Groups: <a href=\"https://groups.google.com/forum/#!forum/arrayfire-users\">https://groups.google.com/forum/#!forum/arrayfire-users</a></li>\r\n	<li>ArrayFire Services: <a href=\"http://sandbox.arrayfire.com/consulting/\">Consulting</a> | <a href=\"http://sandbox.arrayfire.com/support/\">Support</a> | <a href=\"http://sandbox.arrayfire.com/training/\">Training</a></li>\r\n	<li>ArrayFire Blogs: <a href=\"http://sandbox.arrayfire.com/blog/\">http://sandbox.arrayfire.com/blog/</a></li>\r\n	<li>Email: <a href=\"#\">technical@arrayfire.com</a></li>\r\n</ul>\r\n&nbsp;','Learning ArrayFire from scratch: Installation','','inherit','open','closed','','8542-revision-v1','','','2015-10-21 15:13:45','2015-10-21 15:13:45','',8542,'http://sandbox.arrayfire.com/8542-revision-v1/',0,'revision','',0),(8557,18528,'2015-10-21 15:21:45','2015-10-21 15:21:45','Recently one of our interns completed his project ahead of schedule and asked if he could spend some time writing a particle filtering demo in ArrayFire for use at our upcoming trade shows. While learning the ins and outs of ArrayFire he posed several excellent questions which prompted us to start a series of blog posts entitled \"<a href=\"http://sandbox.arrayfire.com/tag/learning-arrayfire-from-scratch/\">Learning ArrayFire from scratch</a>\" that are geared to first-time users of our library.\r\n\r\nIn today\'s post I will cover the installation process on Windows, Mac, and Linux. Our next post will discuss the basics of setting up your first ArrayFire project.\r\n\r\n<!--more-->\r\n\r\nInstalling ArrayFire couldn\'t be easier. We ship installers for Windows, OSX, and Linux. Although you could <a href=\"https://github.com/arrayfire/arrayfire\">build ArrayFire from source</a>, we suggest using our pre-compiled binaries as they include the Intel Math Kernel Library to accelerate linear algebra functions.\r\n\r\nPlease note that although our download page requires a valid login, registration is free and downloading ArrayFire is also free. We request your contact information so that we may notify you of software updates and occasionally collect user feedback about our library.\r\n\r\nIn general, the installation process for ArrayFire looks like this:\r\n<ol type=\"1\">\r\n	<li>Install prerequisites</li>\r\n	<li><a href=\"http://sandbox.arrayfire.com/download/\">Download</a> the ArrayFire installer for your operating system</li>\r\n	<li>Install ArrayFire</li>\r\n	<li>Test the installation</li>\r\n	<li><a href=\"#GettingHelp\">Where to go for help?</a></li>\r\n</ol>\r\nBelow you will find instructions for\r\n<ul>\r\n	<li><a href=\"#Windows\">Windows</a></li>\r\n	<li>Linux including\r\n<ul>\r\n	<li><a href=\"#Debian\">Debian 8</a></li>\r\n	<li><a href=\"#Ubuntu\">Ubuntu 14.10 and later</a></li>\r\n	<li><a href=\"#Fedora\">Fedora 21</a></li>\r\n</ul>\r\n</li>\r\n	<li><a href=\"#OSX\">Mac OSX (.sh and brew)</a></li>\r\n</ul>\r\n<h3><a id=\"Windows\" class=\"anchor\"></a>Windows</h3>\r\nIf you wish to use CUDA or OpenCL please ensure that you have also installed\r\nsupport for these technologies from your video card vendor\'s website.\r\n\r\nNext <a href=\"http://sandbox.arrayfire.com/download/\">download</a> and run the ArrayFire installer.\r\nAfter it has completed, you need to add ArrayFire to the path for all users.\r\n<ol>\r\n	<li>Open Advanced System Settings:\r\n* Windows 8: Move the Mouse pointer to the bottom right corner of the screen, Right click, choose System. Then click \"Advanced System Settings\"\r\n* Windows 7: Open the Start Menu and Right Click on \"Computer\". Then choose Properties and click \"Advanced System Settings\"</li>\r\n	<li>In Advanced System Settings window, click on Advanced tab</li>\r\n	<li>Click on Environment Variables, then under System Variables, find PATH, and click on it.</li>\r\n	<li>In edit mode, append <span class=\"lang:default decode:true  crayon-inline \">%AF_PATH%/lib</span> . NOTE: Ensure that there is a semi-colon separating <span class=\"lang:default decode:true  crayon-inline \">%AF_PATH%/lib</span>  from any existing content (e.g. <span class=\"lang:default decode:true  crayon-inline \">EXISTING_PATHS;%AF_PATH%/lib;</span> ) otherwise other software may not function correctly.</li>\r\n</ol>\r\nFinally, verify that the path addition worked correctly. You can do this by running any of the HelloWorld examples located in <span class=\"lang:default decode:true  crayon-inline \">AF_PATH/examples/helloworld/</span>\r\n<h3>Linux</h3>\r\n<h4><a id=\"Debian\" class=\"anchor\"></a>Debian 8</h4>\r\nFirst install the prerequisite packages:\r\n<pre class=\"fragment\"># Prerequisite packages:\r\napt-get install libfreeimage-dev libatlas3gf-base libfftw3-dev libglew-dev libglewmx-dev libglfw3-dev cmake\r\n\r\n# Enable GPU support (OpenCL):\r\napt-get install ocl-icd-libopencl1\r\n</pre>\r\nIf you wish to use CUDA, please <a href=\"https://developer.nvidia.com/cuda-zone\">download the latest version of CUDA</a> and install it on your system.\r\n\r\nNext <a href=\"http://sandbox.arrayfire.com/download/\">download</a> ArrayFire. After you have the file, run the installer.\r\n<pre class=\"fragment\">./arrayfire_*_Linux_x86_64.sh --exclude-subdir --prefix=/usr/local\r\n</pre>\r\n<h4><a id=\"Fedora\" class=\"anchor\"></a>Fedora 21</h4>\r\nFirst install the prerequisite packages:\r\n<pre class=\"fragment\"># Install prerequiste packages\r\nyum install freeimage atlas fftw cmake\r\n</pre>\r\nIf you wish to use CUDA, please <a href=\"https://developer.nvidia.com/cuda-downloads\">download the latest version of CUDA</a> and install it on your system.\r\n\r\nNext <a href=\"http://sandbox.arrayfire.com/download/\">download</a> ArrayFire. After you have the file, run the installer.\r\n<pre class=\"fragment\">./arrayfire_*_Linux_x86_64.sh --exclude-subdir --prefix=/usr/local\r\n</pre>\r\n<h4><a id=\"Ubuntu\" class=\"anchor\"></a>Ubuntu 14.10 and later</h4>\r\nFirst install the prerequisite packages:\r\n<pre class=\"fragment\"># Prerequisite packages:\r\nsudo apt-get install libfreeimage-dev libatlas3gf-base libfftw3-dev libglew-dev libglewmx-dev libglfw3-dev cmake\r\n</pre>\r\nIf you are using ArrayFire on the Tegra-K1 also install these packages:\r\n<pre class=\"fragment\">sudo apt-get install libatlas3gf-base libatlas-dev libfftw3-dev liblapacke-dev\r\n</pre>\r\nIf your system has a CUDA GPU, we suggest downloading the latest drivers from NVIDIA in the form of a Debian package and installing using the package manager. At present, CUDA downloads can be found on the <a href=\"https://developer.nvidia.com/cuda-downloads\">NVIDIA CUDA download page</a> Follow NVIDIA\'s instructions for getting CUDA set up.\r\n\r\nIf you wish to use OpenCL, simply install the OpenCL ICD loader along with any drivers required for your hardware.\r\n<pre class=\"fragment\"># Enable GPU support (OpenCL):\r\napt-get install ocl-icd-libopencl1\r\n</pre>\r\nFinally, <a href=\"http://sandbox.arrayfire.com/download/\">download</a> ArrayFire. After you have the file, run the installer using:\r\n<pre class=\"fragment\">./arrayfire_*_Linux_x86_64.sh --exclude-subdir --prefix=/usr/local\r\n</pre>\r\n<h3><a id=\"OSX\" class=\"anchor\"></a>Mac OSX</h3>\r\nOn OSX there are several dependencies that are not integrated into the operating system. The ArrayFire installer automatically satisfies these dependencies using <a href=\"http://brew.sh/\">Homebrew</a>. If you don\'t have Homebrew installed on your system, the ArrayFire installer will ask you do to so.\r\n\r\nSimply <a href=\"http://sandbox.arrayfire.com/download\">download</a> the ArrayFire installer and double-click it to carry out the installation.\r\n\r\nArrayFire can also be installed through Homebrew directly using <code>brew install arrayfire</code>; however, it will not include MKL acceleration of linear algebra functions.\r\n<h3><a id=\"Testing\" class=\"anchor\"></a>Testing the installation</h3>\r\nAfter ArrayFire is installed, you can build the example programs as follows:\r\n<pre class=\"fragment\">cp -r /usr/local/share/doc/arrayfire/examples .\r\ncd examples\r\nmkdir build\r\ncd build\r\ncmake ..\r\nmake\r\n</pre>\r\n<h3><a id=\"GettingHelp\" class=\"anchor\"></a>Getting help</h3>\r\n<ul>\r\n	<li>Google Groups: <a href=\"https://groups.google.com/forum/#!forum/arrayfire-users\">https://groups.google.com/forum/#!forum/arrayfire-users</a></li>\r\n	<li>ArrayFire Services: <a href=\"http://sandbox.arrayfire.com/consulting/\">Consulting</a> | <a href=\"http://sandbox.arrayfire.com/support/\">Support</a> | <a href=\"http://sandbox.arrayfire.com/training/\">Training</a></li>\r\n	<li>ArrayFire Blogs: <a href=\"http://sandbox.arrayfire.com/blog/\">http://sandbox.arrayfire.com/blog/</a></li>\r\n	<li>Email: <a href=\"#\">technical@arrayfire.com</a></li>\r\n</ul>\r\n&nbsp;','Learning ArrayFire from scratch: Installation','','inherit','open','closed','','8542-revision-v1','','','2015-10-21 15:21:45','2015-10-21 15:21:45','',8542,'http://sandbox.arrayfire.com/8542-revision-v1/',0,'revision','',0),(8558,18528,'2015-10-21 15:27:51','2015-10-21 15:27:51','Recently one of our interns completed his project ahead of schedule and asked if he could spend some time writing a particle filtering demo in ArrayFire for use at our upcoming trade shows. While learning the ins and outs of ArrayFire he posed several excellent questions which prompted us to start a series of blog posts entitled \"<a href=\"http://sandbox.arrayfire.com/tag/learning-arrayfire-from-scratch/\">Learning ArrayFire from scratch</a>\" that are geared to first-time users of our library.\r\n\r\nIn today\'s post I will cover the installation process on Windows, Mac, and Linux. Our next post will discuss the basics of setting up your first ArrayFire project.\r\n\r\n<!--more-->\r\n\r\nInstalling ArrayFire couldn\'t be easier. We ship installers for Windows, OSX, and Linux. Although you could <a href=\"https://github.com/arrayfire/arrayfire\">build ArrayFire from source</a>, we suggest using our pre-compiled binaries as they include the Intel Math Kernel Library to accelerate linear algebra functions.\r\n\r\nPlease note that although our download page requires a valid login, registration is free and downloading ArrayFire is also free. We request your contact information so that we may notify you of software updates and occasionally collect user feedback about our library.\r\n\r\nIn general, the installation process for ArrayFire looks like this:\r\n<ol type=\"1\">\r\n	<li>Install prerequisites</li>\r\n	<li><a href=\"http://sandbox.arrayfire.com/download/\">Download</a> the ArrayFire installer for your operating system</li>\r\n	<li>Install ArrayFire</li>\r\n	<li>Test the installation</li>\r\n	<li><a href=\"#GettingHelp\">Where to go for help?</a></li>\r\n</ol>\r\nBelow you will find instructions for\r\n<ul>\r\n	<li><a href=\"#Windows\">Windows</a></li>\r\n	<li>Linux including\r\n<ul>\r\n	<li><a href=\"#Debian\">Debian 8</a></li>\r\n	<li><a href=\"#Ubuntu\">Ubuntu 14.10 and later</a></li>\r\n	<li><a href=\"#Fedora\">Fedora 21</a></li>\r\n</ul>\r\n</li>\r\n	<li><a href=\"#OSX\">Mac OSX (.sh and brew)</a></li>\r\n</ul>\r\n<h3><a id=\"Windows\" class=\"anchor\"></a>Windows</h3>\r\nIf you wish to use CUDA or OpenCL please ensure that you have also installed\r\nsupport for these technologies from your video card vendor\'s website.\r\n\r\nNext <a href=\"http://sandbox.arrayfire.com/download/\">download</a> and run the ArrayFire installer.\r\nAfter it has completed, you need to add ArrayFire to the path for all users.\r\n<ol>\r\n	<li>Open Advanced System Settings:\r\n* Windows 8: Move the Mouse pointer to the bottom right corner of the screen, Right click, choose System. Then click \"Advanced System Settings\"\r\n* Windows 7: Open the Start Menu and Right Click on \"Computer\". Then choose Properties and click \"Advanced System Settings\"</li>\r\n	<li>In Advanced System Settings window, click on Advanced tab</li>\r\n	<li>Click on Environment Variables, then under System Variables, find PATH, and click on it.</li>\r\n	<li>In edit mode, append <span class=\"lang:default decode:true  crayon-inline \">%AF_PATH%/lib</span> . NOTE: Ensure that there is a semi-colon separating <span class=\"lang:default decode:true  crayon-inline \">%AF_PATH%/lib</span>  from any existing content (e.g. <span class=\"lang:default decode:true  crayon-inline \">EXISTING_PATHS;%AF_PATH%/lib;</span> ) otherwise other software may not function correctly.</li>\r\n</ol>\r\nFinally, verify that the path addition worked correctly. You can do this by running any of the HelloWorld examples located in <span class=\"lang:default decode:true  crayon-inline \">AF_PATH/examples/helloworld/</span>\r\n<h3>Linux</h3>\r\n<h4><a id=\"Debian\" class=\"anchor\"></a>Debian 8</h4>\r\nFirst install the prerequisite packages:\r\n<pre class=\"fragment\"># Prerequisite packages:\r\napt-get install libfreeimage-dev libatlas3gf-base libfftw3-dev libglew-dev libglewmx-dev libglfw3-dev cmake\r\n\r\n# Enable GPU support (OpenCL):\r\napt-get install ocl-icd-libopencl1\r\n</pre>\r\nIf you wish to use CUDA, please <a href=\"https://developer.nvidia.com/cuda-zone\">download the latest version of CUDA</a> and install it on your system.\r\n\r\nNext <a href=\"http://sandbox.arrayfire.com/download/\">download</a> ArrayFire. After you have the file, run the installer.\r\n<pre class=\"fragment\">./arrayfire_*_Linux_x86_64.sh --exclude-subdir --prefix=/usr/local\r\n</pre>\r\n<h4><a id=\"Fedora\" class=\"anchor\"></a>Fedora 21</h4>\r\nFirst install the prerequisite packages:\r\n<pre class=\"fragment \"># Install prerequiste packages\r\nyum install freeimage atlas fftw libGLEW libGLEWmx glfw cmake\r\n</pre>\r\nIf you wish to use CUDA, please <a href=\"https://developer.nvidia.com/cuda-downloads\">download the latest version of CUDA</a> and install it on your system.\r\n\r\nNext <a href=\"http://sandbox.arrayfire.com/download/\">download</a> ArrayFire. After you have the file, run the installer.\r\n<pre class=\"fragment\">./arrayfire_*_Linux_x86_64.sh --exclude-subdir --prefix=/usr/local\r\n</pre>\r\n<h4><a id=\"Ubuntu\" class=\"anchor\"></a>Ubuntu 14.10 and later</h4>\r\nFirst install the prerequisite packages:\r\n<pre class=\"fragment\"># Prerequisite packages:\r\nsudo apt-get install libfreeimage-dev libatlas3gf-base libfftw3-dev libglew-dev libglewmx-dev libglfw3-dev cmake\r\n</pre>\r\nIf you are using ArrayFire on the Tegra-K1 also install these packages:\r\n<pre class=\"fragment\">sudo apt-get install libatlas3gf-base libatlas-dev libfftw3-dev liblapacke-dev\r\n</pre>\r\nIf your system has a CUDA GPU, we suggest downloading the latest drivers from NVIDIA in the form of a Debian package and installing using the package manager. At present, CUDA downloads can be found on the <a href=\"https://developer.nvidia.com/cuda-downloads\">NVIDIA CUDA download page</a> Follow NVIDIA\'s instructions for getting CUDA set up.\r\n\r\nIf you wish to use OpenCL, simply install the OpenCL ICD loader along with any drivers required for your hardware.\r\n<pre class=\"fragment\"># Enable GPU support (OpenCL):\r\napt-get install ocl-icd-libopencl1\r\n</pre>\r\nFinally, <a href=\"http://sandbox.arrayfire.com/download/\">download</a> ArrayFire. After you have the file, run the installer using:\r\n<pre class=\"fragment\">./arrayfire_*_Linux_x86_64.sh --exclude-subdir --prefix=/usr/local\r\n</pre>\r\n<h3><a id=\"OSX\" class=\"anchor\"></a>Mac OSX</h3>\r\nOn OSX there are several dependencies that are not integrated into the operating system. The ArrayFire installer automatically satisfies these dependencies using <a href=\"http://brew.sh/\">Homebrew</a>. If you don\'t have Homebrew installed on your system, the ArrayFire installer will ask you do to so.\r\n\r\nSimply <a href=\"http://sandbox.arrayfire.com/download\">download</a> the ArrayFire installer and double-click it to carry out the installation.\r\n\r\nArrayFire can also be installed through Homebrew directly using <code>brew install arrayfire</code>; however, it will not include MKL acceleration of linear algebra functions.\r\n<h3><a id=\"Testing\" class=\"anchor\"></a>Testing the installation</h3>\r\nAfter ArrayFire is installed, you can build the example programs as follows:\r\n<pre class=\"fragment\">cp -r /usr/local/share/doc/arrayfire/examples .\r\ncd examples\r\nmkdir build\r\ncd build\r\ncmake ..\r\nmake\r\n</pre>\r\n<h3><a id=\"GettingHelp\" class=\"anchor\"></a>Getting help</h3>\r\n<ul>\r\n	<li>Google Groups: <a href=\"https://groups.google.com/forum/#!forum/arrayfire-users\">https://groups.google.com/forum/#!forum/arrayfire-users</a></li>\r\n	<li>ArrayFire Services: <a href=\"http://sandbox.arrayfire.com/consulting/\">Consulting</a> | <a href=\"http://sandbox.arrayfire.com/support/\">Support</a> | <a href=\"http://sandbox.arrayfire.com/training/\">Training</a></li>\r\n	<li>ArrayFire Blogs: <a href=\"http://sandbox.arrayfire.com/blog/\">http://sandbox.arrayfire.com/blog/</a></li>\r\n	<li>Email: <a href=\"#\">technical@arrayfire.com</a></li>\r\n</ul>\r\n&nbsp;','Learning ArrayFire from scratch: Installation','','inherit','open','closed','','8542-revision-v1','','','2015-10-21 15:27:51','2015-10-21 15:27:51','',8542,'http://sandbox.arrayfire.com/8542-revision-v1/',0,'revision','',0),(8559,18528,'2015-10-21 17:14:56','2015-10-21 17:14:56','Recently one of our interns completed his project ahead of schedule and asked if he could spend some time writing a particle filtering demo in ArrayFire for use at our upcoming trade shows. While learning the ins and outs of ArrayFire he posed several excellent questions which prompted us to start a series of blog posts entitled \"<a href=\"http://sandbox.arrayfire.com/tag/learning-arrayfire-from-scratch/\">Learning ArrayFire from scratch</a>\" that are geared to first-time users of our library.\r\n\r\nIn today\'s post I will cover the installation process on Windows, Mac, and Linux. Our next post will discuss the basics of setting up your first ArrayFire project.\r\n\r\n<!--more-->\r\n\r\nInstalling ArrayFire couldn\'t be easier. We ship installers for Windows, OSX, and Linux. Although you could <a href=\"https://github.com/arrayfire/arrayfire\">build ArrayFire from source</a>, we suggest using our pre-compiled binaries as they include the Intel Math Kernel Library to accelerate linear algebra functions.\r\n\r\nPlease note that although our download page requires a valid login, registration is free and downloading ArrayFire is also free. We request your contact information so that we may notify you of software updates and occasionally collect user feedback about our library.\r\n\r\nIn general, the installation process for ArrayFire looks like this:\r\n<ol type=\"1\">\r\n	<li>Install prerequisites</li>\r\n	<li><a href=\"http://sandbox.arrayfire.com/download/\">Download</a> the ArrayFire installer for your operating system</li>\r\n	<li>Install ArrayFire</li>\r\n	<li>Test the installation</li>\r\n	<li><a href=\"#GettingHelp\">Where to go for help?</a></li>\r\n</ol>\r\nBelow you will find instructions for\r\n<ul>\r\n	<li><a href=\"#Windows\">Windows</a></li>\r\n	<li>Linux including\r\n<ul>\r\n	<li><a href=\"#Debian\">Debian 8</a></li>\r\n	<li><a href=\"#Ubuntu\">Ubuntu 14.10 and later</a></li>\r\n	<li><a href=\"#Fedora\">Fedora 21</a></li>\r\n</ul>\r\n</li>\r\n	<li><a href=\"#OSX\">Mac OSX (.sh and brew)</a></li>\r\n</ul>\r\n<h3><a id=\"Windows\" class=\"anchor\"></a>Windows</h3>\r\nIf you wish to use CUDA or OpenCL please ensure that you have also installed\r\nsupport for these technologies from your video card vendor\'s website.\r\n\r\nNext <a href=\"http://sandbox.arrayfire.com/download/\">download</a> and run the ArrayFire installer.\r\nAfter it has completed, you need to add ArrayFire to the path for all users.\r\n<ol>\r\n	<li>Open Advanced System Settings:\r\n* Windows 8: Move the Mouse pointer to the bottom right corner of the screen, Right click, choose System. Then click \"Advanced System Settings\"\r\n* Windows 7: Open the Start Menu and Right Click on \"Computer\". Then choose Properties and click \"Advanced System Settings\"</li>\r\n	<li>In Advanced System Settings window, click on Advanced tab</li>\r\n	<li>Click on Environment Variables, then under System Variables, find PATH, and click on it.</li>\r\n	<li>In edit mode, append <span class=\"lang:default decode:true  crayon-inline \">%AF_PATH%/lib</span> . NOTE: Ensure that there is a semi-colon separating <span class=\"lang:default decode:true  crayon-inline \">%AF_PATH%/lib</span>  from any existing content (e.g. <span class=\"lang:default decode:true  crayon-inline \">EXISTING_PATHS;%AF_PATH%/lib;</span> ) otherwise other software may not function correctly.</li>\r\n</ol>\r\nFinally, verify that the path addition worked correctly. You can do this by running any of the HelloWorld examples located in <span class=\"lang:default decode:true  crayon-inline \">AF_PATH/examples/helloworld/</span>\r\n<h3>Linux</h3>\r\n<h4><a id=\"Debian\" class=\"anchor\"></a>Debian 8</h4>\r\nFirst install the prerequisite packages:\r\n<pre class=\"fragment\"># Prerequisite packages:\r\napt-get install libfreeimage-dev libatlas3gf-base libfftw3-dev libglew-dev libglewmx-dev libglfw3-dev cmake\r\n\r\n# Enable GPU support (OpenCL):\r\napt-get install ocl-icd-libopencl1\r\n</pre>\r\nIf you wish to use CUDA, please <a href=\"https://developer.nvidia.com/cuda-zone\">download the latest version of CUDA</a> and install it on your system.\r\n\r\nNext <a href=\"http://sandbox.arrayfire.com/download/\">download</a> ArrayFire. After you have the file, run the installer.\r\n<pre class=\"fragment\">./arrayfire_*_Linux_x86_64.sh --exclude-subdir --prefix=/usr/local\r\n</pre>\r\n<h4><a id=\"Fedora\" class=\"anchor\"></a>Fedora 21</h4>\r\nFirst install the prerequisite packages:\r\n<pre class=\"fragment \"># Install prerequiste packages\r\nyum install freeimage atlas fftw libGLEW libGLEWmx glfw cmake\r\n</pre>\r\nIf you wish to use CUDA, please <a href=\"https://developer.nvidia.com/cuda-downloads\">download the latest version of CUDA</a> and install it on your system.\r\n\r\nNext <a href=\"http://sandbox.arrayfire.com/download/\">download</a> ArrayFire. After you have the file, run the installer.\r\n<pre class=\"fragment\">./arrayfire_*_Linux_x86_64.sh --exclude-subdir --prefix=/usr/local\r\n</pre>\r\n<h4><a id=\"Ubuntu\" class=\"anchor\"></a>Ubuntu 14.10 and later</h4>\r\nFirst install the prerequisite packages:\r\n<pre class=\"fragment\"># Prerequisite packages:\r\nsudo apt-get install libfreeimage-dev libatlas3gf-base libfftw3-dev libglew-dev libglewmx-dev libglfw3-dev cmake\r\n</pre>\r\nIf you are using ArrayFire on the Tegra-K1 also install these packages:\r\n<pre class=\"fragment\">sudo apt-get install libatlas3gf-base libatlas-dev libfftw3-dev liblapacke-dev\r\n</pre>\r\nIf your system has a CUDA GPU, we suggest downloading the latest drivers from NVIDIA in the form of a Debian package and installing using the package manager. At present, CUDA downloads can be found on the <a href=\"https://developer.nvidia.com/cuda-downloads\">NVIDIA CUDA download page</a> Follow NVIDIA\'s instructions for getting CUDA set up.\r\n\r\nIf you wish to use OpenCL, simply install the OpenCL ICD loader along with any drivers required for your hardware.\r\n<pre class=\"fragment\"># Enable GPU support (OpenCL):\r\napt-get install ocl-icd-libopencl1\r\n</pre>\r\nFinally, <a href=\"http://sandbox.arrayfire.com/download/\">download</a> ArrayFire. After you have the file, run the installer using:\r\n<pre class=\"fragment\">./arrayfire_*_Linux_x86_64.sh --exclude-subdir --prefix=/usr/local\r\n</pre>\r\n<h3><a id=\"OSX\" class=\"anchor\"></a>Mac OSX</h3>\r\nOn OSX there are several dependencies that are not integrated into the operating system. The ArrayFire installer automatically satisfies these dependencies using <a href=\"http://brew.sh/\">Homebrew</a>. If you don\'t have Homebrew installed on your system, the ArrayFire installer will ask you do to so.\r\n\r\nSimply <a href=\"http://sandbox.arrayfire.com/download\">download</a> the ArrayFire installer and double-click it to carry out the installation.\r\n\r\nArrayFire can also be installed through Homebrew directly using <span class=\"lang:default decode:true  crayon-inline \">brew install arrayfire</span> ; however, it will not include MKL acceleration of linear algebra functions.\r\n<h3><a id=\"Testing\" class=\"anchor\"></a>Testing the installation</h3>\r\nAfter ArrayFire is installed, you can build the example programs as follows:\r\n<pre class=\"fragment\">cp -r /usr/local/share/doc/arrayfire/examples .\r\ncd examples\r\nmkdir build\r\ncd build\r\ncmake ..\r\nmake\r\n</pre>\r\n<h3><a id=\"GettingHelp\" class=\"anchor\"></a>Getting help</h3>\r\n<ul>\r\n	<li>Google Groups: <a href=\"https://groups.google.com/forum/#!forum/arrayfire-users\">https://groups.google.com/forum/#!forum/arrayfire-users</a></li>\r\n	<li>ArrayFire Services: <a href=\"http://sandbox.arrayfire.com/consulting/\">Consulting</a> | <a href=\"http://sandbox.arrayfire.com/support/\">Support</a> | <a href=\"http://sandbox.arrayfire.com/training/\">Training</a></li>\r\n	<li>ArrayFire Blogs: <a href=\"http://sandbox.arrayfire.com/blog/\">http://sandbox.arrayfire.com/blog/</a></li>\r\n	<li>Email: <a href=\"#\">technical@arrayfire.com</a></li>\r\n</ul>\r\n&nbsp;','Learning ArrayFire from scratch: Installation','','inherit','open','closed','','8542-revision-v1','','','2015-10-21 17:14:56','2015-10-21 17:14:56','',8542,'http://sandbox.arrayfire.com/8542-revision-v1/',0,'revision','',0),(8561,18528,'2015-10-22 13:59:45','2015-10-22 13:59:45','','temp','','inherit','open','closed','','temp','','','2015-10-22 13:59:45','2015-10-22 13:59:45','',0,'http://sandbox.arrayfire.com/wp-content/uploads/2015/10/temp.html',0,'attachment','text/html',0),(8565,18528,'2015-11-09 16:04:31','2015-11-09 16:04:31','Recently one of our interns completed his project ahead of schedule and asked if he could spend some time writing a particle filtering demo in ArrayFire for use at our upcoming trade shows. While learning the ins and outs of ArrayFire he posed several excellent questions which prompted us to start a series of blog posts entitled \"<a href=\"http://sandbox.arrayfire.com/tag/learning-arrayfire-from-scratch/\">Learning ArrayFire from scratch</a>\" that are geared to first-time users of our library.\n\nIn today\'s post I will cover the installation process on Windows, Mac, and Linux. Our next post will discuss the basics of setting up your first ArrayFire project.\n\n<!--more-->\n\nInstalling ArrayFire couldn\'t be easier. We ship installers for Windows, OSX, and Linux. Although you could <a href=\"https://github.com/arrayfire/arrayfire\">build ArrayFire from source</a>, we suggest using our pre-compiled binaries as they include the Intel Math Kernel Library to accelerate linear algebra functions.\n\nPlease note that although our download page requires a valid login, registration is free and downloading ArrayFire is also free. We request your contact information so that we may notify you of software updates and occasionally collect user feedback about our library.\n\nIn general, the installation process for ArrayFire looks like this:\n<ol type=\"1\">\n	<li>Install prerequisites</li>\n	<li><a href=\"http://sandbox.arrayfire.com/download/\">Download</a> the ArrayFire installer for your operating system</li>\n	<li>Install ArrayFire</li>\n	<li>Test the installation</li>\n	<li><a href=\"#GettingHelp\">Where to go for help?</a></li>\n</ol>\nBelow you will find instructions for\n<ul>\n	<li><a href=\"#Windows\">Windows</a></li>\n	<li>Linux including\n<ul>\n	<li><a href=\"#Debian\">Debian 8</a></li>\n	<li><a href=\"#Ubuntu\">Ubuntu 14.10 and later</a></li>\n	<li><a href=\"#Fedora\">Fedora 21</a></li>\n</ul>\n</li>\n	<li><a href=\"#OSX\">Mac OSX (.sh and brew)</a></li>\n</ul>\n<h3><a id=\"Windows\" class=\"anchor\"></a>Windows</h3>\nIf you wish to use CUDA or OpenCL please ensure that you have also installed\nsupport for these technologies from your video card vendor\'s website.\n\nNext <a href=\"http://sandbox.arrayfire.com/download/\">download</a> and run the ArrayFire installer.\nAfter it has completed, you need to add ArrayFire to the path for all users.\n<ol>\n	<li>Open Advanced System Settings:\n* Windows 8: Move the Mouse pointer to the bottom right corner of the screen, Right click, choose System. Then click \"Advanced System Settings\"\n* Windows 7: Open the Start Menu and Right Click on \"Computer\". Then choose Properties and click \"Advanced System Settings\"</li>\n	<li>In Advanced System Settings window, click on Advanced tab</li>\n	<li>Click on Environment Variables, then under System Variables, find PATH, and click on it.</li>\n	<li>In edit mode, append <span class=\"lang:default decode:true  crayon-inline \">%AF_PATH%/lib</span> . NOTE: Ensure that there is a semi-colon separating <span class=\"lang:default decode:true  crayon-inline \">%AF_PATH%/lib</span>  from any existing content (e.g. <span class=\"lang:default decode:true  crayon-inline \">EXISTING_PATHS;%AF_PATH%/lib;</span> ) otherwise other software may not function correctly.</li>\n</ol>\nFinally, verify that the path addition worked correctly. You can do this by running any of the HelloWorld examples located in <span class=\"lang:default decode:true  crayon-inline \">AF_PATH/examples/helloworld/</span>\n<h3>Linux</h3>\n<h4><a id=\"Debian\" class=\"anchor\"></a>Debian 8</h4>\nFirst install the prerequisite packages:\n<pre class=\"fragment\"># Prerequisite packages:\napt-get install libfreeimage-dev libatlas3gf-base libfftw3-dev libglew-dev libglewmx-dev libglfw3-dev cmake\n\n# Enable GPU support (OpenCL):\napt-get install ocl-icd-libopencl1\n</pre>\nIf you wish to use CUDA, please <a href=\"https://developer.nvidia.com/cuda-zone\">download the latest version of CUDA</a> and install it on your system.\n\nNext <a href=\"http://sandbox.arrayfire.com/download/\">download</a> ArrayFire. After you have the file, run the installer.\n<pre class=\"fragment\">./arrayfire_*_Linux_x86_64.sh --exclude-subdir --prefix=/usr/local\n</pre>\n<h4><a id=\"Fedora\" class=\"anchor\"></a>Fedora 21</h4>\nFirst install the prerequisite packages:\n<pre class=\"fragment \"># Install prerequiste packages\nyum install freeimage atlas fftw libGLEW libGLEWmx glfw cmake\n</pre>\nIf you wish to use CUDA, please <a href=\"https://developer.nvidia.com/cuda-downloads\">download the latest version of CUDA</a> and install it on your system.\n\nNext <a href=\"http://sandbox.arrayfire.com/download/\">download</a> ArrayFire. After you have the file, run the installer.\n<pre class=\"fragment\">./arrayfire_*_Linux_x86_64.sh --exclude-subdir --prefix=/usr/local\n</pre>\n<h4><a id=\"Ubuntu\" class=\"anchor\"></a>Ubuntu 14.04 and later</h4>\nFirst install the prerequisite packages:\n<pre class=\"fragment\"># Prerequisite packages:\nsudo apt-get install libfreeimage-dev libatlas3gf-base libfftw3-dev libglew-dev libglewmx-dev libglfw3-dev cmake\n</pre>\nUbuntu 14.04 will not have the libglfw3-dev package in its repositories. You can either build the library from source (following the <a href=\"https://github.com/arrayfire/arrayfire/wiki/Build-Instructions-for-Linux#general-dependencies\">instructions listed</a>) or install the library from a PPA as follows:\n<pre class=\"lang:default decode:true\">sudo apt-add repository ppa:keithw/glfw3\nsudo apt-get update\nsudo apt-get install glfw3</pre>\nAfter this point, the installation should proceed identically to Ubuntu 14.10 or newer.\n\nIf you are using ArrayFire on the Tegra-K1 also install these packages:\n<pre class=\"fragment\">sudo apt-get install libatlas3gf-base libatlas-dev libfftw3-dev liblapacke-dev\n</pre>\nIf your system has a CUDA GPU, we suggest downloading the latest drivers from NVIDIA in the form of a Debian package and installing using the package manager. At present, CUDA downloads can be found on the <a href=\"https://developer.nvidia.com/cuda-downloads\">NVIDIA CUDA download page</a> Follow NVIDIA\'s instructions for getting CUDA set up.\n\nIf you wish to use OpenCL, simply install the OpenCL ICD loader along with any drivers required for your hardware.\n<pre class=\"fragment\"># Enable GPU support (OpenCL):\napt-get install ocl-icd-libopencl1\n</pre>\nFinally, <a href=\"http://sandbox.arrayfire.com/download/\">download</a> ArrayFire. After you have the file, run the installer using:\n<pre class=\"fragment\">./arrayfire_*_Linux_x86_64.sh --exclude-subdir --prefix=/usr/local\n</pre>\n<h3><a id=\"OSX\" class=\"anchor\"></a>Mac OSX</h3>\nOn OSX there are several dependencies that are not integrated into the operating system. The ArrayFire installer automatically satisfies these dependencies using <a href=\"http://brew.sh/\">Homebrew</a>. If you don\'t have Homebrew installed on your system, the ArrayFire installer will ask you do to so.\n\nSimply <a href=\"http://sandbox.arrayfire.com/download\">download</a> the ArrayFire installer and double-click it to carry out the installation.\n\nArrayFire can also be installed through Homebrew directly using <span class=\"lang:default decode:true  crayon-inline \">brew install arrayfire</span> ; however, it will not include MKL acceleration of linear algebra functions.\n<h3><a id=\"Testing\" class=\"anchor\"></a>Testing the installation</h3>\nAfter ArrayFire is installed, you can build the example programs as follows:\n<pre class=\"fragment\">cp -r /usr/local/share/doc/arrayfire/examples .\ncd examples\nmkdir build\ncd build\ncmake ..\nmake\n</pre>\n<h3><a id=\"GettingHelp\" class=\"anchor\"></a>Getting help</h3>\n<ul>\n	<li>Google Groups: <a href=\"https://groups.google.com/forum/#!forum/arrayfire-users\">https://groups.google.com/forum/#!forum/arrayfire-users</a></li>\n	<li>ArrayFire Services: <a href=\"http://sandbox.arrayfire.com/consulting/\">Consulting</a> | <a href=\"http://sandbox.arrayfire.com/support/\">Support</a> | <a href=\"http://sandbox.arrayfire.com/training/\">Training</a></li>\n	<li>ArrayFire Blogs: <a href=\"http://sandbox.arrayfire.com/blog/\">http://sandbox.arrayfire.com/blog/</a></li>\n	<li>Email: <a href=\"#\">technical@arrayfire.com</a></li>\n</ul>\n&nbsp;','Learning ArrayFire from scratch: Installation','','inherit','open','closed','','8542-autosave-v1','','','2015-11-09 16:04:31','2015-11-09 16:04:31','',8542,'http://sandbox.arrayfire.com/8542-autosave-v1/',0,'revision','',0),(8566,18528,'2015-11-02 18:44:28','2015-11-02 18:44:28','Recently one of our interns completed his project ahead of schedule and asked if he could spend some time writing a particle filtering demo in ArrayFire for use at our upcoming trade shows. While learning the ins and outs of ArrayFire he posed several excellent questions which prompted us to start a series of blog posts entitled \"<a href=\"http://sandbox.arrayfire.com/tag/learning-arrayfire-from-scratch/\">Learning ArrayFire from scratch</a>\" that are geared to first-time users of our library.\r\n\r\nIn today\'s post I will cover the installation process on Windows, Mac, and Linux. Our next post will discuss the basics of setting up your first ArrayFire project.\r\n\r\n<!--more-->\r\n\r\nInstalling ArrayFire couldn\'t be easier. We ship installers for Windows, OSX, and Linux. Although you could <a href=\"https://github.com/arrayfire/arrayfire\">build ArrayFire from source</a>, we suggest using our pre-compiled binaries as they include the Intel Math Kernel Library to accelerate linear algebra functions.\r\n\r\nPlease note that although our download page requires a valid login, registration is free and downloading ArrayFire is also free. We request your contact information so that we may notify you of software updates and occasionally collect user feedback about our library.\r\n\r\nIn general, the installation process for ArrayFire looks like this:\r\n<ol type=\"1\">\r\n	<li>Install prerequisites</li>\r\n	<li><a href=\"http://sandbox.arrayfire.com/download/\">Download</a> the ArrayFire installer for your operating system</li>\r\n	<li>Install ArrayFire</li>\r\n	<li>Test the installation</li>\r\n	<li><a href=\"#GettingHelp\">Where to go for help?</a></li>\r\n</ol>\r\nBelow you will find instructions for\r\n<ul>\r\n	<li><a href=\"#Windows\">Windows</a></li>\r\n	<li>Linux including\r\n<ul>\r\n	<li><a href=\"#Debian\">Debian 8</a></li>\r\n	<li><a href=\"#Ubuntu\">Ubuntu 14.10 and later</a></li>\r\n	<li><a href=\"#Fedora\">Fedora 21</a></li>\r\n</ul>\r\n</li>\r\n	<li><a href=\"#OSX\">Mac OSX (.sh and brew)</a></li>\r\n</ul>\r\n<h3><a id=\"Windows\" class=\"anchor\"></a>Windows</h3>\r\nIf you wish to use CUDA or OpenCL please ensure that you have also installed\r\nsupport for these technologies from your video card vendor\'s website.\r\n\r\nNext <a href=\"http://sandbox.arrayfire.com/download/\">download</a> and run the ArrayFire installer.\r\nAfter it has completed, you need to add ArrayFire to the path for all users.\r\n<ol>\r\n	<li>Open Advanced System Settings:\r\n* Windows 8: Move the Mouse pointer to the bottom right corner of the screen, Right click, choose System. Then click \"Advanced System Settings\"\r\n* Windows 7: Open the Start Menu and Right Click on \"Computer\". Then choose Properties and click \"Advanced System Settings\"</li>\r\n	<li>In Advanced System Settings window, click on Advanced tab</li>\r\n	<li>Click on Environment Variables, then under System Variables, find PATH, and click on it.</li>\r\n	<li>In edit mode, append <span class=\"lang:default decode:true  crayon-inline \">%AF_PATH%/lib</span> . NOTE: Ensure that there is a semi-colon separating <span class=\"lang:default decode:true  crayon-inline \">%AF_PATH%/lib</span>  from any existing content (e.g. <span class=\"lang:default decode:true  crayon-inline \">EXISTING_PATHS;%AF_PATH%/lib;</span> ) otherwise other software may not function correctly.</li>\r\n</ol>\r\nFinally, verify that the path addition worked correctly. You can do this by running any of the HelloWorld examples located in <span class=\"lang:default decode:true  crayon-inline \">AF_PATH/examples/helloworld/</span>\r\n<h3>Linux</h3>\r\n<h4><a id=\"Debian\" class=\"anchor\"></a>Debian 8</h4>\r\nFirst install the prerequisite packages:\r\n<pre class=\"fragment\"># Prerequisite packages:\r\napt-get install libfreeimage-dev libatlas3gf-base libfftw3-dev libglew-dev libglewmx-dev libglfw3-dev cmake\r\n\r\n# Enable GPU support (OpenCL):\r\napt-get install ocl-icd-libopencl1\r\n</pre>\r\nIf you wish to use CUDA, please <a href=\"https://developer.nvidia.com/cuda-zone\">download the latest version of CUDA</a> and install it on your system.\r\n\r\nNext <a href=\"http://sandbox.arrayfire.com/download/\">download</a> ArrayFire. After you have the file, run the installer.\r\n<pre class=\"fragment\">./arrayfire_*_Linux_x86_64.sh --exclude-subdir --prefix=/usr/local\r\n</pre>\r\n<h4><a id=\"Fedora\" class=\"anchor\"></a>Fedora 21</h4>\r\nFirst install the prerequisite packages:\r\n<pre class=\"fragment \"># Install prerequiste packages\r\nyum install freeimage atlas fftw libGLEW libGLEWmx glfw cmake\r\n</pre>\r\nIf you wish to use CUDA, please <a href=\"https://developer.nvidia.com/cuda-downloads\">download the latest version of CUDA</a> and install it on your system.\r\n\r\nNext <a href=\"http://sandbox.arrayfire.com/download/\">download</a> ArrayFire. After you have the file, run the installer.\r\n<pre class=\"fragment\">./arrayfire_*_Linux_x86_64.sh --exclude-subdir --prefix=/usr/local\r\n</pre>\r\n<h4><a id=\"Ubuntu\" class=\"anchor\"></a>Ubuntu 14.04 and later</h4>\r\nFirst install the prerequisite packages:\r\n<pre class=\"fragment\"># Prerequisite packages:\r\nsudo apt-get install libfreeimage-dev libatlas3gf-base libfftw3-dev libglew-dev libglewmx-dev libglfw3-dev cmake\r\n</pre>\r\nIf you are using Ubuntu 14.04, you will need to install GLFW3 from source following the <a href=\"https://github.com/arrayfire/arrayfire/wiki/Build-Instructions-for-Linux#general-dependencies\">instructions listed here</a>. After this point, the installation should proceed identically to Ubuntu 14.10 or newer.\r\n\r\nIf you are using ArrayFire on the Tegra-K1 also install these packages:\r\n<pre class=\"fragment\">sudo apt-get install libatlas3gf-base libatlas-dev libfftw3-dev liblapacke-dev\r\n</pre>\r\nIf your system has a CUDA GPU, we suggest downloading the latest drivers from NVIDIA in the form of a Debian package and installing using the package manager. At present, CUDA downloads can be found on the <a href=\"https://developer.nvidia.com/cuda-downloads\">NVIDIA CUDA download page</a> Follow NVIDIA\'s instructions for getting CUDA set up.\r\n\r\nIf you wish to use OpenCL, simply install the OpenCL ICD loader along with any drivers required for your hardware.\r\n<pre class=\"fragment\"># Enable GPU support (OpenCL):\r\napt-get install ocl-icd-libopencl1\r\n</pre>\r\nFinally, <a href=\"http://sandbox.arrayfire.com/download/\">download</a> ArrayFire. After you have the file, run the installer using:\r\n<pre class=\"fragment\">./arrayfire_*_Linux_x86_64.sh --exclude-subdir --prefix=/usr/local\r\n</pre>\r\n<h3><a id=\"OSX\" class=\"anchor\"></a>Mac OSX</h3>\r\nOn OSX there are several dependencies that are not integrated into the operating system. The ArrayFire installer automatically satisfies these dependencies using <a href=\"http://brew.sh/\">Homebrew</a>. If you don\'t have Homebrew installed on your system, the ArrayFire installer will ask you do to so.\r\n\r\nSimply <a href=\"http://sandbox.arrayfire.com/download\">download</a> the ArrayFire installer and double-click it to carry out the installation.\r\n\r\nArrayFire can also be installed through Homebrew directly using <span class=\"lang:default decode:true  crayon-inline \">brew install arrayfire</span> ; however, it will not include MKL acceleration of linear algebra functions.\r\n<h3><a id=\"Testing\" class=\"anchor\"></a>Testing the installation</h3>\r\nAfter ArrayFire is installed, you can build the example programs as follows:\r\n<pre class=\"fragment\">cp -r /usr/local/share/doc/arrayfire/examples .\r\ncd examples\r\nmkdir build\r\ncd build\r\ncmake ..\r\nmake\r\n</pre>\r\n<h3><a id=\"GettingHelp\" class=\"anchor\"></a>Getting help</h3>\r\n<ul>\r\n	<li>Google Groups: <a href=\"https://groups.google.com/forum/#!forum/arrayfire-users\">https://groups.google.com/forum/#!forum/arrayfire-users</a></li>\r\n	<li>ArrayFire Services: <a href=\"http://sandbox.arrayfire.com/consulting/\">Consulting</a> | <a href=\"http://sandbox.arrayfire.com/support/\">Support</a> | <a href=\"http://sandbox.arrayfire.com/training/\">Training</a></li>\r\n	<li>ArrayFire Blogs: <a href=\"http://sandbox.arrayfire.com/blog/\">http://sandbox.arrayfire.com/blog/</a></li>\r\n	<li>Email: <a href=\"#\">technical@arrayfire.com</a></li>\r\n</ul>\r\n&nbsp;','Learning ArrayFire from scratch: Installation','','inherit','open','closed','','8542-revision-v1','','','2015-11-02 18:44:28','2015-11-02 18:44:28','',8542,'http://sandbox.arrayfire.com/8542-revision-v1/',0,'revision','',0),(8567,11,'2015-11-02 18:45:59','2015-11-02 18:45:59','At ArrayFire, we constantly encounter projects that require OpenGL and run on a remote server that does not have a display.\r\nIn this blog, we have compiled a list of steps that users can use to run full profile OpenGL applications over SSH on remote systems without a display.\r\n\r\nA few notes before we get started.\r\n<ul>\r\n        <li>This blog is limited to computers running distributions of Linux.\r\n	<li>The first part of the blog that shows the configuration of the xorg.conf file is limited to NVIDIA cards (with display).</li>\r\n	<li>AMD cards support this capability without the modification of xorg.conf file. However, we have not been able to get a comprehensive list of supported devices.</li>\r\n</ul>\r\n\r\n<h4>Requirements</h4>\r\nYou will need access to the remote system over SSH.\r\nTo run the tool, you will need <code>libGL.so<code> and </code>libX11.so</code>. Another tool I would recommend strongly is glewinfo. Most linux distributions ship this with the glew-utils package. An alternate to glewinfo is glxinfo which is present on all systems with X. You can substitute glewinfo with glxinfo in all the commands below if needed.\r\n\r\n<h4 id=\"ConfigX\">Configuring X (NVIDIA Only)</h4>\r\nTo get X to running on NVIDIA cards, we need to make changes to the xorg.conf file. Before making the change, make sure you create a back up of the current version on your system (name it xorg.conf.stable).\r\nYou can find a sample xorg.conf file <a href=\"https://github.com/arrayfire/glContext/blob/master/xorg.conf\" title=\"xorg.conf\" target=\"_blank\">here</a>. The sample file is for a NVIDIA GTX 690. The specific things to notice are the use of \"UseDisplayDevice\" option under \"Screen\" and the \"Virtual\" option under \"SubSection Display\". You can use parts of this file to configure your own config file. Make sure the options listed in the sample file get listed in your config file as well.\r\nSave and close the file.\r\n\r\nNow run this command: <code># nvidia-xconfig -a --use-display-device=None --virtual=1280x1024</code>\r\nRestart the system.\r\n\r\n<strong>Note:</strong> To abort trying this, just copy xorg.conf.stable back to xorg.conf and restart.\r\n\r\nThe following is only for GeForce cards. Quadro and Tesla cards can skip to <a href=\"#InitDiag\">Initial Diagnosis</a> section.\r\n\r\nOn restart, run the command <code># /usr/bin/X :0 &</code>. Ideally, this command should give an output similar to:\r\n<pre>\r\nX.Org X Server 1.13.0\r\nRelease Date: 2012-09-05\r\nX Protocol Version 11, Revision 0\r\n\r\n<Some more output here>\r\n\r\nLoading extension GLX\r\nLoading extension NV-GLX\r\nLoading extension NV-CONTROL\r\n</pre>\r\n\r\nThis means X has started successfully on the virtual display.\r\nIf it fails, restart the system and try again. You can also look at /var/log/Xorg.0.log for the log of the failure.\r\n\r\n<h5>Update: Known issue with Starting X</h5>\r\nIf the output is not similar to the one shown above, run the <a href=\"#InitDiag\">Initial Diagnosis</a> section below. If the output shows an error as follows:\r\n<pre>\r\n$ env DISPLAY=:0 glewinfo\r\nX Error of failed request:  BadWindow (invalid Window parameter)\r\n  Major opcode of failed request:  137 (NV-GLX)\r\n  Minor opcode of failed request:  4 ()\r\n  Resource id in failed request:  0x200004\r\n  Serial number of failed request:  39\r\n  Current serial number in output stream:  39\r\n</pre>\r\nrun the following commands:\r\n<pre>\r\nsudo mv /usr/lib/xorg/modules/extensions/libglx.so /usr/lib/xorg/modules/extensions/libglx.so.orig\r\nsudo ln -s /usr/lib/xorg/modules/extensions/libglx.so.XXX.YY /usr/lib/xorg/modules/extensions/libglx.so\r\n</pre>\r\nWhere XXX.YY is the NVIDIA driver version.\r\n\r\nNow try starting X again.\r\n\r\n<h4 id=\"InitDiag\">Initial Diagnosis</h4>\r\nOnce X has started successfully, run <code>echo $DISPLAY</code>. It is very likely that the output of this will be empty.\r\nIf you have glewinfo installed, run the following command <code>env DISPLAY=:0 glewinfo | less</code>.\r\nThe goal of this command is to run glewinfo having temporarily set DISPLAY to :0 (virtual display on remote system). If this command runs successfully, you should be able to see the graphics card on the remote system along with the full OpenGL profile. And now you are ready to deploy applications using X.\r\n\r\nIf you want to set DISPLAY for the entire session, run <code>export DISPLAY=:0</code>. To set DISPLAY permanently, add the same line to your bashrc file.\r\n\r\n<h4 id=\"Deploy\">Deploying Off-Screen Rendering Applications on Remote System</h4>\r\nThis is where X becomes crucial. Tools like GLFW may or may not work on remote systems because of their dependence on Xrandr and other software. The trick is use X to create an OpenGL context, and the run everything using off-screen rendering using framebuffers and renderbuffers. I took the source to create an OpenGL context using X from <a href=\"http://www.opengl.org/wiki/Tutorial:_OpenGL_3.0_Context_Creation_(GLX)\" title=\"OpenGL Context Creation Page\" target=\"_blank\"></a> and modified it slighly. Thanks to the folks at OpenGL.org for providing this. The source code with the changes I made can be found here: <a href=\"https://github.com/arrayfire/glContext/blob/master/glContext.hpp\" target=\"_blank\">glContext.hpp</a>.\r\n\r\nInclude this in your source code. To create context and delete contexts run createGLContext() and deleteGLContext() respectively.\r\n\r\nI have specified that the minimum OpenGL version should be 4.4 with forward context enabled. You can modify this version by changing the values at lines 26 and 27 of glContext.hpp.\r\nThe forward compatibility can be disabled at line 241 by changing line 241 to None.\r\nIf the application fails to create the specified version of the context, the application will exit.\r\n\r\nAt line 189, we create the window. The API description can be found <a href=\"http://tronche.com/gui/x/xlib/window/XCreateWindow.html\" title=\"link\" target=\"_blank\">here</a>. \"0, 0, 10, 10\" specifies the top-left corner (0,0) and the width and height of the window (10, 10). Since the goal of this is to be used for off-screen rendering, the size of the window has no effect on the rendering.\r\nLine 202 specifies the window title.\r\n\r\nIf everything goes successfully, you should see an output like this:\r\n<pre>\r\nglContext.hpp:297: GL Version  = 4.4.0 NVIDIA 331.79\r\nglContext.hpp:298: GL Vendor   = NVIDIA Corporation\r\nglContext.hpp:299: GL Renderer = GeForce GTX 690/PCIe/SSE2\r\nglContext.hpp:300: GL Shader   = 4.40 NVIDIA via Cg compiler\r\n</pre>\r\n\r\nIf you wish to use a lower minimum version, say 3.0, then the version provided by the output will reflect 3.0 since GL fetches version from the context.\r\n\r\nTo test the context creation as a stand alone, create a cpp file with the following contents (<a href=\"https://github.com/arrayfire/glContext/blob/master/glContext.cpp\" title=\"glContext.cpp\" target=\"_blank\">glContext.cpp</a>):\r\n<pre>\r\n#include \"glContext.hpp\"\r\n\r\nint main(int argc, char* argv[])\r\n{\r\n    createGLContext();\r\n    deleteGLContext();\r\n    return 0;\r\n}\r\n</pre>\r\n\r\nCompile this with <code>g++ -o gl glContext.cpp -lGL -lX11</code> and run with <code>./gl</code> (make sure DISPLAY is :0). If this works successfully, any off-screen rendering code will work perfectly with this.\r\n<strong>Note:</strong> If you use GLEW, make sure you include glew.h before including gl.h.\r\n\r\nIf you wish to know about remote OpenGL further or work with us on remote rendering, contact us at <a href=\"mailto:technical@arrayfire.com\" >technical@arrayfire.com</a>.\r\n\r\nLinks:\r\n<a href=\"http://www.opengl.org/wiki/Tutorial:_OpenGL_3.0_Context_Creation_(GLX)\" title=\"http://www.opengl.org/wiki/Tutorial:_OpenGL_3.0_Context_Creation_(GLX)\" target=\"_blank\">OpenGL Context Creation Tutorial</a>\r\n<a href=\"https://github.com/arrayfire/glContext\" title=\"https://github.com/arrayfire/glContext\" target=\"_blank\">ArrayFire glContext repo on Github</a>','Remote Off-Screen Rendering with OpenGL','','inherit','open','closed','','6054-revision-v1','','','2015-11-02 18:45:59','2015-11-02 18:45:59','',6054,'http://sandbox.arrayfire.com/6054-revision-v1/',0,'revision','',0),(8568,18528,'2015-11-04 13:13:53','2015-11-04 13:13:53','Continuing our blog series \"<a href=\"http://sandbox.arrayfire.com/tag/learning-arrayfire-from-scratch/\">Learning ArrayFire from scratch</a>\" today we will discuss how to set up an ArrayFire project on Linux using CMake or standard makefiles.\r\n\r\n<!--more-->\r\n\r\nOnce you have <a class=\"el\" href=\"installing.htm\">installed</a> ArrayFire on your system, the next thing to do is set up your build system. On Linux, you can create ArrayFire projects using almost any editor, compiler, or build system. The only requirements are that you include the ArrayFire header directories and link with the ArrayFire library you intend to use.\r\n<h4>The big picture</h4>\r\nOn Linux, we suggest you install ArrayFire to the <span class=\"lang:default decode:true  crayon-inline\">/usr/local/</span>  directory so that all of the include files and libraries are part of your standard path. The installer will populate files in the following sub-directories:\r\n<pre class=\"lang:default highlight:0 decode:true fragment \">include/arrayfire.h         - Primary ArrayFire include file\r\ninclude/af/*.h              - Additional include files\r\nlib/libaf*                  - CPU, CUDA, and OpenCL libraries (.a, .so)\r\nlib/libforge*               - Visualization library\r\nshare/ArrayFire/cmake/*     - CMake config (find) scripts\r\nshare/ArrayFire/examples/*  - All ArrayFire examples\r\n</pre>\r\nBecause ArrayFire follows standard installation practices, you can use basically any build system to create and compile projects that use ArrayFire. Among the many possible build systems on Linux we suggest using ArrayFire with either CMake or Makefiles with CMake being our preferred build system.\r\n<h4>Prerequisite software</h4>\r\nTo build ArrayFire projects you will need a compiler\r\n<h5>Fedora, Centos and Redhat</h5>\r\nInstall EPEL repo (not required for Fedora)\r\n<div class=\"fragment\">\r\n<div class=\"line\">\r\n<pre class=\"lang:default decode:true \">yum install epel-release\r\nyum update</pre>\r\nInstall build dependencies\r\n\r\n</div>\r\n</div>\r\n<pre class=\"lang:default decode:true\">yum install gcc gcc-c++ cmake make</pre>\r\n<h5><strong>Debian and Ubuntu</strong></h5>\r\nInstall common dependencies\r\n<div class=\"fragment\">\r\n<div class=\"line\">\r\n<pre class=\"lang:default decode:true\">apt-get install build-essential cmake cmake-curses-gui</pre>\r\n</div>\r\n</div>\r\n<h4>CMake</h4>\r\nWe recommend that the CMake build system be used to create ArrayFire projects.f you are writing a new ArrayFire project in C/C++ from scratch, we suggest you grab a copy of our <a href=\"https://github.com/bkloppenborg/arrayfire-cmake-example\">CMake Project Example</a>; however, it is useful to read the documentation below in case you need to add ArrayFire to an existing project.\r\n\r\nAs <a href=\"#big-picture\">discussed above</a>, ArrayFire ships with a series of CMake scripts to make finding and using our library easy. The scripts will automatically find all versions of the ArrayFire library and pick the most powerful of the installed backends (typically CUDA).\r\n\r\nFirst create a file called <span class=\"lang:default decode:true  crayon-inline \">CMakeLists.txt</span>  in your project directory:\r\n<pre class=\"fragment\">cd your-project-directory\r\ntouch CMakeLists.txt\r\n</pre>\r\nand populate it with the following code:\r\n<pre class=\"fragment\">FIND_PACKAGE(ArrayFire)\r\nINCLUDE_DIRECTORIES(${ArrayFire_INCLUDE_DIRS})\r\n\r\n... [gather source files, etc.]\r\n\r\n# If you intend to use OpenCL, you need to find it\r\nFIND_PACKAGE(OpenCL)\r\nSET(EXTRA_LIBS ${CMAKE_THREAD_LIBS_INIT} ${OpenCL_LIBRARIES})\r\n\r\n# Or if you intend to use CUDA, you need it as well as NVVM:\r\nFIND_PACKAGE(CUDA)\r\nFIND_PACKAGE(NVVM) # this FIND script can be found in the ArrayFire CMake example repository\r\nSET(EXTRA_LIBS ${CMAKE_THREAD_LIBS_INIT} ${CUDA_LIBRARIES} ${NVVM_LIB})\r\n\r\nADD_EXECUTABLE(my_executable [list your source files here])\r\nTARGET_LINK_LIBRARIES(my_executable ${ArrayFire_LIBRARIES} ${EXTRA_LIBS})\r\n</pre>\r\nwhere <span class=\"lang:default decode:true  crayon-inline \">my_executable</span>  is the name of the executable you wish to create. See the <a href=\"https://cmake.org/documentation/\">CMake documentation</a> for more information on how to use CMake. Clearly the above code snippet precludes the use of both CUDA and OpenCL, see the <a href=\"https://github.com/bkloppenborg/arrayfire-cmake-example\">ArrayFire CMake Example</a> for an example of how to build executables for both backends from the same CMake script.\r\n<pre class=\"fragment\">ArrayFire_INCLUDE_DIRS    - Location of ArrayFire\'s include directory.\r\nArrayFire_LIBRARIES       - Location of ArrayFire\'s libraries. \r\n                            This will default to a GPU backend \r\n                            if one is found\r\nArrayFire_FOUND           - True if ArrayFire has been located\r\n</pre>\r\nIf you wish to use a specific backend, the find script also defines these variables:\r\n<pre class=\"fragment\">ArrayFire_CPU_FOUND         - True of the ArrayFire CPU library has been found.\r\nArrayFire_CPU_LIBRARIES     - Location of ArrayFire\'s CPU library, if found\r\nArrayFire_CUDA_FOUND        - True of the ArrayFire CUDA library has been found.\r\nArrayFire_CUDA_LIBRARIES    - Location of ArrayFire\'s CUDA library, if found\r\nArrayFire_OpenCL_FOUND      - True of the ArrayFire OpenCL library has been found.\r\nArrayFire_OpenCL_LIBRARIES  - Location of ArrayFire\'s OpenCL library, if found\r\nArrayFire_Unified_FOUND     - True of the ArrayFire Unified library has been found.\r\nArrayFire_Unified_LIBRARIES - Location of ArrayFire\'s Unified library, if found\r\n</pre>\r\nTherefore, if you wish to target a specific specific backend, simply replace <span class=\"lang:default decode:true  crayon-inline \">${ArrayFire_LIBRARIES}</span>  with<span class=\"lang:default decode:true  crayon-inline \">${ArrayFire_CPU}</span> , <span class=\"lang:default decode:true  crayon-inline \">${ArrayFire_OPENCL}</span> , <span class=\"lang:default decode:true  crayon-inline \">${ArrayFire_CUDA}</span> , or <span class=\"lang:default decode:true  crayon-inline \">${ArrayFire_Unified}</span>  in the<span class=\"lang:default decode:true  crayon-inline \">TARGET_LINK_LIBRARIES</span>  command above.\r\n\r\nNext we need to instruct CMake to create build instructions and then compile. We suggest using CMake\'s out-of-source build functionality to keep your build and source files cleanly separated. To do this:\r\n<pre class=\"fragment\">cd your-project-directory\r\nmkdir build\r\ncd build\r\ncmake ..\r\nmake\r\n</pre>\r\n<em>NOTE:</em> If you have installed ArrayFire to a non-standard location, CMake can still help you out. When you execute CMake specify the path to the <span class=\"lang:default decode:true  crayon-inline \">ArrayFireConfig*</span>  files that are found in the <span class=\"lang:default decode:true  crayon-inline \">share/ArrayFire/cmake</span>  subdirectory of the installation folder. For example, if ArrayFire were installed locally to <span class=\"lang:default decode:true  crayon-inline \">/opt/ArrayFire</span>  then you would modify the <span class=\"lang:default decode:true  crayon-inline \">cmake</span> command above to contain the following definition:\r\n<pre class=\"fragment\">cmake -DArrayFire_DIR=/opt/ArrayFire/share/ArrayFire/cmake ..\r\n</pre>\r\nYou can also specify this information in the <span class=\"lang:default decode:true  crayon-inline \">ccmake</span>  command-line interface.\r\n<h4>MakeFiles</h4>\r\nBuilding ArrayFire projects with Makefiles is fairly similar to CMake except you must specify all paths and libraries manually. As with any make project, you need to specify the include path to the directory containing <span class=\"lang:default decode:true  crayon-inline \">arrayfire.h</span> file. This should be <span class=\"lang:default decode:true  crayon-inline \">-I /usr/local/include</span>  if you followed our installation instructions. Similarly, you will need to specify the path to the ArrayFire library using the <code>-L</code> option (e.g. <span class=\"lang:default decode:true  crayon-inline \">-L/usr/local/lib</span> ) followed by the specific ArrayFire library you wish to use using the <code>-l</code> option (for example <span class=\"lang:default decode:true  crayon-inline\">-lafcpu</span> , <span class=\"lang:default decode:true  crayon-inline\">-lafopencl</span> , <span class=\"lang:default decode:true  crayon-inline \">-lafcuda</span> , or <span class=\"lang:default decode:true  crayon-inline \">-laf</span>  for the CPU, OpenCL, CUDA, and unified backends respectively.\r\n\r\nHere is a minimial example MakeFile which uses ArrayFire\'s CPU backend:\r\n<pre class=\"fragment\">LIBS=-lafcpu\r\nLIB_PATHS=-L/usr/lib\r\nINCLUDES=-I/usr/include\r\nCC=g++ $(COMPILER_OPTIONS)\r\nCOMPILER_OPTIONS=-std=c++11 -g\r\n\r\nall: main.cpp Makefile\r\n    $(CC) main.cpp -o test $(INCLUDES) $(LIBS) $(LIB_PATHS)</pre>\r\n&nbsp;','Setting up an ArrayFire project on Linux','','publish','open','closed','','setting-up-an-arrayfire-project-on-linux','','','2015-11-06 20:50:33','2015-11-06 20:50:33','',0,'http://sandbox.arrayfire.com/?p=8568',0,'post','',0),(8569,18528,'2015-11-02 19:07:21','2015-11-02 19:07:21','Continuing our blog series \"<a href=\"http://sandbox.arrayfire.com/tag/learning-arrayfire-from-scratch/\">Learning ArrayFire from scratch</a>\" today we will discuss how to set up an ArrayFire project on Windows using Microsoft Visual Studio.\r\n\r\n<!--more-->\r\n\r\n&nbsp;','Setting up an ArrayFire project on Linux','','inherit','open','closed','','8568-revision-v1','','','2015-11-02 19:07:21','2015-11-02 19:07:21','',8568,'http://sandbox.arrayfire.com/8568-revision-v1/',0,'revision','',0),(8571,11,'2015-11-02 19:50:41','2015-11-02 19:50:41','Continuing our blog series \"<a href=\"http://sandbox.arrayfire.com/tag/learning-arrayfire-from-scratch/\">Learning ArrayFire from scratch</a>\" today we will discuss how to set up an ArrayFire project on Windows using Microsoft Visual Studio 2013.\r\n\r\nIf you haven\'t already, please download and install ArrayFire from our <a href=\"http://sandbox.arrayfire.com/download\">downloads page</a>.\r\n\r\nThis blog is divided into 2 parts. The first part deals with a simple way for you to add a single ArrayFire backend to your existing project. The second part deals creating an ArrayFire project from scratch that can use all the backends by simply switching the configuration.\r\n\r\n<h4>Part 1: Adding ArrayFire to your existing project</h4>\r\nThere are 3 main steps to adding ArrayFire to your project.\r\n\r\n<h5>1. Add ArrayFire Include Directory</h5>\r\nOpen Project Properties -> C/C++ -> General -> Additional Include Directories and append \"$(AF_PATH)/include;\".\r\n\r\n<h5>2. Add ArrayFire Library and Directory</h5>\r\nOpen Project Properties -> Linker -> General -> Additional Library Directories and append \"$(AF_PATH)/lib;\".\r\nOpen Project Properties -> Linker -> Input -> Additional Dependencies and append \"afbackend.lib\", where backend should be replaced with cpu/cuda/opencl.\r\n\r\n<h5>3. Add Helper Definitions (Optional)</h5>\r\nOpen Project Properties -> C/C++ -> Preprocessor -> Preprocessor Definitions and append \"NOMINMAX;AF_BACKEND\", where you can replace BACKEND with CPU/CUDA/OPENCL.\r\nThe NOMINMAX definition is recommended.\r\n\r\n<h5>X. Copy CUDA DLLs</h5>\r\nIf you choose to use the CUDA backend in your project, you will need to copy the NVVM DLL to a suitable location. This DLL is not a part of the standard PATH and hence can result in runtime errors if not copied. We recommend copying this to the executable directory. To make this process automatic, we can add this as a post build command so that it runs with every build.\r\n\r\nOpen Project Properties -> Build Events -> Post Build Events (click edit). In the dialog box, enter\r\n<pre>\r\necho copy \"$(CUDA_PATH)\\nvvm\\bin\\nvvm64*.dll\" \"$(OutDir)\"\r\ncopy \"$(CUDA_PATH)\\nvvm\\bin\\nvvm64*.dll\" \"$(OutDir)\"\r\n</pre>\r\nNote: Ensure the new line in between.\r\n\r\n<!--more-->\r\n\r\n&nbsp;','Setting up an ArrayFire project on Windows','','inherit','open','closed','','8546-revision-v1','','','2015-11-02 19:50:41','2015-11-02 19:50:41','',8546,'http://sandbox.arrayfire.com/8546-revision-v1/',0,'revision','',0),(8572,18528,'2015-11-02 22:23:38','2015-11-02 22:23:38','Continuing our blog series \"<a href=\"http://sandbox.arrayfire.com/tag/learning-arrayfire-from-scratch/\">Learning ArrayFire from scratch</a>\" today we will discuss how to set up an ArrayFire project on Linux using CMake or standard makefiles.\r\n\r\n<!--more-->\r\n\r\nOnce you have <a class=\"el\" href=\"installing.htm\">installed</a> ArrayFire on your system, the next thing to do is set up your build system. On Linux, you can create ArrayFire projects using almost any editor, compiler, or build system. The only requirements are that you include the ArrayFire header directories and link with the ArrayFire library you intend to use.\r\n<h2>The big picture</h2>\r\nOn Linux, we suggest you install ArrayFire to the <span class=\"lang:default decode:true  crayon-inline\">/usr/local/</span>  directory so that all of the include files and libraries are part of your standard path. The installer will populate files in the following sub-directories:\r\n<pre class=\"fragment\">include/arrayfire.h         - Primary ArrayFire include file\r\ninclude/af/*.h              - Additional include files\r\nlib/libaf*                  - CPU, CUDA, and OpenCL libraries (.a, .so)\r\nlib/libforge*               - Visualization library\r\nshare/ArrayFire/cmake/*     - CMake config (find) scripts\r\nshare/ArrayFire/examples/*  - All ArrayFire examples\r\n</pre>\r\nBecause ArrayFire follows standard installation practices, you can use basically any build system to create and compile projects that use ArrayFire. Among the many possible build systems on Linux we suggest using ArrayFire with either CMake or Makefiles with CMake being our preferred build system.\r\n<h2>Prerequisite software</h2>\r\nTo build ArrayFire projects you will need a compiler\r\n<h4>Fedora, Centos and Redhat</h4>\r\nInstall EPEL repo (not required for Fedora)\r\n<div class=\"fragment\">\r\n<div class=\"line\">\r\n<pre class=\"lang:default decode:true \">yum install epel-release\r\nyum update</pre>\r\nInstall build dependencies\r\n\r\n</div>\r\n</div>\r\n<pre class=\"lang:default decode:true\">yum install gcc gcc-c++ cmake make</pre>\r\n<strong>Debian and Ubuntu</strong>\r\n\r\nInstall common dependencies\r\n<div class=\"fragment\">\r\n<div class=\"line\">\r\n<pre class=\"lang:default decode:true\">apt-get install build-essential cmake cmake-curses-gui</pre>\r\n</div>\r\n</div>\r\n<h2>CMake</h2>\r\nWe recommend that the CMake build system be used to create ArrayFire projects.f you are writing a new ArrayFire project in C/C++ from scratch, we suggest you grab a copy of our <a href=\"https://github.com/bkloppenborg/arrayfire-cmake-example\">CMake Project Example</a>; however, it is useful to read the documentation below in case you need to add ArrayFire to an existing project.\r\n\r\nAs <a href=\"#big-picture\">discussed above</a>, ArrayFire ships with a series of CMake scripts to make finding and using our library easy. The scripts will automatically find all versions of the ArrayFire library and pick the most powerful of the installed backends (typically CUDA).\r\n\r\nFirst create a file called <span class=\"lang:default decode:true  crayon-inline \">CMakeLists.txt</span>  in your project directory:\r\n<pre class=\"fragment\">cd your-project-directory\r\ntouch CMakeLists.txt\r\n</pre>\r\nand populate it with the following code:\r\n<pre class=\"fragment\">FIND_PACKAGE(ArrayFire)\r\nINCLUDE_DIRECTORIES(${ArrayFire_INCLUDE_DIRS})\r\n\r\n... [gather source files, etc.]\r\n\r\n# If you intend to use OpenCL, you need to find it\r\nFIND_PACKAGE(OpenCL)\r\nSET(EXTRA_LIBS ${CMAKE_THREAD_LIBS_INIT} ${OpenCL_LIBRARIES})\r\n\r\n# Or if you intend to use CUDA, you need it as well as NVVM:\r\nFIND_PACKAGE(CUDA)\r\nFIND_PACKAGE(NVVM) # this FIND script can be found in the ArrayFire CMake example repository\r\nSET(EXTRA_LIBS ${CMAKE_THREAD_LIBS_INIT} ${CUDA_LIBRARIES} ${NVVM_LIB})\r\n\r\nADD_EXECUTABLE(my_executable [list your source files here])\r\nTARGET_LINK_LIBRARIES(my_executable ${ArrayFire_LIBRARIES} ${EXTRA_LIBS})\r\n</pre>\r\nwhere <span class=\"lang:default decode:true  crayon-inline \">my_executable</span>  is the name of the executable you wish to create. See the <a href=\"https://cmake.org/documentation/\">CMake documentation</a> for more information on how to use CMake. Clearly the above code snippet precludes the use of both CUDA and OpenCL, see the <a href=\"https://github.com/bkloppenborg/arrayfire-cmake-example\">ArrayFire CMake Example</a> for an example of how to build executables for both backends from the same CMake script.\r\n<pre class=\"fragment\">ArrayFire_INCLUDE_DIRS    - Location of ArrayFire\'s include directory.\r\nArrayFire_LIBRARIES       - Location of ArrayFire\'s libraries. \r\n                            This will default to a GPU backend \r\n                            if one is found\r\nArrayFire_FOUND           - True if ArrayFire has been located\r\n</pre>\r\nIf you wish to use a specific backend, the find script also defines these variables:\r\n<pre class=\"fragment\">ArrayFire_CPU_FOUND         - True of the ArrayFire CPU library has been found.\r\nArrayFire_CPU_LIBRARIES     - Location of ArrayFire\'s CPU library, if found\r\nArrayFire_CUDA_FOUND        - True of the ArrayFire CUDA library has been found.\r\nArrayFire_CUDA_LIBRARIES    - Location of ArrayFire\'s CUDA library, if found\r\nArrayFire_OpenCL_FOUND      - True of the ArrayFire OpenCL library has been found.\r\nArrayFire_OpenCL_LIBRARIES  - Location of ArrayFire\'s OpenCL library, if found\r\nArrayFire_Unified_FOUND     - True of the ArrayFire Unified library has been found.\r\nArrayFire_Unified_LIBRARIES - Location of ArrayFire\'s Unified library, if found\r\n</pre>\r\nTherefore, if you wish to target a specific specific backend, simply replace <span class=\"lang:default decode:true  crayon-inline \">${ArrayFire_LIBRARIES}</span>  with<span class=\"lang:default decode:true  crayon-inline \">${ArrayFire_CPU}</span> , <span class=\"lang:default decode:true  crayon-inline \">${ArrayFire_OPENCL}</span> , <span class=\"lang:default decode:true  crayon-inline \">${ArrayFire_CUDA}</span> , or <span class=\"lang:default decode:true  crayon-inline \">${ArrayFire_Unified}</span>  in the<span class=\"lang:default decode:true  crayon-inline \">TARGET_LINK_LIBRARIES</span>  command above.\r\n\r\nNext we need to instruct CMake to create build instructions and then compile. We suggest using CMake\'s out-of-source build functionality to keep your build and source files cleanly separated. To do this:\r\n<pre class=\"fragment\">cd your-project-directory\r\nmkdir build\r\ncd build\r\ncmake ..\r\nmake\r\n</pre>\r\n<em>NOTE:</em> If you have installed ArrayFire to a non-standard location, CMake can still help you out. When you execute CMake specify the path to the <span class=\"lang:default decode:true  crayon-inline \">ArrayFireConfig*</span>  files that are found in the <span class=\"lang:default decode:true  crayon-inline \">share/ArrayFire/cmake</span>  subdirectory of the installation folder. For example, if ArrayFire were installed locally to <span class=\"lang:default decode:true  crayon-inline \">/opt/ArrayFire</span>  then you would modify the <span class=\"lang:default decode:true  crayon-inline \">cmake</span> command above to contain the following definition:\r\n<pre class=\"fragment\">cmake -DArrayFire_DIR=/opt/ArrayFire/share/ArrayFire/cmake ..\r\n</pre>\r\nYou can also specify this information in the <span class=\"lang:default decode:true  crayon-inline \">ccmake</span>  command-line interface.\r\n<h2>MakeFiles</h2>\r\nBuilding ArrayFire projects with Makefiles is fairly similar to CMake except you must specify all paths and libraries manually. As with any make project, you need to specify the include path to the directory containing <span class=\"lang:default decode:true  crayon-inline \">arrayfire.h</span> file. This should be <span class=\"lang:default decode:true  crayon-inline \">-I /usr/local/include</span>  if you followed our installation instructions. Similarly, you will need to specify the path to the ArrayFire library using the <code>-L</code> option (e.g. <span class=\"lang:default decode:true  crayon-inline \">-L/usr/local/lib</span> ) followed by the specific ArrayFire library you wish to use using the <code>-l</code> option (for example <span class=\"lang:default decode:true  crayon-inline\">-lafcpu</span> , <span class=\"lang:default decode:true  crayon-inline\">-lafopencl</span> , <span class=\"lang:default decode:true  crayon-inline \">-lafcuda</span> , or <span class=\"lang:default decode:true  crayon-inline \">-laf</span>  for the CPU, OpenCL, CUDA, and unified backends respectively.\r\n\r\nHere is a minimial example MakeFile which uses ArrayFire\'s CPU backend:\r\n<pre class=\"fragment\">LIBS=-lafcpu\r\nLIB_PATHS=-L/usr/lib\r\nINCLUDES=-I/usr/include\r\nCC=g++ $(COMPILER_OPTIONS)\r\nCOMPILER_OPTIONS=-std=c++11 -g\r\n\r\nall: main.cpp Makefile\r\n    $(CC) main.cpp -o test $(INCLUDES) $(LIBS) $(LIB_PATHS)</pre>\r\n&nbsp;','Setting up an ArrayFire project on Linux','','inherit','open','closed','','8568-revision-v1','','','2015-11-02 22:23:38','2015-11-02 22:23:38','',8568,'http://sandbox.arrayfire.com/8568-revision-v1/',0,'revision','',0),(8573,18528,'2015-11-02 22:35:29','2015-11-02 22:35:29','Continuing our blog series \"<a href=\"http://sandbox.arrayfire.com/tag/learning-arrayfire-from-scratch/\">Learning ArrayFire from scratch</a>\" today we will discuss how to set up an ArrayFire project on Linux using CMake or standard makefiles.\r\n\r\n<!--more-->\r\n\r\nOnce you have <a class=\"el\" href=\"installing.htm\">installed</a> ArrayFire on your system, the next thing to do is set up your build system. On Linux, you can create ArrayFire projects using almost any editor, compiler, or build system. The only requirements are that you include the ArrayFire header directories and link with the ArrayFire library you intend to use.\r\n<h3>The big picture</h3>\r\nOn Linux, we suggest you install ArrayFire to the <span class=\"lang:default decode:true  crayon-inline\">/usr/local/</span>  directory so that all of the include files and libraries are part of your standard path. The installer will populate files in the following sub-directories:\r\n<pre class=\"fragment\">include/arrayfire.h         - Primary ArrayFire include file\r\ninclude/af/*.h              - Additional include files\r\nlib/libaf*                  - CPU, CUDA, and OpenCL libraries (.a, .so)\r\nlib/libforge*               - Visualization library\r\nshare/ArrayFire/cmake/*     - CMake config (find) scripts\r\nshare/ArrayFire/examples/*  - All ArrayFire examples\r\n</pre>\r\nBecause ArrayFire follows standard installation practices, you can use basically any build system to create and compile projects that use ArrayFire. Among the many possible build systems on Linux we suggest using ArrayFire with either CMake or Makefiles with CMake being our preferred build system.\r\n<h3>Prerequisite software</h3>\r\nTo build ArrayFire projects you will need a compiler\r\n<h4>Fedora, Centos and Redhat</h4>\r\nInstall EPEL repo (not required for Fedora)\r\n<div class=\"fragment\">\r\n<div class=\"line\">\r\n<pre class=\"lang:default decode:true \">yum install epel-release\r\nyum update</pre>\r\nInstall build dependencies\r\n\r\n</div>\r\n</div>\r\n<pre class=\"lang:default decode:true\">yum install gcc gcc-c++ cmake make</pre>\r\n<h4><strong>Debian and Ubuntu</strong></h4>\r\nInstall common dependencies\r\n<div class=\"fragment\">\r\n<div class=\"line\">\r\n<pre class=\"lang:default decode:true\">apt-get install build-essential cmake cmake-curses-gui</pre>\r\n</div>\r\n</div>\r\n<h3>CMake</h3>\r\nWe recommend that the CMake build system be used to create ArrayFire projects.f you are writing a new ArrayFire project in C/C++ from scratch, we suggest you grab a copy of our <a href=\"https://github.com/bkloppenborg/arrayfire-cmake-example\">CMake Project Example</a>; however, it is useful to read the documentation below in case you need to add ArrayFire to an existing project.\r\n\r\nAs <a href=\"#big-picture\">discussed above</a>, ArrayFire ships with a series of CMake scripts to make finding and using our library easy. The scripts will automatically find all versions of the ArrayFire library and pick the most powerful of the installed backends (typically CUDA).\r\n\r\nFirst create a file called <span class=\"lang:default decode:true  crayon-inline \">CMakeLists.txt</span>  in your project directory:\r\n<pre class=\"fragment\">cd your-project-directory\r\ntouch CMakeLists.txt\r\n</pre>\r\nand populate it with the following code:\r\n<pre class=\"fragment\">FIND_PACKAGE(ArrayFire)\r\nINCLUDE_DIRECTORIES(${ArrayFire_INCLUDE_DIRS})\r\n\r\n... [gather source files, etc.]\r\n\r\n# If you intend to use OpenCL, you need to find it\r\nFIND_PACKAGE(OpenCL)\r\nSET(EXTRA_LIBS ${CMAKE_THREAD_LIBS_INIT} ${OpenCL_LIBRARIES})\r\n\r\n# Or if you intend to use CUDA, you need it as well as NVVM:\r\nFIND_PACKAGE(CUDA)\r\nFIND_PACKAGE(NVVM) # this FIND script can be found in the ArrayFire CMake example repository\r\nSET(EXTRA_LIBS ${CMAKE_THREAD_LIBS_INIT} ${CUDA_LIBRARIES} ${NVVM_LIB})\r\n\r\nADD_EXECUTABLE(my_executable [list your source files here])\r\nTARGET_LINK_LIBRARIES(my_executable ${ArrayFire_LIBRARIES} ${EXTRA_LIBS})\r\n</pre>\r\nwhere <span class=\"lang:default decode:true  crayon-inline \">my_executable</span>  is the name of the executable you wish to create. See the <a href=\"https://cmake.org/documentation/\">CMake documentation</a> for more information on how to use CMake. Clearly the above code snippet precludes the use of both CUDA and OpenCL, see the <a href=\"https://github.com/bkloppenborg/arrayfire-cmake-example\">ArrayFire CMake Example</a> for an example of how to build executables for both backends from the same CMake script.\r\n<pre class=\"fragment\">ArrayFire_INCLUDE_DIRS    - Location of ArrayFire\'s include directory.\r\nArrayFire_LIBRARIES       - Location of ArrayFire\'s libraries. \r\n                            This will default to a GPU backend \r\n                            if one is found\r\nArrayFire_FOUND           - True if ArrayFire has been located\r\n</pre>\r\nIf you wish to use a specific backend, the find script also defines these variables:\r\n<pre class=\"fragment\">ArrayFire_CPU_FOUND         - True of the ArrayFire CPU library has been found.\r\nArrayFire_CPU_LIBRARIES     - Location of ArrayFire\'s CPU library, if found\r\nArrayFire_CUDA_FOUND        - True of the ArrayFire CUDA library has been found.\r\nArrayFire_CUDA_LIBRARIES    - Location of ArrayFire\'s CUDA library, if found\r\nArrayFire_OpenCL_FOUND      - True of the ArrayFire OpenCL library has been found.\r\nArrayFire_OpenCL_LIBRARIES  - Location of ArrayFire\'s OpenCL library, if found\r\nArrayFire_Unified_FOUND     - True of the ArrayFire Unified library has been found.\r\nArrayFire_Unified_LIBRARIES - Location of ArrayFire\'s Unified library, if found\r\n</pre>\r\nTherefore, if you wish to target a specific specific backend, simply replace <span class=\"lang:default decode:true  crayon-inline \">${ArrayFire_LIBRARIES}</span>  with<span class=\"lang:default decode:true  crayon-inline \">${ArrayFire_CPU}</span> , <span class=\"lang:default decode:true  crayon-inline \">${ArrayFire_OPENCL}</span> , <span class=\"lang:default decode:true  crayon-inline \">${ArrayFire_CUDA}</span> , or <span class=\"lang:default decode:true  crayon-inline \">${ArrayFire_Unified}</span>  in the<span class=\"lang:default decode:true  crayon-inline \">TARGET_LINK_LIBRARIES</span>  command above.\r\n\r\nNext we need to instruct CMake to create build instructions and then compile. We suggest using CMake\'s out-of-source build functionality to keep your build and source files cleanly separated. To do this:\r\n<pre class=\"fragment\">cd your-project-directory\r\nmkdir build\r\ncd build\r\ncmake ..\r\nmake\r\n</pre>\r\n<em>NOTE:</em> If you have installed ArrayFire to a non-standard location, CMake can still help you out. When you execute CMake specify the path to the <span class=\"lang:default decode:true  crayon-inline \">ArrayFireConfig*</span>  files that are found in the <span class=\"lang:default decode:true  crayon-inline \">share/ArrayFire/cmake</span>  subdirectory of the installation folder. For example, if ArrayFire were installed locally to <span class=\"lang:default decode:true  crayon-inline \">/opt/ArrayFire</span>  then you would modify the <span class=\"lang:default decode:true  crayon-inline \">cmake</span> command above to contain the following definition:\r\n<pre class=\"fragment\">cmake -DArrayFire_DIR=/opt/ArrayFire/share/ArrayFire/cmake ..\r\n</pre>\r\nYou can also specify this information in the <span class=\"lang:default decode:true  crayon-inline \">ccmake</span>  command-line interface.\r\n<h3>MakeFiles</h3>\r\nBuilding ArrayFire projects with Makefiles is fairly similar to CMake except you must specify all paths and libraries manually. As with any make project, you need to specify the include path to the directory containing <span class=\"lang:default decode:true  crayon-inline \">arrayfire.h</span> file. This should be <span class=\"lang:default decode:true  crayon-inline \">-I /usr/local/include</span>  if you followed our installation instructions. Similarly, you will need to specify the path to the ArrayFire library using the <code>-L</code> option (e.g. <span class=\"lang:default decode:true  crayon-inline \">-L/usr/local/lib</span> ) followed by the specific ArrayFire library you wish to use using the <code>-l</code> option (for example <span class=\"lang:default decode:true  crayon-inline\">-lafcpu</span> , <span class=\"lang:default decode:true  crayon-inline\">-lafopencl</span> , <span class=\"lang:default decode:true  crayon-inline \">-lafcuda</span> , or <span class=\"lang:default decode:true  crayon-inline \">-laf</span>  for the CPU, OpenCL, CUDA, and unified backends respectively.\r\n\r\nHere is a minimial example MakeFile which uses ArrayFire\'s CPU backend:\r\n<pre class=\"fragment\">LIBS=-lafcpu\r\nLIB_PATHS=-L/usr/lib\r\nINCLUDES=-I/usr/include\r\nCC=g++ $(COMPILER_OPTIONS)\r\nCOMPILER_OPTIONS=-std=c++11 -g\r\n\r\nall: main.cpp Makefile\r\n    $(CC) main.cpp -o test $(INCLUDES) $(LIBS) $(LIB_PATHS)</pre>\r\n&nbsp;','Setting up an ArrayFire project on Linux','','inherit','open','closed','','8568-revision-v1','','','2015-11-02 22:35:29','2015-11-02 22:35:29','',8568,'http://sandbox.arrayfire.com/8568-revision-v1/',0,'revision','',0),(8574,18528,'2015-11-02 22:36:02','2015-11-02 22:36:02','Continuing our blog series \"<a href=\"http://sandbox.arrayfire.com/tag/learning-arrayfire-from-scratch/\">Learning ArrayFire from scratch</a>\" today we will discuss how to set up an ArrayFire project on Linux using CMake or standard makefiles.\r\n\r\n<!--more-->\r\n\r\nOnce you have <a class=\"el\" href=\"installing.htm\">installed</a> ArrayFire on your system, the next thing to do is set up your build system. On Linux, you can create ArrayFire projects using almost any editor, compiler, or build system. The only requirements are that you include the ArrayFire header directories and link with the ArrayFire library you intend to use.\r\n<h4>The big picture</h4>\r\nOn Linux, we suggest you install ArrayFire to the <span class=\"lang:default decode:true  crayon-inline\">/usr/local/</span>  directory so that all of the include files and libraries are part of your standard path. The installer will populate files in the following sub-directories:\r\n<pre class=\"fragment\">include/arrayfire.h         - Primary ArrayFire include file\r\ninclude/af/*.h              - Additional include files\r\nlib/libaf*                  - CPU, CUDA, and OpenCL libraries (.a, .so)\r\nlib/libforge*               - Visualization library\r\nshare/ArrayFire/cmake/*     - CMake config (find) scripts\r\nshare/ArrayFire/examples/*  - All ArrayFire examples\r\n</pre>\r\nBecause ArrayFire follows standard installation practices, you can use basically any build system to create and compile projects that use ArrayFire. Among the many possible build systems on Linux we suggest using ArrayFire with either CMake or Makefiles with CMake being our preferred build system.\r\n<h4>Prerequisite software</h4>\r\nTo build ArrayFire projects you will need a compiler\r\n<h5>Fedora, Centos and Redhat</h5>\r\nInstall EPEL repo (not required for Fedora)\r\n<div class=\"fragment\">\r\n<div class=\"line\">\r\n<pre class=\"lang:default decode:true \">yum install epel-release\r\nyum update</pre>\r\nInstall build dependencies\r\n\r\n</div>\r\n</div>\r\n<pre class=\"lang:default decode:true\">yum install gcc gcc-c++ cmake make</pre>\r\n<h5><strong>Debian and Ubuntu</strong></h5>\r\nInstall common dependencies\r\n<div class=\"fragment\">\r\n<div class=\"line\">\r\n<pre class=\"lang:default decode:true\">apt-get install build-essential cmake cmake-curses-gui</pre>\r\n</div>\r\n</div>\r\n<h4>CMake</h4>\r\nWe recommend that the CMake build system be used to create ArrayFire projects.f you are writing a new ArrayFire project in C/C++ from scratch, we suggest you grab a copy of our <a href=\"https://github.com/bkloppenborg/arrayfire-cmake-example\">CMake Project Example</a>; however, it is useful to read the documentation below in case you need to add ArrayFire to an existing project.\r\n\r\nAs <a href=\"#big-picture\">discussed above</a>, ArrayFire ships with a series of CMake scripts to make finding and using our library easy. The scripts will automatically find all versions of the ArrayFire library and pick the most powerful of the installed backends (typically CUDA).\r\n\r\nFirst create a file called <span class=\"lang:default decode:true  crayon-inline \">CMakeLists.txt</span>  in your project directory:\r\n<pre class=\"fragment\">cd your-project-directory\r\ntouch CMakeLists.txt\r\n</pre>\r\nand populate it with the following code:\r\n<pre class=\"fragment\">FIND_PACKAGE(ArrayFire)\r\nINCLUDE_DIRECTORIES(${ArrayFire_INCLUDE_DIRS})\r\n\r\n... [gather source files, etc.]\r\n\r\n# If you intend to use OpenCL, you need to find it\r\nFIND_PACKAGE(OpenCL)\r\nSET(EXTRA_LIBS ${CMAKE_THREAD_LIBS_INIT} ${OpenCL_LIBRARIES})\r\n\r\n# Or if you intend to use CUDA, you need it as well as NVVM:\r\nFIND_PACKAGE(CUDA)\r\nFIND_PACKAGE(NVVM) # this FIND script can be found in the ArrayFire CMake example repository\r\nSET(EXTRA_LIBS ${CMAKE_THREAD_LIBS_INIT} ${CUDA_LIBRARIES} ${NVVM_LIB})\r\n\r\nADD_EXECUTABLE(my_executable [list your source files here])\r\nTARGET_LINK_LIBRARIES(my_executable ${ArrayFire_LIBRARIES} ${EXTRA_LIBS})\r\n</pre>\r\nwhere <span class=\"lang:default decode:true  crayon-inline \">my_executable</span>  is the name of the executable you wish to create. See the <a href=\"https://cmake.org/documentation/\">CMake documentation</a> for more information on how to use CMake. Clearly the above code snippet precludes the use of both CUDA and OpenCL, see the <a href=\"https://github.com/bkloppenborg/arrayfire-cmake-example\">ArrayFire CMake Example</a> for an example of how to build executables for both backends from the same CMake script.\r\n<pre class=\"fragment\">ArrayFire_INCLUDE_DIRS    - Location of ArrayFire\'s include directory.\r\nArrayFire_LIBRARIES       - Location of ArrayFire\'s libraries. \r\n                            This will default to a GPU backend \r\n                            if one is found\r\nArrayFire_FOUND           - True if ArrayFire has been located\r\n</pre>\r\nIf you wish to use a specific backend, the find script also defines these variables:\r\n<pre class=\"fragment\">ArrayFire_CPU_FOUND         - True of the ArrayFire CPU library has been found.\r\nArrayFire_CPU_LIBRARIES     - Location of ArrayFire\'s CPU library, if found\r\nArrayFire_CUDA_FOUND        - True of the ArrayFire CUDA library has been found.\r\nArrayFire_CUDA_LIBRARIES    - Location of ArrayFire\'s CUDA library, if found\r\nArrayFire_OpenCL_FOUND      - True of the ArrayFire OpenCL library has been found.\r\nArrayFire_OpenCL_LIBRARIES  - Location of ArrayFire\'s OpenCL library, if found\r\nArrayFire_Unified_FOUND     - True of the ArrayFire Unified library has been found.\r\nArrayFire_Unified_LIBRARIES - Location of ArrayFire\'s Unified library, if found\r\n</pre>\r\nTherefore, if you wish to target a specific specific backend, simply replace <span class=\"lang:default decode:true  crayon-inline \">${ArrayFire_LIBRARIES}</span>  with<span class=\"lang:default decode:true  crayon-inline \">${ArrayFire_CPU}</span> , <span class=\"lang:default decode:true  crayon-inline \">${ArrayFire_OPENCL}</span> , <span class=\"lang:default decode:true  crayon-inline \">${ArrayFire_CUDA}</span> , or <span class=\"lang:default decode:true  crayon-inline \">${ArrayFire_Unified}</span>  in the<span class=\"lang:default decode:true  crayon-inline \">TARGET_LINK_LIBRARIES</span>  command above.\r\n\r\nNext we need to instruct CMake to create build instructions and then compile. We suggest using CMake\'s out-of-source build functionality to keep your build and source files cleanly separated. To do this:\r\n<pre class=\"fragment\">cd your-project-directory\r\nmkdir build\r\ncd build\r\ncmake ..\r\nmake\r\n</pre>\r\n<em>NOTE:</em> If you have installed ArrayFire to a non-standard location, CMake can still help you out. When you execute CMake specify the path to the <span class=\"lang:default decode:true  crayon-inline \">ArrayFireConfig*</span>  files that are found in the <span class=\"lang:default decode:true  crayon-inline \">share/ArrayFire/cmake</span>  subdirectory of the installation folder. For example, if ArrayFire were installed locally to <span class=\"lang:default decode:true  crayon-inline \">/opt/ArrayFire</span>  then you would modify the <span class=\"lang:default decode:true  crayon-inline \">cmake</span> command above to contain the following definition:\r\n<pre class=\"fragment\">cmake -DArrayFire_DIR=/opt/ArrayFire/share/ArrayFire/cmake ..\r\n</pre>\r\nYou can also specify this information in the <span class=\"lang:default decode:true  crayon-inline \">ccmake</span>  command-line interface.\r\n<h4>MakeFiles</h4>\r\nBuilding ArrayFire projects with Makefiles is fairly similar to CMake except you must specify all paths and libraries manually. As with any make project, you need to specify the include path to the directory containing <span class=\"lang:default decode:true  crayon-inline \">arrayfire.h</span> file. This should be <span class=\"lang:default decode:true  crayon-inline \">-I /usr/local/include</span>  if you followed our installation instructions. Similarly, you will need to specify the path to the ArrayFire library using the <code>-L</code> option (e.g. <span class=\"lang:default decode:true  crayon-inline \">-L/usr/local/lib</span> ) followed by the specific ArrayFire library you wish to use using the <code>-l</code> option (for example <span class=\"lang:default decode:true  crayon-inline\">-lafcpu</span> , <span class=\"lang:default decode:true  crayon-inline\">-lafopencl</span> , <span class=\"lang:default decode:true  crayon-inline \">-lafcuda</span> , or <span class=\"lang:default decode:true  crayon-inline \">-laf</span>  for the CPU, OpenCL, CUDA, and unified backends respectively.\r\n\r\nHere is a minimial example MakeFile which uses ArrayFire\'s CPU backend:\r\n<pre class=\"fragment\">LIBS=-lafcpu\r\nLIB_PATHS=-L/usr/lib\r\nINCLUDES=-I/usr/include\r\nCC=g++ $(COMPILER_OPTIONS)\r\nCOMPILER_OPTIONS=-std=c++11 -g\r\n\r\nall: main.cpp Makefile\r\n    $(CC) main.cpp -o test $(INCLUDES) $(LIBS) $(LIB_PATHS)</pre>\r\n&nbsp;','Setting up an ArrayFire project on Linux','','inherit','open','closed','','8568-revision-v1','','','2015-11-02 22:36:02','2015-11-02 22:36:02','',8568,'http://sandbox.arrayfire.com/8568-revision-v1/',0,'revision','',0),(8575,11,'2015-11-02 23:14:07','2015-11-02 23:14:07','<div class=\"header\">\r\n<div class=\"headertitle\">\r\n<div class=\"title\">\r\n<div class=\"header\">\r\n<div class=\"headertitle\">\r\n<div class=\"title\">Using ArrayFire with Microsoft Windows and Visual Studio</div>\r\n</div>\r\n</div>\r\n<div class=\"contents\">\r\n<div class=\"textblock\">\r\n\r\nIf you have not already done so, please make sure you have installed, configured, and tested ArrayFire following the <a class=\"el\" href=\"installing.htm\">installation instructions</a>.\r\n<h2>The big picture</h2>\r\nThe ArrayFire Windows installer installs the following:\r\n<ol type=\"1\">\r\n	<li>Creates <code>AF_PATH</code> environment variable to point to the installation location.</li>\r\n	<li><code>AF_PATH/include</code> : Header files for ArrayFire (Include Dir)</li>\r\n	<li><code>AF_PATH/lib</code> : All ArrayFire backends libraries, dlls and dependency dlls (Library dir)</li>\r\n	<li><code>AF_PATH/examples</code> : Examples to get started. Some examples also have pre-built exectuables</li>\r\n	<li><code>AF_PATH/cmake</code> : CMake config files for automatic configuration of external projects</li>\r\n	<li><code>AF_PATH/uninstall.exe</code> : Uninstaller</li>\r\n	<li><code>AF_PATH/*</code> : Other miscellenous files including licenses, logos, copyrights</li>\r\n</ol>\r\nThe installer also appends <code>%AF_PATH%/lib</code> to the User PATH variable. See <a href=\"#step1\">step 1</a> for more.\r\n\r\nTo add <code>%AF_PATH%/lib</code> to PATH for all users see the windows section in <a class=\"el\" href=\"installing.htm\">installation instructions</a>.\r\n<h3><a id=\"nvvm_dlls\" class=\"anchor\"></a>Dealing with CUDA NMMV DLLs</h3>\r\nThe NVVM DLLs are not a part of the standard <code>CUDA_PATH\\bin</code> directory which is added to PATH at the time of CUDA installation. Hence it is not found automatically by the system dll loading operation. There are a few ways to deal with this:\r\n<ol type=\"1\">\r\n	<li>Copy the DLLs to the exectuable location. This is the solution ArrayFire\'s examples use. The DLL ios copied to the executable location as a post build event. The stes for this are shown under <a href=\"#s3partA\">Step 3 - Part A</a>.</li>\r\n	<li>Copy <code>CUDA_PATH\\nvvm\\bin\\nvvm64_30_0.dll</code> to <code>CUDA_PATH\\bin</code>. This is a one time copy such that the NVVM DLL is now with all the other CUDA dlls and in a directory that is a part of PATH and hence the DLL can be detected automatically.</li>\r\n	<li>Add <code>%CUDA_PATH%\\nvvm\\bin</code> to the system PATH environment variable. This will allow automatic detection by the system and No further copying will be required. ArrayFire does not add this to PATH since the CUDA installer doesn\'t add it to PATH.</li>\r\n</ol>\r\n<h2><a id=\"step1\" class=\"anchor\"></a>Step 1: Running pre-built executables</h2>\r\nThe ArrayFire installer ships with a few pre-built executables with the examples. These should run out of the box when double clicked.\r\n\r\nSome prebuilt examples are:\r\n<ul>\r\n	<li>Helloworld (examples/helloworld)</li>\r\n	<li>BLAS (examples/benchmarks)</li>\r\n	<li>FFT (examples/benchmarks)</li>\r\n	<li>Pi Estimation (examples/benchmarks)</li>\r\n	<li>Conway (Graphics) (examples/graphics)</li>\r\n</ul>\r\nNote: For the CUDA executables, you will need to copy <code>CUDA_PATH\\nvvm\\bin\\nvvm64_30_0.dll</code> to the location of the executables.\r\n<h2><a id=\"step2\" class=\"anchor\"></a>Step 2: Build and Run a Project</h2>\r\n<ol type=\"1\">\r\n	<li>Open Visual Studio 2013. Open the HelloWorld solution which is located at <code>AF_PATH/examples/helloworld/helloworld.sln</code>.</li>\r\n	<li>Build the <code>helloworld</code> example. Be sure to, select the platform/configuration of your choice using the platform drop-down (the options are CPU, CUDA, OpenCL, and Unified) and Solution Configuration drop down (options of Release and Debug) menus.</li>\r\n	<li>Run the <code>helloworld</code> example</li>\r\n</ol>\r\n<h2><a id=\"step3\" class=\"anchor\"></a>Step 3: Using ArrayFire with Visual Studio</h2>\r\nThis is divided into 4 parts:\r\n<ul>\r\n	<li><a href=\"#s3partA\">Part A: Adding ArrayFire to an existing solution (Single Backend)</a></li>\r\n	<li><a href=\"#s3partB\">Part B: Adding ArrayFire CUDA to a new/existing CUDA project</a></li>\r\n	<li><a href=\"#s3partC\">Part C: Project with all ArrayFire backends</a></li>\r\n	<li><a href=\"#s3partD\">Part D: ArrayFire with CMake</a></li>\r\n</ul>\r\n<h3><a id=\"s3partA\" class=\"anchor\"></a>Part A: Adding ArrayFire to an existing solution (Single Backend)</h3>\r\nNote: If you plan on using Native CUDA code in the project, use the steps under <a href=\"#s3partB\">Part B</a>. Adding a single backend to an existing project is quite simple.\r\n<ol type=\"1\">\r\n	<li>Add <code>\"$(AF_PATH)/include;\"</code> to <em>Project Properties -&gt; C/C++ -&gt; General -&gt; Additional Include Directories</em></li>\r\n	<li>Add <code>\"$(AF_PATH)/lib;\"</code> to <em>Project Properties -&gt; Linker -&gt; General -&gt; Additional Library Directories</em></li>\r\n	<li>Add <code>afcpu.lib</code> or <code>afcuda.lib</code> or <code>afopencl.lib</code> to <em>Project Properties -&gt; Linker -&gt; Input -&gt; Additional Dependencies</em> based on your preferred backend.</li>\r\n	<li>(Optional) You may choose to define <code>NOMINMAX</code>, <code>AF_&lt;CPU/CUDA/OPENCL&gt;</code> and/or <code>AF_&lt;DEBUG/RELEASE&gt;</code> in your projects. This can be added to <em>Project Properties -&gt; C/C++ -&gt; General -&gt; Preprocessor-&gt; Preprocessory definitions</em>.</li>\r\n</ol>\r\nIf you are using the CUDA backend, it is important to ensure that the CUDA NVVM DLLs are copied to the exectuable directory. This can be done by adding a post build event.\r\n\r\nOpen the <em>Project Properties -&gt; Build Events -&gt; Post Build Events</em> dialog and add the following lines to it.\r\n<div class=\"fragment\">\r\n<div class=\"line\">echo <a class=\"code\" href=\"group__index__func__index.htm#ga25f470817062b23ad3f74347ea44b17c\">copy</a> <span class=\"stringliteral\">\"$(CUDA_PATH)\\nvvm\\bin\\nvvm64*.dll\"</span> <span class=\"stringliteral\">\"$(OutDir)\"</span></div>\r\n<div class=\"line\"><a class=\"code\" href=\"group__index__func__index.htm#ga25f470817062b23ad3f74347ea44b17c\">copy</a> <span class=\"stringliteral\">\"$(CUDA_PATH)\\nvvm\\bin\\nvvm64*.dll\"</span> <span class=\"stringliteral\">\"$(OutDir)\"</span></div>\r\n</div>\r\n<h3><a id=\"s3partB\" class=\"anchor\"></a>Part B: Adding ArrayFire CUDA to a new/existing CUDA project</h3>\r\nLastly, if your project contains custom CUDA code, the instructions are slightly different as it requires using a CUDA NVCC Project:\r\n<ol type=\"1\">\r\n	<li>Create a custom \"CUDA NVCC project\" in Visual Studio</li>\r\n	<li>Add <code>\"$(AF_PATH)/include;\"</code> to <em>Project Properties -&gt; CUDA C/C++ -&gt; General -&gt; Additional Include Directories</em></li>\r\n	<li>Add <code>\"$(AF_PATH)/lib;\"</code> to <em>Project Properties -&gt; Linker -&gt; General -&gt; Additional Library Directories</em></li>\r\n	<li>Add <code>afcpu.lib</code> or <code>afcuda.lib</code> or <code>afopencl.lib</code> to <em>Project Properties -&gt; Linker -&gt; Input -&gt; Additional Dependencies</em> based on your preferred backend.</li>\r\n	<li>(Optional) You may choose to define <code>NOMINMAX</code>, <code>AF_CUDA</code> and/or <code>AF_&lt;DEBUG/RELEASE&gt;</code> in your projects. This can be added to <em>Project Properties -&gt; C/C++ -&gt; General -&gt; Preprocessor-&gt; Preprocessory definitions</em>.</li>\r\n	<li>Pick a solution to handle the NVVM DLLs. We recommend the post build event method used in <a href=\"#s3partA\">Part A</a>.</li>\r\n</ol>\r\n<h3><a id=\"s3partC\" class=\"anchor\"></a>Part C: Project with all ArrayFire backends</h3>\r\nIf you wish to create a project that allows you to use all the ArrayFire backends with ease, the best way to go is to copy the <em>HelloWorld sln/vcxproj/cpp</em> file trio and rename them to suit your project.\r\n\r\nAll the ArrayFire examples are pre-configured for all ArrayFire backends as well as the Unified API. These can be chosen from the Solution/Platform configuration drop down boxes.\r\n\r\nYou can alternately download the template project from the <a href=\"https://github.com/shehzan10/AF_VS2013\">ArrayFire VS 2013 Template Projects</a>\r\n<h3><a id=\"s3partD\" class=\"anchor\"></a>Part D: ArrayFire with CMake</h3>\r\n<em>NOTE:</em> The ArrayFire installer sets up CMake file and registry so that it can be found by CMake by simply using the <code>Find_PACKAGE(ArrayFire)</code> command.\r\n\r\nIf you are writing a new ArrayFire project in C/C++ from scratch, we suggest you grab a copy of our <a href=\"https://github.com/bkloppenborg/arrayfire-cmake-example\">CMake Project Example</a>; however, it is useful to read the documentation below in case you need to add ArrayFire to an existing project.\r\n\r\nAs <a href=\"#big-picture\">discussed above</a>, ArrayFire ships with a series of CMake scripts to make finding and using our library easy. The scripts will automatically find all versions of the ArrayFire library and pick the most powerful of the installed backends (typically CUDA).\r\n\r\nFirst create a file called <code>CMakeLists.txt</code> in your project directory:\r\n<pre class=\"fragment\">cd your-project-directory\r\ntouch CMakeLists.txt\r\n</pre>\r\nand populate it with the following code:\r\n<pre class=\"fragment\">FIND_PACKAGE(ArrayFire)\r\nINCLUDE_DIRECTORIES(${ArrayFire_INCLUDE_DIRS})\r\n\r\n... [gather source files, etc.]\r\n\r\n# If you intend to use OpenCL, you need to find it\r\nFIND_PACKAGE(OpenCL)\r\nSET(EXTRA_LIBS ${CMAKE_THREAD_LIBS_INIT} ${OpenCL_LIBRARIES})\r\n\r\n# Or if you intend to use CUDA, you need it as well as NVVM:\r\nFIND_PACKAGE(CUDA)\r\nFIND_PACKAGE(NVVM) # this FIND script can be found in the ArrayFire CMake example repository\r\nSET(EXTRA_LIBS ${CMAKE_THREAD_LIBS_INIT} ${CUDA_LIBRARIES} ${NVVM_LIB})\r\n\r\nADD_EXECUTABLE(my_executable [list your source files here])\r\nTARGET_LINK_LIBRARIES(my_executable ${ArrayFire_LIBRARIES} ${EXTRA_LIBS})\r\n</pre>\r\nwhere <code>my_executable</code> is the name of the executable you wish to create. See the <a href=\"https://cmake.org/documentation/\">CMake documentation</a> for more information on how to use CMake. Clearly the above code snippet precludes the use of both CUDA and OpenCL, see the <a href=\"https://github.com/bkloppenborg/arrayfire-cmake-example\">ArrayFire CMake Example</a> for an example of how to build executables for both backends from the same CMake script.\r\n\r\nIn the above code listing, the <code>FIND_PACKAGE</code> will find the ArrayFire include files, libraries, and define several variables including:\r\n<pre class=\"fragment\">ArrayFire_INCLUDE_DIRS    - Location of ArrayFire\'s include directory.\r\nArrayFire_LIBRARIES       - Location of ArrayFire\'s libraries.\r\n                            This will default to a GPU backend if one\r\n                            is found\r\nArrayFire_FOUND           - True if ArrayFire has been located\r\n</pre>\r\nIf you wish to use a specific backend, the find script also defines these variables:\r\n<pre class=\"fragment\">ArrayFire_CPU_FOUND         - True of the ArrayFire CPU library has been found.\r\nArrayFire_CPU_LIBRARIES     - Location of ArrayFire\'s CPU library, if found\r\nArrayFire_CUDA_FOUND        - True of the ArrayFire CUDA library has been found.\r\nArrayFire_CUDA_LIBRARIES    - Location of ArrayFire\'s CUDA library, if found\r\nArrayFire_OpenCL_FOUND      - True of the ArrayFire OpenCL library has been found.\r\nArrayFire_OpenCL_LIBRARIES  - Location of ArrayFire\'s OpenCL library, if found\r\nArrayFire_Unified_FOUND     - True of the ArrayFire Unified library has been found.\r\nArrayFire_Unified_LIBRARIES - Location of ArrayFire\'s Unified library, if found\r\n</pre>\r\nTherefore, if you wish to target a specific specific backend, simply replace <code>${ArrayFire_LIBRARIES}</code> with <code>${ArrayFire_CPU}</code>, <code>${ArrayFire_OPENCL}</code>, <code>${ArrayFire_CUDA}</code>, or <code>${ArrayFire_Unified}</code> in the <code>TARGET_LINK_LIBRARIES</code> command above.\r\n\r\nNext we need to instruct CMake to create build instructions and then compile. We suggest using CMake\'s out-of-source build functionality to keep your build and source files cleanly separated. To do this open the CMake GUI.\r\n<ul>\r\n	<li>Under source directory, add the path to your project</li>\r\n	<li>Under build directory, add the path to your project and append /build</li>\r\n	<li>Click configure and choose Visual Studio 2013 Win 64 as the generator.</li>\r\n	<li>If configuration was successful, click generate. This will create a my-project.sln file under build. You can open this in Visual Studio and compile the ALL_BUILD project.</li>\r\n</ul>\r\nThe <a href=\"https://github.com/bkloppenborg/arrayfire-cmake-example\">ArrayFire CMake Example</a> is a CMake project used to demo how ArrayFire can be using with a CMake project.\r\n\r\nNote: The CMake project does not add the post build event to copy the NVVM DLLs in case of CUDA backend. You will need to either copy it manually to the exectuable directory, or pick another solution for it.\r\n\r\n</div>\r\n</div>\r\n</div>\r\n</div>\r\n</div>','Setting up an ArrayFire project on Windows','','inherit','open','closed','','8546-revision-v1','','','2015-11-02 23:14:07','2015-11-02 23:14:07','',8546,'http://sandbox.arrayfire.com/8546-revision-v1/',0,'revision','',0),(8576,18528,'2015-11-02 23:25:23','2015-11-02 23:25:23','Continuing our blog series \"<a href=\"http://sandbox.arrayfire.com/tag/learning-arrayfire-from-scratch/\">Learning ArrayFire from scratch</a>\" today we will discuss how to set up an ArrayFire project on Linux using CMake or standard makefiles.\r\n\r\n<!--more-->\r\n\r\nIf you have not already done so, please make sure you have installed, configured, and tested ArrayFire following the <a class=\"el\" href=\"installing.htm\">installation instructions</a>.\r\n<h2>The big picture</h2>\r\nThe ArrayFire Windows installer installs the following:\r\n<ol type=\"1\">\r\n	<li>Creates <code>AF_PATH</code> environment variable to point to the installation location.</li>\r\n	<li><code>AF_PATH/include</code> : Header files for ArrayFire (Include Dir)</li>\r\n	<li><code>AF_PATH/lib</code> : All ArrayFire backends libraries, dlls and dependency dlls (Library dir)</li>\r\n	<li><code>AF_PATH/examples</code> : Examples to get started. Some examples also have pre-built exectuables</li>\r\n	<li><code>AF_PATH/cmake</code> : CMake config files for automatic configuration of external projects</li>\r\n	<li><code>AF_PATH/uninstall.exe</code> : Uninstaller</li>\r\n	<li><code>AF_PATH/*</code> : Other miscellenous files including licenses, logos, copyrights</li>\r\n</ol>\r\nThe installer also appends <code>%AF_PATH%/lib</code> to the User PATH variable. See <a href=\"#step1\">step 1</a> for more.\r\n\r\nTo add <code>%AF_PATH%/lib</code> to PATH for all users see the windows section in <a class=\"el\" href=\"installing.htm\">installation instructions</a>.\r\n<h3><a id=\"nvvm_dlls\" class=\"anchor\"></a>Dealing with CUDA NMMV DLLs</h3>\r\nThe NVVM DLLs are not a part of the standard <code>CUDA_PATH\\bin</code> directory which is added to PATH at the time of CUDA installation. Hence it is not found automatically by the system dll loading operation. There are a few ways to deal with this:\r\n<ol type=\"1\">\r\n	<li>Copy the DLLs to the exectuable location. This is the solution ArrayFire\'s examples use. The DLL ios copied to the executable location as a post build event. The stes for this are shown under <a href=\"#s3partA\">Step 3 - Part A</a>.</li>\r\n	<li>Copy <code>CUDA_PATH\\nvvm\\bin\\nvvm64_30_0.dll</code> to <code>CUDA_PATH\\bin</code>. This is a one time copy such that the NVVM DLL is now with all the other CUDA dlls and in a directory that is a part of PATH and hence the DLL can be detected automatically.</li>\r\n	<li>Add <code>%CUDA_PATH%\\nvvm\\bin</code> to the system PATH environment variable. This will allow automatic detection by the system and No further copying will be required. ArrayFire does not add this to PATH since the CUDA installer doesn\'t add it to PATH.</li>\r\n</ol>\r\n<h2><a id=\"step1\" class=\"anchor\"></a>Step 1: Running pre-built executables</h2>\r\nThe ArrayFire installer ships with a few pre-built executables with the examples. These should run out of the box when double clicked.\r\n\r\nSome prebuilt examples are:\r\n<ul>\r\n	<li>Helloworld (examples/helloworld)</li>\r\n	<li>BLAS (examples/benchmarks)</li>\r\n	<li>FFT (examples/benchmarks)</li>\r\n	<li>Pi Estimation (examples/benchmarks)</li>\r\n	<li>Conway (Graphics) (examples/graphics)</li>\r\n</ul>\r\nNote: For the CUDA executables, you will need to copy <code>CUDA_PATH\\nvvm\\bin\\nvvm64_30_0.dll</code> to the location of the executables.\r\n<h2><a id=\"step2\" class=\"anchor\"></a>Step 2: Build and Run a Project</h2>\r\n<ol type=\"1\">\r\n	<li>Open Visual Studio 2013. Open the HelloWorld solution which is located at <code>AF_PATH/examples/helloworld/helloworld.sln</code>.</li>\r\n	<li>Build the <code>helloworld</code> example. Be sure to, select the platform/configuration of your choice using the platform drop-down (the options are CPU, CUDA, OpenCL, and Unified) and Solution Configuration drop down (options of Release and Debug) menus.</li>\r\n	<li>Run the <code>helloworld</code> example</li>\r\n</ol>\r\n<h2><a id=\"step3\" class=\"anchor\"></a>Step 3: Using ArrayFire with Visual Studio</h2>\r\nThis is divided into 4 parts:\r\n<ul>\r\n	<li><a href=\"#s3partA\">Part A: Adding ArrayFire to an existing solution (Single Backend)</a></li>\r\n	<li><a href=\"#s3partB\">Part B: Adding ArrayFire CUDA to a new/existing CUDA project</a></li>\r\n	<li><a href=\"#s3partC\">Part C: Project with all ArrayFire backends</a></li>\r\n	<li><a href=\"#s3partD\">Part D: ArrayFire with CMake</a></li>\r\n</ul>\r\n<h3><a id=\"s3partA\" class=\"anchor\"></a>Part A: Adding ArrayFire to an existing solution (Single Backend)</h3>\r\nNote: If you plan on using Native CUDA code in the project, use the steps under <a href=\"#s3partB\">Part B</a>. Adding a single backend to an existing project is quite simple.\r\n<ol type=\"1\">\r\n	<li>Add <code>\"$(AF_PATH)/include;\"</code> to <em>Project Properties -&gt; C/C++ -&gt; General -&gt; Additional Include Directories</em></li>\r\n	<li>Add <code>\"$(AF_PATH)/lib;\"</code> to <em>Project Properties -&gt; Linker -&gt; General -&gt; Additional Library Directories</em></li>\r\n	<li>Add <code>afcpu.lib</code> or <code>afcuda.lib</code> or <code>afopencl.lib</code> to <em>Project Properties -&gt; Linker -&gt; Input -&gt; Additional Dependencies</em> based on your preferred backend.</li>\r\n	<li>(Optional) You may choose to define <code>NOMINMAX</code>, <code>AF_&lt;CPU/CUDA/OPENCL&gt;</code> and/or <code>AF_&lt;DEBUG/RELEASE&gt;</code> in your projects. This can be added to <em>Project Properties -&gt; C/C++ -&gt; General -&gt; Preprocessor-&gt; Preprocessory definitions</em>.</li>\r\n</ol>\r\nIf you are using the CUDA backend, it is important to ensure that the CUDA NVVM DLLs are copied to the exectuable directory. This can be done by adding a post build event.\r\n\r\nOpen the <em>Project Properties -&gt; Build Events -&gt; Post Build Events</em> dialog and add the following lines to it.\r\n<div class=\"fragment\">\r\n<div class=\"line\">echo <a class=\"code\" href=\"group__index__func__index.htm#ga25f470817062b23ad3f74347ea44b17c\">copy</a> <span class=\"stringliteral\">\"$(CUDA_PATH)\\nvvm\\bin\\nvvm64*.dll\"</span> <span class=\"stringliteral\">\"$(OutDir)\"</span></div>\r\n<div class=\"line\"><a class=\"code\" href=\"group__index__func__index.htm#ga25f470817062b23ad3f74347ea44b17c\">copy</a> <span class=\"stringliteral\">\"$(CUDA_PATH)\\nvvm\\bin\\nvvm64*.dll\"</span> <span class=\"stringliteral\">\"$(OutDir)\"</span></div>\r\n</div>\r\n<h3><a id=\"s3partB\" class=\"anchor\"></a>Part B: Adding ArrayFire CUDA to a new/existing CUDA project</h3>\r\nLastly, if your project contains custom CUDA code, the instructions are slightly different as it requires using a CUDA NVCC Project:\r\n<ol type=\"1\">\r\n	<li>Create a custom \"CUDA NVCC project\" in Visual Studio</li>\r\n	<li>Add <code>\"$(AF_PATH)/include;\"</code> to <em>Project Properties -&gt; CUDA C/C++ -&gt; General -&gt; Additional Include Directories</em></li>\r\n	<li>Add <code>\"$(AF_PATH)/lib;\"</code> to <em>Project Properties -&gt; Linker -&gt; General -&gt; Additional Library Directories</em></li>\r\n	<li>Add <code>afcpu.lib</code> or <code>afcuda.lib</code> or <code>afopencl.lib</code> to <em>Project Properties -&gt; Linker -&gt; Input -&gt; Additional Dependencies</em> based on your preferred backend.</li>\r\n	<li>(Optional) You may choose to define <code>NOMINMAX</code>, <code>AF_CUDA</code> and/or <code>AF_&lt;DEBUG/RELEASE&gt;</code> in your projects. This can be added to <em>Project Properties -&gt; C/C++ -&gt; General -&gt; Preprocessor-&gt; Preprocessory definitions</em>.</li>\r\n	<li>Pick a solution to handle the NVVM DLLs. We recommend the post build event method used in <a href=\"#s3partA\">Part A</a>.</li>\r\n</ol>\r\n<h3><a id=\"s3partC\" class=\"anchor\"></a>Part C: Project with all ArrayFire backends</h3>\r\nIf you wish to create a project that allows you to use all the ArrayFire backends with ease, the best way to go is to copy the <em>HelloWorld sln/vcxproj/cpp</em> file trio and rename them to suit your project.\r\n\r\nAll the ArrayFire examples are pre-configured for all ArrayFire backends as well as the Unified API. These can be chosen from the Solution/Platform configuration drop down boxes.\r\n\r\nYou can alternately download the template project from the <a href=\"https://github.com/shehzan10/AF_VS2013\">ArrayFire VS 2013 Template Projects</a>\r\n<h3><a id=\"s3partD\" class=\"anchor\"></a>Part D: ArrayFire with CMake</h3>\r\n<em>NOTE:</em> The ArrayFire installer sets up CMake file and registry so that it can be found by CMake by simply using the <code>Find_PACKAGE(ArrayFire)</code> command.\r\n\r\nIf you are writing a new ArrayFire project in C/C++ from scratch, we suggest you grab a copy of our <a href=\"https://github.com/bkloppenborg/arrayfire-cmake-example\">CMake Project Example</a>; however, it is useful to read the documentation below in case you need to add ArrayFire to an existing project.\r\n\r\nAs <a href=\"#big-picture\">discussed above</a>, ArrayFire ships with a series of CMake scripts to make finding and using our library easy. The scripts will automatically find all versions of the ArrayFire library and pick the most powerful of the installed backends (typically CUDA).\r\n\r\nFirst create a file called <code>CMakeLists.txt</code> in your project directory:\r\n<pre class=\"fragment\">cd your-project-directory\r\ntouch CMakeLists.txt\r\n</pre>\r\nand populate it with the following code:\r\n<pre class=\"fragment\">FIND_PACKAGE(ArrayFire)\r\nINCLUDE_DIRECTORIES(${ArrayFire_INCLUDE_DIRS})\r\n\r\n... [gather source files, etc.]\r\n\r\n# If you intend to use OpenCL, you need to find it\r\nFIND_PACKAGE(OpenCL)\r\nSET(EXTRA_LIBS ${CMAKE_THREAD_LIBS_INIT} ${OpenCL_LIBRARIES})\r\n\r\n# Or if you intend to use CUDA, you need it as well as NVVM:\r\nFIND_PACKAGE(CUDA)\r\nFIND_PACKAGE(NVVM) # this FIND script can be found in the ArrayFire CMake example repository\r\nSET(EXTRA_LIBS ${CMAKE_THREAD_LIBS_INIT} ${CUDA_LIBRARIES} ${NVVM_LIB})\r\n\r\nADD_EXECUTABLE(my_executable [list your source files here])\r\nTARGET_LINK_LIBRARIES(my_executable ${ArrayFire_LIBRARIES} ${EXTRA_LIBS})\r\n</pre>\r\nwhere <code>my_executable</code> is the name of the executable you wish to create. See the <a href=\"https://cmake.org/documentation/\">CMake documentation</a> for more information on how to use CMake. Clearly the above code snippet precludes the use of both CUDA and OpenCL, see the <a href=\"https://github.com/bkloppenborg/arrayfire-cmake-example\">ArrayFire CMake Example</a> for an example of how to build executables for both backends from the same CMake script.\r\n\r\nIn the above code listing, the <code>FIND_PACKAGE</code> will find the ArrayFire include files, libraries, and define several variables including:\r\n<pre class=\"fragment\">ArrayFire_INCLUDE_DIRS    - Location of ArrayFire\'s include directory.\r\nArrayFire_LIBRARIES       - Location of ArrayFire\'s libraries.\r\n                            This will default to a GPU backend if one\r\n                            is found\r\nArrayFire_FOUND           - True if ArrayFire has been located\r\n</pre>\r\nIf you wish to use a specific backend, the find script also defines these variables:\r\n<pre class=\"fragment\">ArrayFire_CPU_FOUND         - True of the ArrayFire CPU library has been found.\r\nArrayFire_CPU_LIBRARIES     - Location of ArrayFire\'s CPU library, if found\r\nArrayFire_CUDA_FOUND        - True of the ArrayFire CUDA library has been found.\r\nArrayFire_CUDA_LIBRARIES    - Location of ArrayFire\'s CUDA library, if found\r\nArrayFire_OpenCL_FOUND      - True of the ArrayFire OpenCL library has been found.\r\nArrayFire_OpenCL_LIBRARIES  - Location of ArrayFire\'s OpenCL library, if found\r\nArrayFire_Unified_FOUND     - True of the ArrayFire Unified library has been found.\r\nArrayFire_Unified_LIBRARIES - Location of ArrayFire\'s Unified library, if found\r\n</pre>\r\nTherefore, if you wish to target a specific specific backend, simply replace <code>${ArrayFire_LIBRARIES}</code> with <code>${ArrayFire_CPU}</code>, <code>${ArrayFire_OPENCL}</code>, <code>${ArrayFire_CUDA}</code>, or <code>${ArrayFire_Unified}</code> in the <code>TARGET_LINK_LIBRARIES</code> command above.\r\n\r\nNext we need to instruct CMake to create build instructions and then compile. We suggest using CMake\'s out-of-source build functionality to keep your build and source files cleanly separated. To do this open the CMake GUI.\r\n<ul>\r\n	<li>Under source directory, add the path to your project</li>\r\n	<li>Under build directory, add the path to your project and append /build</li>\r\n	<li>Click configure and choose Visual Studio 2013 Win 64 as the generator.</li>\r\n	<li>If configuration was successful, click generate. This will create a my-project.sln file under build. You can open this in Visual Studio and compile the ALL_BUILD project.</li>\r\n</ul>\r\nThe <a href=\"https://github.com/bkloppenborg/arrayfire-cmake-example\">ArrayFire CMake Example</a> is a CMake project used to demo how ArrayFire can be using with a CMake project.\r\n\r\nNote: The CMake project does not add the post build event to copy the NVVM DLLs in case of CUDA backend. You will need to either copy it manually to the exectuable directory, or pick another solution for it.\r\n\r\n</div>\r\n</div>\r\n</div>\r\n</div>\r\n</div>','Setting up an ArrayFire project on Windows','','inherit','open','closed','','8546-revision-v1','','','2015-11-02 23:25:23','2015-11-02 23:25:23','',8546,'http://sandbox.arrayfire.com/8546-revision-v1/',0,'revision','',0),(8577,18528,'2015-11-02 23:27:09','2015-11-02 23:27:09','Continuing our blog series \"<a href=\"http://sandbox.arrayfire.com/tag/learning-arrayfire-from-scratch/\">Learning ArrayFire from scratch</a>\" today we will discuss how to set up an ArrayFire project on Linux using CMake or standard makefiles.\r\n\r\n<!--more-->\r\n\r\nIf you have not already done so, please make sure you have installed, configured, and tested ArrayFire following the <a class=\"el\" href=\"installing.htm\">installation instructions</a>.\r\n<h4>The big picture</h4>\r\nThe ArrayFire Windows installer installs the following:\r\n<ol type=\"1\">\r\n	<li>Creates <code>AF_PATH</code> environment variable to point to the installation location.</li>\r\n	<li><code>AF_PATH/include</code> : Header files for ArrayFire (Include Dir)</li>\r\n	<li><code>AF_PATH/lib</code> : All ArrayFire backends libraries, dlls and dependency dlls (Library dir)</li>\r\n	<li><code>AF_PATH/examples</code> : Examples to get started. Some examples also have pre-built exectuables</li>\r\n	<li><code>AF_PATH/cmake</code> : CMake config files for automatic configuration of external projects</li>\r\n	<li><code>AF_PATH/uninstall.exe</code> : Uninstaller</li>\r\n	<li><code>AF_PATH/*</code> : Other miscellenous files including licenses, logos, copyrights</li>\r\n</ol>\r\nThe installer also appends <code>%AF_PATH%/lib</code> to the User PATH variable. See <a href=\"#step1\">step 1</a> for more.\r\n\r\nTo add <code>%AF_PATH%/lib</code> to PATH for all users see the windows section in <a class=\"el\" href=\"installing.htm\">installation instructions</a>.\r\n<h5>Dealing with CUDA NMMV DLLs</h5>\r\nThe NVVM DLLs are not a part of the standard <code>CUDA_PATH\\bin</code> directory which is added to PATH at the time of CUDA installation. Hence it is not found automatically by the system dll loading operation. There are a few ways to deal with this:\r\n<ol type=\"1\">\r\n	<li>Copy the DLLs to the exectuable location. This is the solution ArrayFire\'s examples use. The DLL ios copied to the executable location as a post build event. The stes for this are shown under <a href=\"#s3partA\">Step 3 - Part A</a>.</li>\r\n	<li>Copy <code>CUDA_PATH\\nvvm\\bin\\nvvm64_30_0.dll</code> to <code>CUDA_PATH\\bin</code>. This is a one time copy such that the NVVM DLL is now with all the other CUDA dlls and in a directory that is a part of PATH and hence the DLL can be detected automatically.</li>\r\n	<li>Add <code>%CUDA_PATH%\\nvvm\\bin</code> to the system PATH environment variable. This will allow automatic detection by the system and No further copying will be required. ArrayFire does not add this to PATH since the CUDA installer doesn\'t add it to PATH.</li>\r\n</ol>\r\n<h4>Step 1: Running pre-built executables</h4>\r\nThe ArrayFire installer ships with a few pre-built executables with the examples. These should run out of the box when double clicked.\r\n\r\nSome prebuilt examples are:\r\n<ul>\r\n	<li>Helloworld (examples/helloworld)</li>\r\n	<li>BLAS (examples/benchmarks)</li>\r\n	<li>FFT (examples/benchmarks)</li>\r\n	<li>Pi Estimation (examples/benchmarks)</li>\r\n	<li>Conway (Graphics) (examples/graphics)</li>\r\n</ul>\r\nNote: For the CUDA executables, you will need to copy <code>CUDA_PATH\\nvvm\\bin\\nvvm64_30_0.dll</code> to the location of the executables.\r\n<h4>Step 2: Build and Run a Project</h4>\r\n<ol type=\"1\">\r\n	<li>Open Visual Studio 2013. Open the HelloWorld solution which is located at <code>AF_PATH/examples/helloworld/helloworld.sln</code>.</li>\r\n	<li>Build the <code>helloworld</code> example. Be sure to, select the platform/configuration of your choice using the platform drop-down (the options are CPU, CUDA, OpenCL, and Unified) and Solution Configuration drop down (options of Release and Debug) menus.</li>\r\n	<li>Run the <code>helloworld</code> example</li>\r\n</ol>\r\n<h4>Step 3: Using ArrayFire with Visual Studio</h4>\r\nThis is divided into 4 parts:\r\n<ul>\r\n	<li><a href=\"#s3partA\">Part A: Adding ArrayFire to an existing solution (Single Backend)</a></li>\r\n	<li><a href=\"#s3partB\">Part B: Adding ArrayFire CUDA to a new/existing CUDA project</a></li>\r\n	<li><a href=\"#s3partC\">Part C: Project with all ArrayFire backends</a></li>\r\n	<li><a href=\"#s3partD\">Part D: ArrayFire with CMake</a></li>\r\n</ul>\r\n<h4>Part A: Adding ArrayFire to an existing solution (Single Backend)</h4>\r\nNote: If you plan on using Native CUDA code in the project, use the steps under <a href=\"#s3partB\">Part B</a>. Adding a single backend to an existing project is quite simple.\r\n<ol type=\"1\">\r\n	<li>Add <code>\"$(AF_PATH)/include;\"</code> to <em>Project Properties -&gt; C/C++ -&gt; General -&gt; Additional Include Directories</em></li>\r\n	<li>Add <code>\"$(AF_PATH)/lib;\"</code> to <em>Project Properties -&gt; Linker -&gt; General -&gt; Additional Library Directories</em></li>\r\n	<li>Add <code>afcpu.lib</code> or <code>afcuda.lib</code> or <code>afopencl.lib</code> to <em>Project Properties -&gt; Linker -&gt; Input -&gt; Additional Dependencies</em> based on your preferred backend.</li>\r\n	<li>(Optional) You may choose to define <code>NOMINMAX</code>, <code>AF_&lt;CPU/CUDA/OPENCL&gt;</code> and/or <code>AF_&lt;DEBUG/RELEASE&gt;</code> in your projects. This can be added to <em>Project Properties -&gt; C/C++ -&gt; General -&gt; Preprocessor-&gt; Preprocessory definitions</em>.</li>\r\n</ol>\r\nIf you are using the CUDA backend, it is important to ensure that the CUDA NVVM DLLs are copied to the exectuable directory. This can be done by adding a post build event.\r\n\r\nOpen the <em>Project Properties -&gt; Build Events -&gt; Post Build Events</em> dialog and add the following lines to it.\r\n<div class=\"fragment\">\r\n<div class=\"line\">echo <a class=\"code\" href=\"group__index__func__index.htm#ga25f470817062b23ad3f74347ea44b17c\">copy</a> <span class=\"stringliteral\">\"$(CUDA_PATH)\\nvvm\\bin\\nvvm64*.dll\"</span> <span class=\"stringliteral\">\"$(OutDir)\"</span></div>\r\n<div class=\"line\"><a class=\"code\" href=\"group__index__func__index.htm#ga25f470817062b23ad3f74347ea44b17c\">copy</a> <span class=\"stringliteral\">\"$(CUDA_PATH)\\nvvm\\bin\\nvvm64*.dll\"</span> <span class=\"stringliteral\">\"$(OutDir)\"</span></div>\r\n</div>\r\n<h4>Part B: Adding ArrayFire CUDA to a new/existing CUDA project</h4>\r\nLastly, if your project contains custom CUDA code, the instructions are slightly different as it requires using a CUDA NVCC Project:\r\n<ol type=\"1\">\r\n	<li>Create a custom \"CUDA NVCC project\" in Visual Studio</li>\r\n	<li>Add <code>\"$(AF_PATH)/include;\"</code> to <em>Project Properties -&gt; CUDA C/C++ -&gt; General -&gt; Additional Include Directories</em></li>\r\n	<li>Add <code>\"$(AF_PATH)/lib;\"</code> to <em>Project Properties -&gt; Linker -&gt; General -&gt; Additional Library Directories</em></li>\r\n	<li>Add <code>afcpu.lib</code> or <code>afcuda.lib</code> or <code>afopencl.lib</code> to <em>Project Properties -&gt; Linker -&gt; Input -&gt; Additional Dependencies</em> based on your preferred backend.</li>\r\n	<li>(Optional) You may choose to define <code>NOMINMAX</code>, <code>AF_CUDA</code> and/or <code>AF_&lt;DEBUG/RELEASE&gt;</code> in your projects. This can be added to <em>Project Properties -&gt; C/C++ -&gt; General -&gt; Preprocessor-&gt; Preprocessory definitions</em>.</li>\r\n	<li>Pick a solution to handle the NVVM DLLs. We recommend the post build event method used in <a href=\"#s3partA\">Part A</a>.</li>\r\n</ol>\r\n<h4>Part C: Project with all ArrayFire backends</h4>\r\nIf you wish to create a project that allows you to use all the ArrayFire backends with ease, the best way to go is to copy the <em>HelloWorld sln/vcxproj/cpp</em> file trio and rename them to suit your project.\r\n\r\nAll the ArrayFire examples are pre-configured for all ArrayFire backends as well as the Unified API. These can be chosen from the Solution/Platform configuration drop down boxes.\r\n\r\nYou can alternately download the template project from the <a href=\"https://github.com/shehzan10/AF_VS2013\">ArrayFire VS 2013 Template Projects</a>\r\n<h4>Part D: ArrayFire with CMake</h4>\r\n<em>NOTE:</em> The ArrayFire installer sets up CMake file and registry so that it can be found by CMake by simply using the <code>Find_PACKAGE(ArrayFire)</code> command.\r\n\r\nIf you are writing a new ArrayFire project in C/C++ from scratch, we suggest you grab a copy of our <a href=\"https://github.com/bkloppenborg/arrayfire-cmake-example\">CMake Project Example</a>; however, it is useful to read the documentation below in case you need to add ArrayFire to an existing project.\r\n\r\nAs <a href=\"#big-picture\">discussed above</a>, ArrayFire ships with a series of CMake scripts to make finding and using our library easy. The scripts will automatically find all versions of the ArrayFire library and pick the most powerful of the installed backends (typically CUDA).\r\n\r\nFirst create a file called <code>CMakeLists.txt</code> in your project directory:\r\n<pre class=\"fragment\">cd your-project-directory\r\ntouch CMakeLists.txt\r\n</pre>\r\nand populate it with the following code:\r\n<pre class=\"fragment\">FIND_PACKAGE(ArrayFire)\r\nINCLUDE_DIRECTORIES(${ArrayFire_INCLUDE_DIRS})\r\n\r\n... [gather source files, etc.]\r\n\r\n# If you intend to use OpenCL, you need to find it\r\nFIND_PACKAGE(OpenCL)\r\nSET(EXTRA_LIBS ${CMAKE_THREAD_LIBS_INIT} ${OpenCL_LIBRARIES})\r\n\r\n# Or if you intend to use CUDA, you need it as well as NVVM:\r\nFIND_PACKAGE(CUDA)\r\nFIND_PACKAGE(NVVM) # this FIND script can be found in the ArrayFire CMake example repository\r\nSET(EXTRA_LIBS ${CMAKE_THREAD_LIBS_INIT} ${CUDA_LIBRARIES} ${NVVM_LIB})\r\n\r\nADD_EXECUTABLE(my_executable [list your source files here])\r\nTARGET_LINK_LIBRARIES(my_executable ${ArrayFire_LIBRARIES} ${EXTRA_LIBS})\r\n</pre>\r\nwhere <span class=\"lang:default decode:true  crayon-inline \">my_executable</span>  is the name of the executable you wish to create. See the <a href=\"https://cmake.org/documentation/\">CMake documentation</a> for more information on how to use CMake. Clearly the above code snippet precludes the use of both CUDA and OpenCL, see the <a href=\"https://github.com/bkloppenborg/arrayfire-cmake-example\">ArrayFire CMake Example</a> for an example of how to build executables for both backends from the same CMake script.\r\n\r\nIn the above code listing, the <span class=\"lang:default decode:true  crayon-inline \">FIND_PACKAGE</span>  will find the ArrayFire include files, libraries, and define several variables including:\r\n<pre class=\"fragment\">ArrayFire_INCLUDE_DIRS    - Location of ArrayFire\'s include directory.\r\nArrayFire_LIBRARIES       - Location of ArrayFire\'s libraries.\r\n                            This will default to a GPU backend if one\r\n                            is found\r\nArrayFire_FOUND           - True if ArrayFire has been located\r\n</pre>\r\nIf you wish to use a specific backend, the find script also defines these variables:\r\n<pre class=\"fragment\">ArrayFire_CPU_FOUND         - True of the ArrayFire CPU library has been found.\r\nArrayFire_CPU_LIBRARIES     - Location of ArrayFire\'s CPU library, if found\r\nArrayFire_CUDA_FOUND        - True of the ArrayFire CUDA library has been found.\r\nArrayFire_CUDA_LIBRARIES    - Location of ArrayFire\'s CUDA library, if found\r\nArrayFire_OpenCL_FOUND      - True of the ArrayFire OpenCL library has been found.\r\nArrayFire_OpenCL_LIBRARIES  - Location of ArrayFire\'s OpenCL library, if found\r\nArrayFire_Unified_FOUND     - True of the ArrayFire Unified library has been found.\r\nArrayFire_Unified_LIBRARIES - Location of ArrayFire\'s Unified library, if found\r\n</pre>\r\nTherefore, if you wish to target a specific specific backend, simply replace <code>${ArrayFire_LIBRARIES}</code> with <code>${ArrayFire_CPU}</code>, <code>${ArrayFire_OPENCL}</code>, <code>${ArrayFire_CUDA}</code>, or <code>${ArrayFire_Unified}</code> in the <code>TARGET_LINK_LIBRARIES</code> command above.\r\n\r\nNext we need to instruct CMake to create build instructions and then compile. We suggest using CMake\'s out-of-source build functionality to keep your build and source files cleanly separated. To do this open the CMake GUI.\r\n<ul>\r\n	<li>Under source directory, add the path to your project</li>\r\n	<li>Under build directory, add the path to your project and append /build</li>\r\n	<li>Click configure and choose Visual Studio 2013 Win 64 as the generator.</li>\r\n	<li>If configuration was successful, click generate. This will create a my-project.sln file under build. You can open this in Visual Studio and compile the ALL_BUILD project.</li>\r\n</ul>\r\nThe <a href=\"https://github.com/bkloppenborg/arrayfire-cmake-example\">ArrayFire CMake Example</a> is a CMake project used to demo how ArrayFire can be using with a CMake project.\r\n\r\nNote: The CMake project does not add the post build event to copy the NVVM DLLs in case of CUDA backend. You will need to either copy it manually to the exectuable directory, or pick another solution for it.','Setting up an ArrayFire project on Windows','','inherit','open','closed','','8546-revision-v1','','','2015-11-02 23:27:09','2015-11-02 23:27:09','',8546,'http://sandbox.arrayfire.com/8546-revision-v1/',0,'revision','',0),(8578,18528,'2015-11-02 23:27:51','2015-11-02 23:27:51','Continuing our blog series \"<a href=\"http://sandbox.arrayfire.com/tag/learning-arrayfire-from-scratch/\">Learning ArrayFire from scratch</a>\" today we will discuss how to set up an ArrayFire project on Windows using either Visual Studio or CMake as a build system.\r\n\r\n<!--more-->\r\n\r\nIf you have not already done so, please make sure you have installed, configured, and tested ArrayFire following the <a class=\"el\" href=\"installing.htm\">installation instructions</a>.\r\n<h4>The big picture</h4>\r\nThe ArrayFire Windows installer installs the following:\r\n<ol type=\"1\">\r\n	<li>Creates <code>AF_PATH</code> environment variable to point to the installation location.</li>\r\n	<li><code>AF_PATH/include</code> : Header files for ArrayFire (Include Dir)</li>\r\n	<li><code>AF_PATH/lib</code> : All ArrayFire backends libraries, dlls and dependency dlls (Library dir)</li>\r\n	<li><code>AF_PATH/examples</code> : Examples to get started. Some examples also have pre-built exectuables</li>\r\n	<li><code>AF_PATH/cmake</code> : CMake config files for automatic configuration of external projects</li>\r\n	<li><code>AF_PATH/uninstall.exe</code> : Uninstaller</li>\r\n	<li><code>AF_PATH/*</code> : Other miscellenous files including licenses, logos, copyrights</li>\r\n</ol>\r\nThe installer also appends <code>%AF_PATH%/lib</code> to the User PATH variable. See <a href=\"#step1\">step 1</a> for more.\r\n\r\nTo add <code>%AF_PATH%/lib</code> to PATH for all users see the windows section in <a class=\"el\" href=\"installing.htm\">installation instructions</a>.\r\n<h5>Dealing with CUDA NMMV DLLs</h5>\r\nThe NVVM DLLs are not a part of the standard <code>CUDA_PATH\\bin</code> directory which is added to PATH at the time of CUDA installation. Hence it is not found automatically by the system dll loading operation. There are a few ways to deal with this:\r\n<ol type=\"1\">\r\n	<li>Copy the DLLs to the exectuable location. This is the solution ArrayFire\'s examples use. The DLL ios copied to the executable location as a post build event. The stes for this are shown under <a href=\"#s3partA\">Step 3 - Part A</a>.</li>\r\n	<li>Copy <code>CUDA_PATH\\nvvm\\bin\\nvvm64_30_0.dll</code> to <code>CUDA_PATH\\bin</code>. This is a one time copy such that the NVVM DLL is now with all the other CUDA dlls and in a directory that is a part of PATH and hence the DLL can be detected automatically.</li>\r\n	<li>Add <code>%CUDA_PATH%\\nvvm\\bin</code> to the system PATH environment variable. This will allow automatic detection by the system and No further copying will be required. ArrayFire does not add this to PATH since the CUDA installer doesn\'t add it to PATH.</li>\r\n</ol>\r\n<h4>Step 1: Running pre-built executables</h4>\r\nThe ArrayFire installer ships with a few pre-built executables with the examples. These should run out of the box when double clicked.\r\n\r\nSome prebuilt examples are:\r\n<ul>\r\n	<li>Helloworld (examples/helloworld)</li>\r\n	<li>BLAS (examples/benchmarks)</li>\r\n	<li>FFT (examples/benchmarks)</li>\r\n	<li>Pi Estimation (examples/benchmarks)</li>\r\n	<li>Conway (Graphics) (examples/graphics)</li>\r\n</ul>\r\nNote: For the CUDA executables, you will need to copy <code>CUDA_PATH\\nvvm\\bin\\nvvm64_30_0.dll</code> to the location of the executables.\r\n<h4>Step 2: Build and Run a Project</h4>\r\n<ol type=\"1\">\r\n	<li>Open Visual Studio 2013. Open the HelloWorld solution which is located at <code>AF_PATH/examples/helloworld/helloworld.sln</code>.</li>\r\n	<li>Build the <code>helloworld</code> example. Be sure to, select the platform/configuration of your choice using the platform drop-down (the options are CPU, CUDA, OpenCL, and Unified) and Solution Configuration drop down (options of Release and Debug) menus.</li>\r\n	<li>Run the <code>helloworld</code> example</li>\r\n</ol>\r\n<h4>Step 3: Using ArrayFire with Visual Studio</h4>\r\nThis is divided into 4 parts:\r\n<ul>\r\n	<li><a href=\"#s3partA\">Part A: Adding ArrayFire to an existing solution (Single Backend)</a></li>\r\n	<li><a href=\"#s3partB\">Part B: Adding ArrayFire CUDA to a new/existing CUDA project</a></li>\r\n	<li><a href=\"#s3partC\">Part C: Project with all ArrayFire backends</a></li>\r\n	<li><a href=\"#s3partD\">Part D: ArrayFire with CMake</a></li>\r\n</ul>\r\n<h4>Part A: Adding ArrayFire to an existing solution (Single Backend)</h4>\r\nNote: If you plan on using Native CUDA code in the project, use the steps under <a href=\"#s3partB\">Part B</a>. Adding a single backend to an existing project is quite simple.\r\n<ol type=\"1\">\r\n	<li>Add <code>\"$(AF_PATH)/include;\"</code> to <em>Project Properties -&gt; C/C++ -&gt; General -&gt; Additional Include Directories</em></li>\r\n	<li>Add <code>\"$(AF_PATH)/lib;\"</code> to <em>Project Properties -&gt; Linker -&gt; General -&gt; Additional Library Directories</em></li>\r\n	<li>Add <code>afcpu.lib</code> or <code>afcuda.lib</code> or <code>afopencl.lib</code> to <em>Project Properties -&gt; Linker -&gt; Input -&gt; Additional Dependencies</em> based on your preferred backend.</li>\r\n	<li>(Optional) You may choose to define <code>NOMINMAX</code>, <code>AF_&lt;CPU/CUDA/OPENCL&gt;</code> and/or <code>AF_&lt;DEBUG/RELEASE&gt;</code> in your projects. This can be added to <em>Project Properties -&gt; C/C++ -&gt; General -&gt; Preprocessor-&gt; Preprocessory definitions</em>.</li>\r\n</ol>\r\nIf you are using the CUDA backend, it is important to ensure that the CUDA NVVM DLLs are copied to the exectuable directory. This can be done by adding a post build event.\r\n\r\nOpen the <em>Project Properties -&gt; Build Events -&gt; Post Build Events</em> dialog and add the following lines to it.\r\n<div class=\"fragment\">\r\n<div class=\"line\">echo <a class=\"code\" href=\"group__index__func__index.htm#ga25f470817062b23ad3f74347ea44b17c\">copy</a> <span class=\"stringliteral\">\"$(CUDA_PATH)\\nvvm\\bin\\nvvm64*.dll\"</span> <span class=\"stringliteral\">\"$(OutDir)\"</span></div>\r\n<div class=\"line\"><a class=\"code\" href=\"group__index__func__index.htm#ga25f470817062b23ad3f74347ea44b17c\">copy</a> <span class=\"stringliteral\">\"$(CUDA_PATH)\\nvvm\\bin\\nvvm64*.dll\"</span> <span class=\"stringliteral\">\"$(OutDir)\"</span></div>\r\n</div>\r\n<h4>Part B: Adding ArrayFire CUDA to a new/existing CUDA project</h4>\r\nLastly, if your project contains custom CUDA code, the instructions are slightly different as it requires using a CUDA NVCC Project:\r\n<ol type=\"1\">\r\n	<li>Create a custom \"CUDA NVCC project\" in Visual Studio</li>\r\n	<li>Add <code>\"$(AF_PATH)/include;\"</code> to <em>Project Properties -&gt; CUDA C/C++ -&gt; General -&gt; Additional Include Directories</em></li>\r\n	<li>Add <code>\"$(AF_PATH)/lib;\"</code> to <em>Project Properties -&gt; Linker -&gt; General -&gt; Additional Library Directories</em></li>\r\n	<li>Add <code>afcpu.lib</code> or <code>afcuda.lib</code> or <code>afopencl.lib</code> to <em>Project Properties -&gt; Linker -&gt; Input -&gt; Additional Dependencies</em> based on your preferred backend.</li>\r\n	<li>(Optional) You may choose to define <code>NOMINMAX</code>, <code>AF_CUDA</code> and/or <code>AF_&lt;DEBUG/RELEASE&gt;</code> in your projects. This can be added to <em>Project Properties -&gt; C/C++ -&gt; General -&gt; Preprocessor-&gt; Preprocessory definitions</em>.</li>\r\n	<li>Pick a solution to handle the NVVM DLLs. We recommend the post build event method used in <a href=\"#s3partA\">Part A</a>.</li>\r\n</ol>\r\n<h4>Part C: Project with all ArrayFire backends</h4>\r\nIf you wish to create a project that allows you to use all the ArrayFire backends with ease, the best way to go is to copy the <em>HelloWorld sln/vcxproj/cpp</em> file trio and rename them to suit your project.\r\n\r\nAll the ArrayFire examples are pre-configured for all ArrayFire backends as well as the Unified API. These can be chosen from the Solution/Platform configuration drop down boxes.\r\n\r\nYou can alternately download the template project from the <a href=\"https://github.com/shehzan10/AF_VS2013\">ArrayFire VS 2013 Template Projects</a>\r\n<h4>Part D: ArrayFire with CMake</h4>\r\n<em>NOTE:</em> The ArrayFire installer sets up CMake file and registry so that it can be found by CMake by simply using the <code>Find_PACKAGE(ArrayFire)</code> command.\r\n\r\nIf you are writing a new ArrayFire project in C/C++ from scratch, we suggest you grab a copy of our <a href=\"https://github.com/bkloppenborg/arrayfire-cmake-example\">CMake Project Example</a>; however, it is useful to read the documentation below in case you need to add ArrayFire to an existing project.\r\n\r\nAs <a href=\"#big-picture\">discussed above</a>, ArrayFire ships with a series of CMake scripts to make finding and using our library easy. The scripts will automatically find all versions of the ArrayFire library and pick the most powerful of the installed backends (typically CUDA).\r\n\r\nFirst create a file called <code>CMakeLists.txt</code> in your project directory:\r\n<pre class=\"fragment\">cd your-project-directory\r\ntouch CMakeLists.txt\r\n</pre>\r\nand populate it with the following code:\r\n<pre class=\"fragment\">FIND_PACKAGE(ArrayFire)\r\nINCLUDE_DIRECTORIES(${ArrayFire_INCLUDE_DIRS})\r\n\r\n... [gather source files, etc.]\r\n\r\n# If you intend to use OpenCL, you need to find it\r\nFIND_PACKAGE(OpenCL)\r\nSET(EXTRA_LIBS ${CMAKE_THREAD_LIBS_INIT} ${OpenCL_LIBRARIES})\r\n\r\n# Or if you intend to use CUDA, you need it as well as NVVM:\r\nFIND_PACKAGE(CUDA)\r\nFIND_PACKAGE(NVVM) # this FIND script can be found in the ArrayFire CMake example repository\r\nSET(EXTRA_LIBS ${CMAKE_THREAD_LIBS_INIT} ${CUDA_LIBRARIES} ${NVVM_LIB})\r\n\r\nADD_EXECUTABLE(my_executable [list your source files here])\r\nTARGET_LINK_LIBRARIES(my_executable ${ArrayFire_LIBRARIES} ${EXTRA_LIBS})\r\n</pre>\r\nwhere <span class=\"lang:default decode:true  crayon-inline \">my_executable</span>  is the name of the executable you wish to create. See the <a href=\"https://cmake.org/documentation/\">CMake documentation</a> for more information on how to use CMake. Clearly the above code snippet precludes the use of both CUDA and OpenCL, see the <a href=\"https://github.com/bkloppenborg/arrayfire-cmake-example\">ArrayFire CMake Example</a> for an example of how to build executables for both backends from the same CMake script.\r\n\r\nIn the above code listing, the <span class=\"lang:default decode:true  crayon-inline \">FIND_PACKAGE</span>  will find the ArrayFire include files, libraries, and define several variables including:\r\n<pre class=\"fragment\">ArrayFire_INCLUDE_DIRS    - Location of ArrayFire\'s include directory.\r\nArrayFire_LIBRARIES       - Location of ArrayFire\'s libraries.\r\n                            This will default to a GPU backend if one\r\n                            is found\r\nArrayFire_FOUND           - True if ArrayFire has been located\r\n</pre>\r\nIf you wish to use a specific backend, the find script also defines these variables:\r\n<pre class=\"fragment\">ArrayFire_CPU_FOUND         - True of the ArrayFire CPU library has been found.\r\nArrayFire_CPU_LIBRARIES     - Location of ArrayFire\'s CPU library, if found\r\nArrayFire_CUDA_FOUND        - True of the ArrayFire CUDA library has been found.\r\nArrayFire_CUDA_LIBRARIES    - Location of ArrayFire\'s CUDA library, if found\r\nArrayFire_OpenCL_FOUND      - True of the ArrayFire OpenCL library has been found.\r\nArrayFire_OpenCL_LIBRARIES  - Location of ArrayFire\'s OpenCL library, if found\r\nArrayFire_Unified_FOUND     - True of the ArrayFire Unified library has been found.\r\nArrayFire_Unified_LIBRARIES - Location of ArrayFire\'s Unified library, if found\r\n</pre>\r\nTherefore, if you wish to target a specific specific backend, simply replace <code>${ArrayFire_LIBRARIES}</code> with <code>${ArrayFire_CPU}</code>, <code>${ArrayFire_OPENCL}</code>, <code>${ArrayFire_CUDA}</code>, or <code>${ArrayFire_Unified}</code> in the <code>TARGET_LINK_LIBRARIES</code> command above.\r\n\r\nNext we need to instruct CMake to create build instructions and then compile. We suggest using CMake\'s out-of-source build functionality to keep your build and source files cleanly separated. To do this open the CMake GUI.\r\n<ul>\r\n	<li>Under source directory, add the path to your project</li>\r\n	<li>Under build directory, add the path to your project and append /build</li>\r\n	<li>Click configure and choose Visual Studio 2013 Win 64 as the generator.</li>\r\n	<li>If configuration was successful, click generate. This will create a my-project.sln file under build. You can open this in Visual Studio and compile the ALL_BUILD project.</li>\r\n</ul>\r\nThe <a href=\"https://github.com/bkloppenborg/arrayfire-cmake-example\">ArrayFire CMake Example</a> is a CMake project used to demo how ArrayFire can be using with a CMake project.\r\n\r\nNote: The CMake project does not add the post build event to copy the NVVM DLLs in case of CUDA backend. You will need to either copy it manually to the exectuable directory, or pick another solution for it.','Setting up an ArrayFire project on Windows','','inherit','open','closed','','8546-revision-v1','','','2015-11-02 23:27:51','2015-11-02 23:27:51','',8546,'http://sandbox.arrayfire.com/8546-revision-v1/',0,'revision','',0),(8579,11,'2015-11-06 14:30:58','2015-11-06 14:30:58','<div class=\"header\">\n<div class=\"headertitle\">\n<div class=\"title\">Continuing our blog series \"<a href=\"http://sandbox.arrayfire.com/tag/learning-arrayfire-from-scratch/\">Learning ArrayFire from scratch</a>\" today we will discuss how to set up an ArrayFire project on Windows using Visual Studio or CMake.</div>\n</div>\n</div>\n<!--more-->\n\nIf you have not already done so, please make sure you have installed, configured, and tested ArrayFire following the <a class=\"el\" href=\"installing.htm\">installation instructions</a>.\n<div class=\"contents\">\n<div class=\"textblock\">\n<h3>The big picture</h3>\nThe ArrayFire Windows installer creates the following:\n<pre class=\"lang:default decode:true\">AF_PATH                 Environment variable to point to the installation location.\n                        This is normally C:/Program Files/ArrayFire/v*\nAF_PATH/include         Header files for ArrayFire (Include Dir)\nAF_PATH/lib             All ArrayFire backends libraries, dlls and dependency dlls \n                        (Library dir)\nAF_PATH/examples        Examples to get started. Some examples also have pre-built \n                        exectuables\nAF_PATH/cmake           CMake config files for automatic configuration by external \n                        projects\nAF_PATH/uninstall.exe   Uninstaller\nAF_PATH/*               Other miscellenous files including licenses, logos, copyrights</pre>\nThe installer also appends <span class=\"lang:default decode:true  crayon-inline \">%AF_PATH%/lib</span>  to the User <span class=\"lang:default decode:true  crayon-inline \">PATH</span>  variable (see the <a class=\"el\" href=\"installing.htm\">installation instructions</a> for further details).\n<h4>Dealing with CUDA NVVM DLLs</h4>\nWhen using CUDA with ArrayFire you may encounter a linker error indicating the NVVM DLLs are missing. This is because the NVVM DLLs are not part of the standard <span class=\"lang:default decode:true  crayon-inline \">CUDA_PATH\\bin</span>  installation directory that is added to your <span class=\"lang:default decode:true  crayon-inline \">PATH</span>  when the CUDA installer runs. Thus, NVVM will not be found during the linking stage. There are a few ways to deal with this issue:\n&nbsp;\n<ol type=\"1\">\n	<li>Copy the DLLs to the executable location. This is, by far, the cleanest solution and we recommend doing this with ArrayFire projects. To do so, create a post-build event to copy the NVVM DLL as discussed below in <a href=\"#s3partA\">Step 3 - Part A</a>.</li>\n	<li>Copy <span class=\"lang:default decode:true  crayon-inline\">CUDA_PATH\\nvvm\\bin\\nvvm64_30_0.dll</span>  to <span class=\"lang:default decode:true  crayon-inline \">CUDA_PATH\\bin</span> . This is a one time copy such that the NVVM DLL is now with all the other CUDA dlls and in a directory that is a part of PATH and hence the DLL can be detected automatically.</li>\n	<li>Add <span class=\"lang:default decode:true  crayon-inline \">%CUDA_PATH%\\nvvm\\bin</span>  to the system PATH environment variable. This will allow automatic detection by the system and No further copying will be required. ArrayFire does not add this to PATH since the CUDA installer doesn\'t add it to PATH.</li>\n</ol>\n<h3><a id=\"step1\" class=\"anchor\"></a>Step 1: Running pre-built executables</h3>\nThe ArrayFire installer ships with a few pre-built executables with the examples. These should run out of the box when double clicked.\n\nSome prebuilt examples are:\n<ul>\n	<li>Helloworld (examples/helloworld)</li>\n	<li>BLAS (examples/benchmarks)</li>\n	<li>FFT (examples/benchmarks)</li>\n	<li>Pi Estimation (examples/benchmarks)</li>\n	<li>Conway (Graphics) (examples/graphics)</li>\n</ul>\nNote: For the CUDA executables, you will need to copy <span class=\"lang:default decode:true  crayon-inline \">CUDA_PATH\\nvvm\\bin\\nvvm64_30_0.dll</span>  to the location of the executables.\n<h3><a id=\"step2\" class=\"anchor\"></a>Step 2: Build and Run a Project</h3>\n<ol type=\"1\">\n	<li>Open Visual Studio 2013. Load the HelloWorld solution which is located at <span class=\"lang:default decode:true  crayon-inline \">AF_PATH/examples/helloworld/helloworld.sln</span> .</li>\n	<li>Build the <span class=\"lang:default decode:true  crayon-inline \">helloworld</span>  example. Be sure to, select the platform/configuration of your choice using the platform drop-down (the options are CPU, CUDA, OpenCL, and Unified) and Solution Configuration drop down (options of Release and Debug) menus.</li>\n	<li>Run the <span class=\"lang:default decode:true  crayon-inline \">helloworld</span>  example.</li>\n</ol>\n<h3><a id=\"step3\" class=\"anchor\"></a>Step 3: Using ArrayFire within Visual Studio</h3>\nThis is divided into 4 parts:\n<ul>\n	<li><a href=\"#s3partA\">Part A: Adding ArrayFire to an existing solution (Single Backend)</a></li>\n	<li><a href=\"#s3partB\">Part B: Adding ArrayFire CUDA to a new/existing CUDA project</a></li>\n	<li><a href=\"#s3partC\">Part C: Project with all ArrayFire backends</a></li>\n	<li><a href=\"#s3partD\">Part D: ArrayFire with CMake</a></li>\n</ul>\n<h4><a id=\"s3partA\" class=\"anchor\"></a>Part A: Adding ArrayFire to an existing solution (Single Backend)</h4>\nNote: If you plan on using native CUDA code in the project, use the steps under <a href=\"#s3partB\">Part B</a>.\n\nAdding a single backend to an existing project is quite simple.\n<ol type=\"1\">\n	<li>Add <code>\"<span class=\"lang:default decode:true  crayon-inline \">$(AF_PATH)/include;</span> \"</code> to <em>Project Properties -&gt; C/C++ -&gt; General -&gt; Additional Include Directories</em>.</li>\n	<li>Add <code>\"<span class=\"lang:default decode:true  crayon-inline \">$(AF_PATH)/lib;</span> \"</code> to <em>Project Properties -&gt; Linker -&gt; General -&gt; Additional Library Directories</em>.</li>\n	<li>Add <span class=\"lang:default decode:true  crayon-inline \">afcpu.lib</span>  or <span class=\"lang:default decode:true  crayon-inline \">afcuda.lib</span>  or <span class=\"lang:default decode:true  crayon-inline \">afopencl.lib</span>  to <em>Project Properties -&gt; Linker -&gt; Input -&gt; Additional Dependencies</em>. based on your preferred backend.</li>\n	<li>(Optional) You may choose to define <span class=\"lang:default decode:true  crayon-inline \">NOMINMAX, AF_&lt;CPU/CUDA/OPENCL&gt;</span>  and/or <span class=\"lang:default decode:true  crayon-inline \">AF_&lt;DEBUG/RELEASE&gt;</span>  in your projects. This can be added to <em>Project Properties -&gt; C/C++ -&gt; General -&gt; Preprocessor-&gt; Preprocessory definitions</em>.</li>\n</ol>\nIf you are using the CUDA backend, it is important to ensure that the CUDA NVVM DLLs are copied to the exectuable directory. This can be done by adding a post build event.\n\nOpen the <em>Project Properties -&gt; Build Events -&gt; Post Build Events</em> dialog and add the following lines to it.\n<div class=\"fragment\">\n<pre class=\"lang:default decode:true\">echo copy \"$(CUDA_PATH)\\nvvm\\bin\\nvvm64*.dll\" \"$(OutDir)\" \necho copy \"$(CUDA_PATH)\\nvvm\\bin\\nvvm64*.dll\" \"$(OutDir)\"</pre>\n<h4 class=\"line\"> <a id=\"s3partB\" class=\"anchor\"></a>Part B: Adding ArrayFire CUDA to a new/existing CUDA project</h4>\n</div>\nIf your project contains custom CUDA code, the instructions are slightly different as it requires using a CUDA NVCC Project:\n<ol type=\"1\">\n	<li>Create a custom \"CUDA NVCC project\" in Visual Studio</li>\n	<li>Add <code>\"<span class=\"lang:default decode:true  crayon-inline \">$(AF_PATH)/include;</span> \"</code> to <em>Project Properties -&gt; CUDA C/C++ -&gt; General -&gt; Additional Include Directories</em>.</li>\n	<li>Add <code>\"<span class=\"lang:default decode:true  crayon-inline \">$(AF_PATH)/lib;</span> \"</code> to <em>Project Properties -&gt; Linker -&gt; General -&gt; Additional Library Directories</em>.</li>\n	<li>Add <span class=\"lang:default decode:true  crayon-inline \">afcpu.lib</span>  or <span class=\"lang:default decode:true  crayon-inline \">afcuda.lib</span>  or <span class=\"lang:default decode:true  crayon-inline \">afopencl.lib</span>  to <em>Project Properties -&gt; Linker -&gt; Input -&gt; Additional Dependencies</em>. based on your preferred backend.</li>\n	<li>(Optional) You may choose to define <span class=\"lang:default decode:true  crayon-inline \">NOMINMAX, AF_CUDA</span>  and/or <span class=\"lang:default decode:true  crayon-inline \">AF_&lt;DEBUG/RELEASE&gt;</span>  in your projects. This can be added to <em>Project Properties -&gt; C/C++ -&gt; General -&gt; Preprocessor-&gt; Preprocessory definitions</em>.</li>\n	<li>Pick a solution to handle the NVVM DLLs. We recommend the post build event method used in <a href=\"#s3partA\">Part A</a>.</li>\n</ol>\n<h4><a id=\"s3partC\" class=\"anchor\"></a>Part C: Project with all ArrayFire backends</h4>\nIf you wish to create a project that allows you to use all the ArrayFire backends with ease, the best way to go is to copy the <em>HelloWorld sln/vcxproj/cpp</em> file trio and rename them to suit your project.\n\nAll the ArrayFire examples are pre-configured for all ArrayFire backends as well as the Unified API. These can be chosen from the Solution/Platform configuration drop down boxes.\n\nYou can alternately download the template project from <a href=\"https://github.com/arrayfire/arrayfire-project-templates\">ArrayFire Project Templates</a>\n<h4><a id=\"s3partD\" class=\"anchor\"></a>Part D: ArrayFire with CMake</h4>\n<em>NOTE:</em> The ArrayFire installer sets up CMake file and registry so that it can be found by CMake by simply using the <span class=\"lang:default decode:true  crayon-inline \">Find_PACKAGE(ArrayFire)</span>  command.\n\nIf you are writing a new ArrayFire project in C/C++ from scratch, we suggest you grab a copy of our <a href=\"https://github.com/arrayfire/arrayfire-project-templates\">CMake Project Example</a>; however, it is useful to read the documentation below in case you need to add ArrayFire to an existing project.\n\nAs <a href=\"#big-picture\">discussed above</a>, ArrayFire ships with a series of CMake scripts to make finding and using our library easy. The scripts will automatically find all versions of the ArrayFire library and pick the most powerful of the installed backends (typically CUDA).\n\nFirst create a file called <span class=\"lang:default decode:true  crayon-inline \">CMakeLists.txt</span>  in your project directory:\n<pre class=\"fragment\">cd your-project-directory\ntouch CMakeLists.txt\n</pre>\nand populate it with the following code:\n<pre class=\"fragment\">FIND_PACKAGE(ArrayFire)\nINCLUDE_DIRECTORIES(${ArrayFire_INCLUDE_DIRS})\n\n... [gather source files, etc.]\n\n# If you intend to use OpenCL, you need to find it\nFIND_PACKAGE(OpenCL)\nSET(EXTRA_LIBS ${CMAKE_THREAD_LIBS_INIT} ${OpenCL_LIBRARIES})\n\n# Or if you intend to use CUDA, you need it as well as NVVM:\nFIND_PACKAGE(CUDA)\nFIND_PACKAGE(NVVM) # this FIND script can be found in the ArrayFire CMake example repository\nSET(EXTRA_LIBS ${CMAKE_THREAD_LIBS_INIT} ${CUDA_LIBRARIES} ${NVVM_LIB})\n\nADD_EXECUTABLE(my_executable [list your source files here])\nTARGET_LINK_LIBRARIES(my_executable ${ArrayFire_LIBRARIES} ${EXTRA_LIBS})\n</pre>\nwhere <span class=\"lang:default decode:true  crayon-inline \">my_executable</span>  is the name of the executable you wish to create. See the <a href=\"https://cmake.org/documentation/\">CMake documentation</a> for more information on how to use CMake. Clearly the above code snippet precludes the use of both CUDA and OpenCL, see the <a href=\"https://github.com/bkloppenborg/arrayfire-cmake-example\">ArrayFire CMake Example</a> for an example of how to build executables for both backends from the same CMake script.\n\nIn the above code listing, the <span class=\"lang:default decode:true  crayon-inline \">FIND_PACKAGE</span>  will find the ArrayFire include files, libraries, and define several variables including:\n<pre class=\"fragment\">ArrayFire_INCLUDE_DIRS    - Location of ArrayFire\'s include directory.\nArrayFire_LIBRARIES       - Location of ArrayFire\'s libraries.\n                            This will default to a GPU backend if one\n                            is found\nArrayFire_FOUND           - True if ArrayFire has been located\n</pre>\nIf you wish to use a specific backend, the find script also defines these variables:\n<pre class=\"fragment\">ArrayFire_CPU_FOUND         - True of the ArrayFire CPU library has been found.\nArrayFire_CPU_LIBRARIES     - Location of ArrayFire\'s CPU library, if found\nArrayFire_CUDA_FOUND        - True of the ArrayFire CUDA library has been found.\nArrayFire_CUDA_LIBRARIES    - Location of ArrayFire\'s CUDA library, if found\nArrayFire_OpenCL_FOUND      - True of the ArrayFire OpenCL library has been found.\nArrayFire_OpenCL_LIBRARIES  - Location of ArrayFire\'s OpenCL library, if found\nArrayFire_Unified_FOUND     - True of the ArrayFire Unified library has been found.\nArrayFire_Unified_LIBRARIES - Location of ArrayFire\'s Unified library, if found\n</pre>\nTherefore, if you wish to target a specific specific backend, simply replace <span class=\"lang:default decode:true  crayon-inline \">${ArrayFire_LIBRARIES}</span>  with <span class=\"lang:default decode:true  crayon-inline \">${ArrayFire_CPU}</span> ,<span class=\"lang:default decode:true  crayon-inline \"> ${ArrayFire_OPENCL}</span> , <span class=\"lang:default decode:true  crayon-inline \">${ArrayFire_CUDA}</span> , or <span class=\"lang:default decode:true  crayon-inline \">${ArrayFire_Unified}</span>  in the <span class=\"lang:default decode:true  crayon-inline \">TARGET_LINK_LIBRARIES</span>  command above.\n\nNext we need to instruct CMake to create build instructions and then compile. We suggest using CMake\'s out-of-source build functionality to keep your build and source files cleanly separated. To do this open the CMake GUI.\n<ul>\n	<li>Under source directory, add the path to your project</li>\n	<li>Under build directory, add the path to your project and append /build</li>\n	<li>Click configure and choose Visual Studio 2013 Win 64 as the generator.</li>\n	<li>If configuration was successful, click generate. This will create a my-project.sln file under build. You can open this in Visual Studio and compile the ALL_BUILD project.</li>\n</ul>\nThe <a href=\"https://github.com/bkloppenborg/arrayfire-cmake-example\">ArrayFire CMake Example</a> is a CMake project used to demo how ArrayFire can be using with a CMake project.\n\nNote: The CMake project does not add the post build event to copy the NVVM DLLs in case of CUDA backend. You will need to either copy it manually to the exectuable directory, or pick another solution for it.\n\n</div>\n</div>','Setting up an ArrayFire project on Windows','','inherit','open','closed','','8546-autosave-v1','','','2015-11-06 14:30:58','2015-11-06 14:30:58','',8546,'http://sandbox.arrayfire.com/8546-autosave-v1/',0,'revision','',0),(8580,11,'2015-11-03 22:53:57','2015-11-03 22:53:57','<div class=\"header\">\r\n<div class=\"headertitle\">\r\n<div class=\"title\">If you have not already done so, please make sure you have installed, configured, and tested ArrayFire following the <a class=\"el\" href=\"installing.htm\">installation instructions</a>.</div>\r\n</div>\r\n</div>\r\n<div class=\"contents\">\r\n<div class=\"textblock\">\r\n<h2>The big picture</h2>\r\nThe ArrayFire Windows installer installs the following:\r\n<ol type=\"1\">\r\n	<li>Creates <code>AF_PATH</code> environment variable to point to the installation location.</li>\r\n	<li><code>AF_PATH/include</code> : Header files for ArrayFire (Include Dir)</li>\r\n	<li><code>AF_PATH/lib</code> : All ArrayFire backends libraries, dlls and dependency dlls (Library dir)</li>\r\n	<li><code>AF_PATH/examples</code> : Examples to get started. Some examples also have pre-built exectuables</li>\r\n	<li><code>AF_PATH/cmake</code> : CMake config files for automatic configuration by external projects</li>\r\n	<li><code>AF_PATH/uninstall.exe</code> : Uninstaller</li>\r\n	<li><code>AF_PATH/*</code> : Other miscellenous files including licenses, logos, copyrights</li>\r\n</ol>\r\nThe installer also appends <code>%AF_PATH%/lib</code> to the User PATH variable. See <a href=\"#step1\">step 1</a> for more.\r\n\r\nTo add <code>%AF_PATH%/lib</code> to PATH for all users see the windows section in <a class=\"el\" href=\"installing.htm\">installation instructions</a>.\r\n<h3><a id=\"nvvm_dlls\" class=\"anchor\"></a>Dealing with CUDA NMMV DLLs</h3>\r\nThe NVVM DLLs are not a part of the standard <code>CUDA_PATH\\bin</code> directory which is added to PATH at the time of CUDA installation. Hence it is not found automatically by the system dll loading operation. There are a few ways to deal with this:\r\n<ol type=\"1\">\r\n	<li>Copy the DLLs to the exectuable location. This is the solution ArrayFire\'s examples use. The DLL ios copied to the executable location as a post build event. The steps for this are shown under <a href=\"#s3partA\">Step 3 - Part A</a>.</li>\r\n	<li>Copy <code>CUDA_PATH\\nvvm\\bin\\nvvm64_30_0.dll</code> to <code>CUDA_PATH\\bin</code>. This is a one time copy such that the NVVM DLL is now with all the other CUDA dlls and in a directory that is a part of PATH and hence the DLL can be detected automatically.</li>\r\n	<li>Add <code>%CUDA_PATH%\\nvvm\\bin</code> to the system PATH environment variable. This will allow automatic detection by the system and No further copying will be required. ArrayFire does not add this to PATH since the CUDA installer doesn\'t add it to PATH.</li>\r\n</ol>\r\n<h2><a id=\"step1\" class=\"anchor\"></a>Step 1: Running pre-built executables</h2>\r\nThe ArrayFire installer ships with a few pre-built executables with the examples. These should run out of the box when double clicked.\r\n\r\nSome prebuilt examples are:\r\n<ul>\r\n	<li>Helloworld (examples/helloworld)</li>\r\n	<li>BLAS (examples/benchmarks)</li>\r\n	<li>FFT (examples/benchmarks)</li>\r\n	<li>Pi Estimation (examples/benchmarks)</li>\r\n	<li>Conway (Graphics) (examples/graphics)</li>\r\n</ul>\r\nNote: For the CUDA executables, you will need to copy <code>CUDA_PATH\\nvvm\\bin\\nvvm64_30_0.dll</code> to the location of the executables.\r\n<h2><a id=\"step2\" class=\"anchor\"></a>Step 2: Build and Run a Project</h2>\r\n<ol type=\"1\">\r\n	<li>Open Visual Studio 2013. Load the HelloWorld solution which is located at <code>AF_PATH/examples/helloworld/helloworld.sln</code>.</li>\r\n	<li>Build the <code>helloworld</code> example. Be sure to, select the platform/configuration of your choice using the platform drop-down (the options are CPU, CUDA, OpenCL, and Unified) and Solution Configuration drop down (options of Release and Debug) menus.</li>\r\n	<li>Run the <code>helloworld</code> example.</li>\r\n</ol>\r\n<h2><a id=\"step3\" class=\"anchor\"></a>Step 3: Using ArrayFire with Visual Studio</h2>\r\nThis is divided into 4 parts:\r\n<ul>\r\n	<li><a href=\"#s3partA\">Part A: Adding ArrayFire to an existing solution (Single Backend)</a></li>\r\n	<li><a href=\"#s3partB\">Part B: Adding ArrayFire CUDA to a new/existing CUDA project</a></li>\r\n	<li><a href=\"#s3partC\">Part C: Project with all ArrayFire backends</a></li>\r\n	<li><a href=\"#s3partD\">Part D: ArrayFire with CMake</a></li>\r\n</ul>\r\n<h3><a id=\"s3partA\" class=\"anchor\"></a>Part A: Adding ArrayFire to an existing solution (Single Backend)</h3>\r\nNote: If you plan on using Native CUDA code in the project, use the steps under <a href=\"#s3partB\">Part B</a>.\r\n\r\nAdding a single backend to an existing project is quite simple.\r\n<ol type=\"1\">\r\n	<li>Add <code>\"$(AF_PATH)/include;\"</code> to <em>Project Properties -&gt; C/C++ -&gt; General -&gt; Additional Include Directories</em>.</li>\r\n	<li>Add <code>\"$(AF_PATH)/lib;\"</code> to <em>Project Properties -&gt; Linker -&gt; General -&gt; Additional Library Directories</em>.</li>\r\n	<li>Add <code>afcpu.lib</code> or <code>afcuda.lib</code> or <code>afopencl.lib</code> to <em>Project Properties -&gt; Linker -&gt; Input -&gt; Additional Dependencies</em>. based on your preferred backend.</li>\r\n	<li>(Optional) You may choose to define <code>NOMINMAX</code>, <code>AF_&lt;CPU/CUDA/OPENCL&gt;</code> and/or <code>AF_&lt;DEBUG/RELEASE&gt;</code> in your projects. This can be added to <em>Project Properties -&gt; C/C++ -&gt; General -&gt; Preprocessor-&gt; Preprocessory definitions</em>.</li>\r\n</ol>\r\nIf you are using the CUDA backend, it is important to ensure that the CUDA NVVM DLLs are copied to the exectuable directory. This can be done by adding a post build event.\r\n\r\nOpen the <em>Project Properties -&gt; Build Events -&gt; Post Build Events</em> dialog and add the following lines to it.\r\n<div class=\"fragment\">\r\n<div class=\"line\">echo <a class=\"code\" href=\"group__index__func__index.htm#ga25f470817062b23ad3f74347ea44b17c\">copy</a> <span class=\"stringliteral\">\"$(CUDA_PATH)\\nvvm\\bin\\nvvm64*.dll\"</span> <span class=\"stringliteral\">\"$(OutDir)\"</span></div>\r\n<div class=\"line\"><a class=\"code\" href=\"group__index__func__index.htm#ga25f470817062b23ad3f74347ea44b17c\">copy</a> <span class=\"stringliteral\">\"$(CUDA_PATH)\\nvvm\\bin\\nvvm64*.dll\"</span> <span class=\"stringliteral\">\"$(OutDir)\"</span></div>\r\n</div>\r\n<h3><a id=\"s3partB\" class=\"anchor\"></a>Part B: Adding ArrayFire CUDA to a new/existing CUDA project</h3>\r\nLastly, if your project contains custom CUDA code, the instructions are slightly different as it requires using a CUDA NVCC Project:\r\n<ol type=\"1\">\r\n	<li>Create a custom \"CUDA NVCC project\" in Visual Studio</li>\r\n	<li>Add <code>\"$(AF_PATH)/include;\"</code> to <em>Project Properties -&gt; CUDA C/C++ -&gt; General -&gt; Additional Include Directories</em>.</li>\r\n	<li>Add <code>\"$(AF_PATH)/lib;\"</code> to <em>Project Properties -&gt; Linker -&gt; General -&gt; Additional Library Directories</em>.</li>\r\n	<li>Add <code>afcpu.lib</code> or <code>afcuda.lib</code> or <code>afopencl.lib</code> to <em>Project Properties -&gt; Linker -&gt; Input -&gt; Additional Dependencies</em>. based on your preferred backend.</li>\r\n	<li>(Optional) You may choose to define <code>NOMINMAX</code>, <code>AF_CUDA</code> and/or <code>AF_&lt;DEBUG/RELEASE&gt;</code> in your projects. This can be added to <em>Project Properties -&gt; C/C++ -&gt; General -&gt; Preprocessor-&gt; Preprocessory definitions</em>.</li>\r\n	<li>Pick a solution to handle the NVVM DLLs. We recommend the post build event method used in <a href=\"#s3partA\">Part A</a>.</li>\r\n</ol>\r\n<h3><a id=\"s3partC\" class=\"anchor\"></a>Part C: Project with all ArrayFire backends</h3>\r\nIf you wish to create a project that allows you to use all the ArrayFire backends with ease, the best way to go is to copy the <em>HelloWorld sln/vcxproj/cpp</em> file trio and rename them to suit your project.\r\n\r\nAll the ArrayFire examples are pre-configured for all ArrayFire backends as well as the Unified API. These can be chosen from the Solution/Platform configuration drop down boxes.\r\n\r\nYou can alternately download the template project from <a href=\"https://github.com/arrayfire/arrayfire-template-projects\">ArrayFire Template Projects</a>\r\n<h3><a id=\"s3partD\" class=\"anchor\"></a>Part D: ArrayFire with CMake</h3>\r\n<em>NOTE:</em> The ArrayFire installer sets up CMake file and registry so that it can be found by CMake by simply using the <code>Find_PACKAGE(ArrayFire)</code> command.\r\n\r\nIf you are writing a new ArrayFire project in C/C++ from scratch, we suggest you grab a copy of our <a href=\"https://github.com/arrayfire/arrayfire-template-projects\">CMake Project Example</a>; however, it is useful to read the documentation below in case you need to add ArrayFire to an existing project.\r\n\r\nAs <a href=\"#big-picture\">discussed above</a>, ArrayFire ships with a series of CMake scripts to make finding and using our library easy. The scripts will automatically find all versions of the ArrayFire library and pick the most powerful of the installed backends (typically CUDA).\r\n\r\nFirst create a file called <code>CMakeLists.txt</code> in your project directory:\r\n<pre class=\"fragment\">cd your-project-directory\r\ntouch CMakeLists.txt\r\n</pre>\r\nand populate it with the following code:\r\n<pre class=\"fragment\">FIND_PACKAGE(ArrayFire)\r\nINCLUDE_DIRECTORIES(${ArrayFire_INCLUDE_DIRS})\r\n\r\n... [gather source files, etc.]\r\n\r\n# If you intend to use OpenCL, you need to find it\r\nFIND_PACKAGE(OpenCL)\r\nSET(EXTRA_LIBS ${CMAKE_THREAD_LIBS_INIT} ${OpenCL_LIBRARIES})\r\n\r\n# Or if you intend to use CUDA, you need it as well as NVVM:\r\nFIND_PACKAGE(CUDA)\r\nFIND_PACKAGE(NVVM) # this FIND script can be found in the ArrayFire CMake example repository\r\nSET(EXTRA_LIBS ${CMAKE_THREAD_LIBS_INIT} ${CUDA_LIBRARIES} ${NVVM_LIB})\r\n\r\nADD_EXECUTABLE(my_executable [list your source files here])\r\nTARGET_LINK_LIBRARIES(my_executable ${ArrayFire_LIBRARIES} ${EXTRA_LIBS})\r\n</pre>\r\nwhere <code>my_executable</code> is the name of the executable you wish to create. See the <a href=\"https://cmake.org/documentation/\">CMake documentation</a> for more information on how to use CMake. Clearly the above code snippet precludes the use of both CUDA and OpenCL, see the <a href=\"https://github.com/bkloppenborg/arrayfire-cmake-example\">ArrayFire CMake Example</a> for an example of how to build executables for both backends from the same CMake script.\r\n\r\nIn the above code listing, the <code>FIND_PACKAGE</code> will find the ArrayFire include files, libraries, and define several variables including:\r\n<pre class=\"fragment\">ArrayFire_INCLUDE_DIRS    - Location of ArrayFire\'s include directory.\r\nArrayFire_LIBRARIES       - Location of ArrayFire\'s libraries.\r\n                            This will default to a GPU backend if one\r\n                            is found\r\nArrayFire_FOUND           - True if ArrayFire has been located\r\n</pre>\r\nIf you wish to use a specific backend, the find script also defines these variables:\r\n<pre class=\"fragment\">ArrayFire_CPU_FOUND         - True of the ArrayFire CPU library has been found.\r\nArrayFire_CPU_LIBRARIES     - Location of ArrayFire\'s CPU library, if found\r\nArrayFire_CUDA_FOUND        - True of the ArrayFire CUDA library has been found.\r\nArrayFire_CUDA_LIBRARIES    - Location of ArrayFire\'s CUDA library, if found\r\nArrayFire_OpenCL_FOUND      - True of the ArrayFire OpenCL library has been found.\r\nArrayFire_OpenCL_LIBRARIES  - Location of ArrayFire\'s OpenCL library, if found\r\nArrayFire_Unified_FOUND     - True of the ArrayFire Unified library has been found.\r\nArrayFire_Unified_LIBRARIES - Location of ArrayFire\'s Unified library, if found\r\n</pre>\r\nTherefore, if you wish to target a specific specific backend, simply replace <code>${ArrayFire_LIBRARIES}</code> with <code>${ArrayFire_CPU}</code>, <code>${ArrayFire_OPENCL}</code>, <code>${ArrayFire_CUDA}</code>, or <code>${ArrayFire_Unified}</code> in the <code>TARGET_LINK_LIBRARIES</code> command above.\r\n\r\nNext we need to instruct CMake to create build instructions and then compile. We suggest using CMake\'s out-of-source build functionality to keep your build and source files cleanly separated. To do this open the CMake GUI.\r\n<ul>\r\n	<li>Under source directory, add the path to your project</li>\r\n	<li>Under build directory, add the path to your project and append /build</li>\r\n	<li>Click configure and choose Visual Studio 2013 Win 64 as the generator.</li>\r\n	<li>If configuration was successful, click generate. This will create a my-project.sln file under build. You can open this in Visual Studio and compile the ALL_BUILD project.</li>\r\n</ul>\r\nThe <a href=\"https://github.com/bkloppenborg/arrayfire-cmake-example\">ArrayFire CMake Example</a> is a CMake project used to demo how ArrayFire can be using with a CMake project.\r\n\r\nNote: The CMake project does not add the post build event to copy the NVVM DLLs in case of CUDA backend. You will need to either copy it manually to the exectuable directory, or pick another solution for it.\r\n\r\n</div>\r\n</div>','Setting up an ArrayFire project on Windows','','inherit','open','closed','','8546-revision-v1','','','2015-11-03 22:53:57','2015-11-03 22:53:57','',8546,'http://sandbox.arrayfire.com/8546-revision-v1/',0,'revision','',0),(8581,18528,'2015-11-04 13:29:45','2015-11-04 13:29:45','<div class=\"header\">\r\n<div class=\"headertitle\">\r\n<div class=\"title\">If you have not already done so, please make sure you have installed, configured, and tested ArrayFire following the <a class=\"el\" href=\"installing.htm\">installation instructions</a>.</div>\r\n</div>\r\n</div>\r\n<div class=\"contents\">\r\n<div class=\"textblock\">\r\n<h2>The big picture</h2>\r\nThe ArrayFire Windows installer installs the following:\r\n<pre class=\"lang:default decode:true\">AF_PATH                 Environment variable to point to the installation location.\r\n                        This is normally C:/Program Files/ArrayFire/v*\r\nAF_PATH/include :       Header files for ArrayFire (Include Dir)\r\nAF_PATH/lib :           All ArrayFire backends libraries, dlls and dependency dlls \r\n                        (Library dir)\r\nAF_PATH/examples :      Examples to get started. Some examples also have pre-built \r\n                        exectuables\r\nAF_PATH/cmake :         CMake config files for automatic configuration by external \r\n                        projects\r\nAF_PATH/uninstall.exe : Uninstaller\r\nAF_PATH/* :             Other miscellenous files including licenses, logos, copyrights</pre>\r\nThe installer also appends <span class=\"lang:default decode:true  crayon-inline \">%AF_PATH%/lib</span>  to the User <span class=\"lang:default decode:true  crayon-inline \">PATH</span>  variable (see the <a class=\"el\" href=\"installing.htm\">installation instructions</a> for further details).\r\n<h3>Dealing with CUDA NMMV DLLs</h3>\r\nThe NVVM DLLs are not a part of the standard <span class=\"lang:default decode:true  crayon-inline \">CUDA_PATH\\bin</span>  directory which is added to PATH at the time of CUDA installation. Hence it is not found automatically by the system dll loading operation. There are a few ways to deal with this:\r\n<ol type=\"1\">\r\n	<li>Copy the DLLs to the exectuable location. This is the solution ArrayFire\'s examples use. The DLL ios copied to the executable location as a post build event. The steps for this are shown under <a href=\"#s3partA\">Step 3 - Part A</a>.</li>\r\n	<li>Copy <span class=\"lang:default decode:true  crayon-inline \">CUDA_PATH\\nvvm\\bin\\nvvm64_30_0.dll</span>  to <span class=\"lang:default decode:true  crayon-inline \">CUDA_PATH\\bin</span> . This is a one time copy such that the NVVM DLL is now with all the other CUDA dlls and in a directory that is a part of PATH and hence the DLL can be detected automatically.</li>\r\n	<li>Add <span class=\"lang:default decode:true  crayon-inline \">%CUDA_PATH%\\nvvm\\bin</span>  to the system PATH environment variable. This will allow automatic detection by the system and No further copying will be required. ArrayFire does not add this to PATH since the CUDA installer doesn\'t add it to PATH.</li>\r\n</ol>\r\n<h2><a id=\"step1\" class=\"anchor\"></a>Step 1: Running pre-built executables</h2>\r\nThe ArrayFire installer ships with a few pre-built executables with the examples. These should run out of the box when double clicked.\r\n\r\nSome prebuilt examples are:\r\n<ul>\r\n	<li>Helloworld (examples/helloworld)</li>\r\n	<li>BLAS (examples/benchmarks)</li>\r\n	<li>FFT (examples/benchmarks)</li>\r\n	<li>Pi Estimation (examples/benchmarks)</li>\r\n	<li>Conway (Graphics) (examples/graphics)</li>\r\n</ul>\r\nNote: For the CUDA executables, you will need to copy <span class=\"lang:default decode:true  crayon-inline \">CUDA_PATH\\nvvm\\bin\\nvvm64_30_0.dll</span>  to the location of the executables.\r\n<h2><a id=\"step2\" class=\"anchor\"></a>Step 2: Build and Run a Project</h2>\r\n<ol type=\"1\">\r\n	<li>Open Visual Studio 2013. Load the HelloWorld solution which is located at <span class=\"lang:default decode:true  crayon-inline \">AF_PATH/examples/helloworld/helloworld.sln</span> .</li>\r\n	<li>Build the <span class=\"lang:default decode:true  crayon-inline \">helloworld</span>  example. Be sure to, select the platform/configuration of your choice using the platform drop-down (the options are CPU, CUDA, OpenCL, and Unified) and Solution Configuration drop down (options of Release and Debug) menus.</li>\r\n	<li>Run the <span class=\"lang:default decode:true  crayon-inline \">helloworld</span>  example.</li>\r\n</ol>\r\n<h2><a id=\"step3\" class=\"anchor\"></a>Step 3: Using ArrayFire with Visual Studio</h2>\r\nThis is divided into 4 parts:\r\n<ul>\r\n	<li><a href=\"#s3partA\">Part A: Adding ArrayFire to an existing solution (Single Backend)</a></li>\r\n	<li><a href=\"#s3partB\">Part B: Adding ArrayFire CUDA to a new/existing CUDA project</a></li>\r\n	<li><a href=\"#s3partC\">Part C: Project with all ArrayFire backends</a></li>\r\n	<li><a href=\"#s3partD\">Part D: ArrayFire with CMake</a></li>\r\n</ul>\r\n<h3><a id=\"s3partA\" class=\"anchor\"></a>Part A: Adding ArrayFire to an existing solution (Single Backend)</h3>\r\nNote: If you plan on using Native CUDA code in the project, use the steps under <a href=\"#s3partB\">Part B</a>.\r\n\r\nAdding a single backend to an existing project is quite simple.\r\n<ol type=\"1\">\r\n	<li>Add <code>\"<span class=\"lang:default decode:true  crayon-inline \">$(AF_PATH)/include;</span> \"</code> to <em>Project Properties -&gt; C/C++ -&gt; General -&gt; Additional Include Directories</em>.</li>\r\n	<li>Add <code>\"<span class=\"lang:default decode:true  crayon-inline \">$(AF_PATH)/lib;</span> \"</code> to <em>Project Properties -&gt; Linker -&gt; General -&gt; Additional Library Directories</em>.</li>\r\n	<li>Add <span class=\"lang:default decode:true  crayon-inline \">afcpu.lib</span>  or <span class=\"lang:default decode:true  crayon-inline \">afcuda.lib</span>  or <span class=\"lang:default decode:true  crayon-inline \">afopencl.lib</span>  to <em>Project Properties -&gt; Linker -&gt; Input -&gt; Additional Dependencies</em>. based on your preferred backend.</li>\r\n	<li>(Optional) You may choose to define <span class=\"lang:default decode:true  crayon-inline \">NOMINMAX, AF_&lt;CPU/CUDA/OPENCL&gt;</span>  and/or <span class=\"lang:default decode:true  crayon-inline \">AF_&lt;DEBUG/RELEASE&gt;</span>  in your projects. This can be added to <em>Project Properties -&gt; C/C++ -&gt; General -&gt; Preprocessor-&gt; Preprocessory definitions</em>.</li>\r\n</ol>\r\nIf you are using the CUDA backend, it is important to ensure that the CUDA NVVM DLLs are copied to the exectuable directory. This can be done by adding a post build event.\r\n\r\nOpen the <em>Project Properties -&gt; Build Events -&gt; Post Build Events</em> dialog and add the following lines to it.\r\n<div class=\"fragment\">\r\n<pre class=\"lang:default decode:true\">echo copy \"$(CUDA_PATH)\\nvvm\\bin\\nvvm64*.dll\" \"$(OutDir)\" \r\necho copy \"$(CUDA_PATH)\\nvvm\\bin\\nvvm64*.dll\" \"$(OutDir)\"</pre>\r\n<h3 class=\"line\"> <a id=\"s3partB\" class=\"anchor\"></a>Part B: Adding ArrayFire CUDA to a new/existing CUDA project</h3>\r\n</div>\r\nLastly, if your project contains custom CUDA code, the instructions are slightly different as it requires using a CUDA NVCC Project:\r\n<ol type=\"1\">\r\n	<li>Create a custom \"CUDA NVCC project\" in Visual Studio</li>\r\n	<li>Add <code>\"<span class=\"lang:default decode:true  crayon-inline \">$(AF_PATH)/include;</span> \"</code> to <em>Project Properties -&gt; CUDA C/C++ -&gt; General -&gt; Additional Include Directories</em>.</li>\r\n	<li>Add <code>\"<span class=\"lang:default decode:true  crayon-inline \">$(AF_PATH)/lib;</span> \"</code> to <em>Project Properties -&gt; Linker -&gt; General -&gt; Additional Library Directories</em>.</li>\r\n	<li>Add <span class=\"lang:default decode:true  crayon-inline \">afcpu.lib</span>  or <span class=\"lang:default decode:true  crayon-inline \">afcuda.lib</span>  or <span class=\"lang:default decode:true  crayon-inline \">afopencl.lib</span>  to <em>Project Properties -&gt; Linker -&gt; Input -&gt; Additional Dependencies</em>. based on your preferred backend.</li>\r\n	<li>(Optional) You may choose to define <span class=\"lang:default decode:true  crayon-inline \">NOMINMAX, AF_CUDA</span>  and/or <span class=\"lang:default decode:true  crayon-inline \">AF_&lt;DEBUG/RELEASE&gt;</span>  in your projects. This can be added to <em>Project Properties -&gt; C/C++ -&gt; General -&gt; Preprocessor-&gt; Preprocessory definitions</em>.</li>\r\n	<li>Pick a solution to handle the NVVM DLLs. We recommend the post build event method used in <a href=\"#s3partA\">Part A</a>.</li>\r\n</ol>\r\n<h3><a id=\"s3partC\" class=\"anchor\"></a>Part C: Project with all ArrayFire backends</h3>\r\nIf you wish to create a project that allows you to use all the ArrayFire backends with ease, the best way to go is to copy the <em>HelloWorld sln/vcxproj/cpp</em> file trio and rename them to suit your project.\r\n\r\nAll the ArrayFire examples are pre-configured for all ArrayFire backends as well as the Unified API. These can be chosen from the Solution/Platform configuration drop down boxes.\r\n\r\nYou can alternately download the template project from <a href=\"https://github.com/arrayfire/arrayfire-template-projects\">ArrayFire Template Projects</a>\r\n<h3><a id=\"s3partD\" class=\"anchor\"></a>Part D: ArrayFire with CMake</h3>\r\n<em>NOTE:</em> The ArrayFire installer sets up CMake file and registry so that it can be found by CMake by simply using the <span class=\"lang:default decode:true  crayon-inline \">Find_PACKAGE(ArrayFire)</span>  command.\r\n\r\nIf you are writing a new ArrayFire project in C/C++ from scratch, we suggest you grab a copy of our <a href=\"https://github.com/arrayfire/arrayfire-template-projects\">CMake Project Example</a>; however, it is useful to read the documentation below in case you need to add ArrayFire to an existing project.\r\n\r\nAs <a href=\"#big-picture\">discussed above</a>, ArrayFire ships with a series of CMake scripts to make finding and using our library easy. The scripts will automatically find all versions of the ArrayFire library and pick the most powerful of the installed backends (typically CUDA).\r\n\r\nFirst create a file called <span class=\"lang:default decode:true  crayon-inline \">CMakeLists.txt</span>  in your project directory:\r\n<pre class=\"fragment\">cd your-project-directory\r\ntouch CMakeLists.txt\r\n</pre>\r\nand populate it with the following code:\r\n<pre class=\"fragment\">FIND_PACKAGE(ArrayFire)\r\nINCLUDE_DIRECTORIES(${ArrayFire_INCLUDE_DIRS})\r\n\r\n... [gather source files, etc.]\r\n\r\n# If you intend to use OpenCL, you need to find it\r\nFIND_PACKAGE(OpenCL)\r\nSET(EXTRA_LIBS ${CMAKE_THREAD_LIBS_INIT} ${OpenCL_LIBRARIES})\r\n\r\n# Or if you intend to use CUDA, you need it as well as NVVM:\r\nFIND_PACKAGE(CUDA)\r\nFIND_PACKAGE(NVVM) # this FIND script can be found in the ArrayFire CMake example repository\r\nSET(EXTRA_LIBS ${CMAKE_THREAD_LIBS_INIT} ${CUDA_LIBRARIES} ${NVVM_LIB})\r\n\r\nADD_EXECUTABLE(my_executable [list your source files here])\r\nTARGET_LINK_LIBRARIES(my_executable ${ArrayFire_LIBRARIES} ${EXTRA_LIBS})\r\n</pre>\r\nwhere <span class=\"lang:default decode:true  crayon-inline \">my_executable</span>  is the name of the executable you wish to create. See the <a href=\"https://cmake.org/documentation/\">CMake documentation</a> for more information on how to use CMake. Clearly the above code snippet precludes the use of both CUDA and OpenCL, see the <a href=\"https://github.com/bkloppenborg/arrayfire-cmake-example\">ArrayFire CMake Example</a> for an example of how to build executables for both backends from the same CMake script.\r\n\r\nIn the above code listing, the <span class=\"lang:default decode:true  crayon-inline \">FIND_PACKAGE</span>  will find the ArrayFire include files, libraries, and define several variables including:\r\n<pre class=\"fragment\">ArrayFire_INCLUDE_DIRS    - Location of ArrayFire\'s include directory.\r\nArrayFire_LIBRARIES       - Location of ArrayFire\'s libraries.\r\n                            This will default to a GPU backend if one\r\n                            is found\r\nArrayFire_FOUND           - True if ArrayFire has been located\r\n</pre>\r\nIf you wish to use a specific backend, the find script also defines these variables:\r\n<pre class=\"fragment\">ArrayFire_CPU_FOUND         - True of the ArrayFire CPU library has been found.\r\nArrayFire_CPU_LIBRARIES     - Location of ArrayFire\'s CPU library, if found\r\nArrayFire_CUDA_FOUND        - True of the ArrayFire CUDA library has been found.\r\nArrayFire_CUDA_LIBRARIES    - Location of ArrayFire\'s CUDA library, if found\r\nArrayFire_OpenCL_FOUND      - True of the ArrayFire OpenCL library has been found.\r\nArrayFire_OpenCL_LIBRARIES  - Location of ArrayFire\'s OpenCL library, if found\r\nArrayFire_Unified_FOUND     - True of the ArrayFire Unified library has been found.\r\nArrayFire_Unified_LIBRARIES - Location of ArrayFire\'s Unified library, if found\r\n</pre>\r\nTherefore, if you wish to target a specific specific backend, simply replace <span class=\"lang:default decode:true  crayon-inline \">${ArrayFire_LIBRARIES}</span>  with <span class=\"lang:default decode:true  crayon-inline \">${ArrayFire_CPU}</span> ,<span class=\"lang:default decode:true  crayon-inline \"> ${ArrayFire_OPENCL}</span> , <span class=\"lang:default decode:true  crayon-inline \">${ArrayFire_CUDA}</span> , or <span class=\"lang:default decode:true  crayon-inline \">${ArrayFire_Unified}</span>  in the <span class=\"lang:default decode:true  crayon-inline \">TARGET_LINK_LIBRARIES</span>  command above.\r\n\r\nNext we need to instruct CMake to create build instructions and then compile. We suggest using CMake\'s out-of-source build functionality to keep your build and source files cleanly separated. To do this open the CMake GUI.\r\n<ul>\r\n	<li>Under source directory, add the path to your project</li>\r\n	<li>Under build directory, add the path to your project and append /build</li>\r\n	<li>Click configure and choose Visual Studio 2013 Win 64 as the generator.</li>\r\n	<li>If configuration was successful, click generate. This will create a my-project.sln file under build. You can open this in Visual Studio and compile the ALL_BUILD project.</li>\r\n</ul>\r\nThe <a href=\"https://github.com/bkloppenborg/arrayfire-cmake-example\">ArrayFire CMake Example</a> is a CMake project used to demo how ArrayFire can be using with a CMake project.\r\n\r\nNote: The CMake project does not add the post build event to copy the NVVM DLLs in case of CUDA backend. You will need to either copy it manually to the exectuable directory, or pick another solution for it.\r\n\r\n</div>\r\n</div>','Setting up an ArrayFire project on Windows','','inherit','open','closed','','8546-revision-v1','','','2015-11-04 13:29:45','2015-11-04 13:29:45','',8546,'http://sandbox.arrayfire.com/8546-revision-v1/',0,'revision','',0),(8582,18528,'2015-11-04 13:44:41','2015-11-04 13:44:41','<div class=\"header\">\r\n<div class=\"headertitle\">\r\n<div class=\"title\">Continuing our blog series \"<a href=\"http://sandbox.arrayfire.com/tag/learning-arrayfire-from-scratch/\">Learning ArrayFire from scratch</a>\" today we will discuss how to set up an ArrayFire project on Windows using Visual Studio or CMake.</div>\r\n</div>\r\n</div>\r\n<!--more-->\r\n\r\nIf you have not already done so, please make sure you have installed, configured, and tested ArrayFire following the <a class=\"el\" href=\"installing.htm\">installation instructions</a>.\r\n<div class=\"contents\">\r\n<div class=\"textblock\">\r\n<h2>The big picture</h2>\r\nThe ArrayFire Windows installer creates the following:\r\n<pre class=\"lang:default decode:true\">AF_PATH                 Environment variable to point to the installation location.\r\n                        This is normally C:/Program Files/ArrayFire/v*\r\nAF_PATH/include         Header files for ArrayFire (Include Dir)\r\nAF_PATH/lib             All ArrayFire backends libraries, dlls and dependency dlls \r\n                        (Library dir)\r\nAF_PATH/examples        Examples to get started. Some examples also have pre-built \r\n                        exectuables\r\nAF_PATH/cmake           CMake config files for automatic configuration by external \r\n                        projects\r\nAF_PATH/uninstall.exe : Uninstaller\r\nAF_PATH/*               Other miscellenous files including licenses, logos, copyrights</pre>\r\nThe installer also appends <span class=\"lang:default decode:true  crayon-inline \">%AF_PATH%/lib</span>  to the User <span class=\"lang:default decode:true  crayon-inline \">PATH</span>  variable (see the <a class=\"el\" href=\"installing.htm\">installation instructions</a> for further details).\r\n<h3>Dealing with CUDA NMMV DLLs</h3>\r\nWhen using CUDA with ArrayFire you may encounter a linker error indicating the NVVM DLLs are missing. This is because the NVVM DLLs are not part of the standard <span class=\"lang:default decode:true  crayon-inline \">CUDA_PATH\\bin</span>  installation directory that is added to your <span class=\"lang:default decode:true  crayon-inline \">PATH</span>  when the CUDA installer runs. Thus, NVVM will not be found during the linking stage. There are a few ways to deal with this issue:\r\n\r\n&nbsp;\r\n<ol type=\"1\">\r\n	<li>Copy the DLLs to the executable location. This is, by far, the easiest solution and we suggest doing this with ArrayFire projects. To do so, create a post-build event to copy the NVVM DLL as discussed below in <a href=\"#s3partA\">Step 3 - Part A</a>.</li>\r\n	<li>Copy <span class=\"lang:default decode:true  crayon-inline \">CUDA_PATH\\nvvm\\bin\\nvvm64_30_0.dll</span>  to <span class=\"lang:default decode:true  crayon-inline \">CUDA_PATH\\bin</span> . This is a one time copy such that the NVVM DLL is now with all the other CUDA dlls and in a directory that is a part of PATH and hence the DLL can be detected automatically.</li>\r\n	<li>Add <span class=\"lang:default decode:true  crayon-inline \">%CUDA_PATH%\\nvvm\\bin</span>  to the system PATH environment variable. This will allow automatic detection by the system and No further copying will be required. ArrayFire does not add this to PATH since the CUDA installer doesn\'t add it to PATH.</li>\r\n</ol>\r\n<h2><a id=\"step1\" class=\"anchor\"></a>Step 1: Running pre-built executables</h2>\r\nThe ArrayFire installer ships with a few pre-built executables with the examples. These should run out of the box when double clicked.\r\n\r\nSome prebuilt examples are:\r\n<ul>\r\n	<li>Helloworld (examples/helloworld)</li>\r\n	<li>BLAS (examples/benchmarks)</li>\r\n	<li>FFT (examples/benchmarks)</li>\r\n	<li>Pi Estimation (examples/benchmarks)</li>\r\n	<li>Conway (Graphics) (examples/graphics)</li>\r\n</ul>\r\nNote: For the CUDA executables, you will need to copy <span class=\"lang:default decode:true  crayon-inline \">CUDA_PATH\\nvvm\\bin\\nvvm64_30_0.dll</span>  to the location of the executables.\r\n<h2><a id=\"step2\" class=\"anchor\"></a>Step 2: Build and Run a Project</h2>\r\n<ol type=\"1\">\r\n	<li>Open Visual Studio 2013. Load the HelloWorld solution which is located at <span class=\"lang:default decode:true  crayon-inline \">AF_PATH/examples/helloworld/helloworld.sln</span> .</li>\r\n	<li>Build the <span class=\"lang:default decode:true  crayon-inline \">helloworld</span>  example. Be sure to, select the platform/configuration of your choice using the platform drop-down (the options are CPU, CUDA, OpenCL, and Unified) and Solution Configuration drop down (options of Release and Debug) menus.</li>\r\n	<li>Run the <span class=\"lang:default decode:true  crayon-inline \">helloworld</span>  example.</li>\r\n</ol>\r\n<h2><a id=\"step3\" class=\"anchor\"></a>Step 3: Using ArrayFire within Visual Studio</h2>\r\nThis is divided into 4 parts:\r\n<ul>\r\n	<li><a href=\"#s3partA\">Part A: Adding ArrayFire to an existing solution (Single Backend)</a></li>\r\n	<li><a href=\"#s3partB\">Part B: Adding ArrayFire CUDA to a new/existing CUDA project</a></li>\r\n	<li><a href=\"#s3partC\">Part C: Project with all ArrayFire backends</a></li>\r\n	<li><a href=\"#s3partD\">Part D: ArrayFire with CMake</a></li>\r\n</ul>\r\n<h3><a id=\"s3partA\" class=\"anchor\"></a>Part A: Adding ArrayFire to an existing solution (Single Backend)</h3>\r\nNote: If you plan on using Native CUDA code in the project, use the steps under <a href=\"#s3partB\">Part B</a>.\r\n\r\nAdding a single backend to an existing project is quite simple.\r\n<ol type=\"1\">\r\n	<li>Add <code>\"<span class=\"lang:default decode:true  crayon-inline \">$(AF_PATH)/include;</span> \"</code> to <em>Project Properties -&gt; C/C++ -&gt; General -&gt; Additional Include Directories</em>.</li>\r\n	<li>Add <code>\"<span class=\"lang:default decode:true  crayon-inline \">$(AF_PATH)/lib;</span> \"</code> to <em>Project Properties -&gt; Linker -&gt; General -&gt; Additional Library Directories</em>.</li>\r\n	<li>Add <span class=\"lang:default decode:true  crayon-inline \">afcpu.lib</span>  or <span class=\"lang:default decode:true  crayon-inline \">afcuda.lib</span>  or <span class=\"lang:default decode:true  crayon-inline \">afopencl.lib</span>  to <em>Project Properties -&gt; Linker -&gt; Input -&gt; Additional Dependencies</em>. based on your preferred backend.</li>\r\n	<li>(Optional) You may choose to define <span class=\"lang:default decode:true  crayon-inline \">NOMINMAX, AF_&lt;CPU/CUDA/OPENCL&gt;</span>  and/or <span class=\"lang:default decode:true  crayon-inline \">AF_&lt;DEBUG/RELEASE&gt;</span>  in your projects. This can be added to <em>Project Properties -&gt; C/C++ -&gt; General -&gt; Preprocessor-&gt; Preprocessory definitions</em>.</li>\r\n</ol>\r\nIf you are using the CUDA backend, it is important to ensure that the CUDA NVVM DLLs are copied to the exectuable directory. This can be done by adding a post build event.\r\n\r\nOpen the <em>Project Properties -&gt; Build Events -&gt; Post Build Events</em> dialog and add the following lines to it.\r\n<div class=\"fragment\">\r\n<pre class=\"lang:default decode:true\">echo copy \"$(CUDA_PATH)\\nvvm\\bin\\nvvm64*.dll\" \"$(OutDir)\" \r\necho copy \"$(CUDA_PATH)\\nvvm\\bin\\nvvm64*.dll\" \"$(OutDir)\"</pre>\r\n<h3 class=\"line\"> <a id=\"s3partB\" class=\"anchor\"></a>Part B: Adding ArrayFire CUDA to a new/existing CUDA project</h3>\r\n</div>\r\nLastly, if your project contains custom CUDA code, the instructions are slightly different as it requires using a CUDA NVCC Project:\r\n<ol type=\"1\">\r\n	<li>Create a custom \"CUDA NVCC project\" in Visual Studio</li>\r\n	<li>Add <code>\"<span class=\"lang:default decode:true  crayon-inline \">$(AF_PATH)/include;</span> \"</code> to <em>Project Properties -&gt; CUDA C/C++ -&gt; General -&gt; Additional Include Directories</em>.</li>\r\n	<li>Add <code>\"<span class=\"lang:default decode:true  crayon-inline \">$(AF_PATH)/lib;</span> \"</code> to <em>Project Properties -&gt; Linker -&gt; General -&gt; Additional Library Directories</em>.</li>\r\n	<li>Add <span class=\"lang:default decode:true  crayon-inline \">afcpu.lib</span>  or <span class=\"lang:default decode:true  crayon-inline \">afcuda.lib</span>  or <span class=\"lang:default decode:true  crayon-inline \">afopencl.lib</span>  to <em>Project Properties -&gt; Linker -&gt; Input -&gt; Additional Dependencies</em>. based on your preferred backend.</li>\r\n	<li>(Optional) You may choose to define <span class=\"lang:default decode:true  crayon-inline \">NOMINMAX, AF_CUDA</span>  and/or <span class=\"lang:default decode:true  crayon-inline \">AF_&lt;DEBUG/RELEASE&gt;</span>  in your projects. This can be added to <em>Project Properties -&gt; C/C++ -&gt; General -&gt; Preprocessor-&gt; Preprocessory definitions</em>.</li>\r\n	<li>Pick a solution to handle the NVVM DLLs. We recommend the post build event method used in <a href=\"#s3partA\">Part A</a>.</li>\r\n</ol>\r\n<h3><a id=\"s3partC\" class=\"anchor\"></a>Part C: Project with all ArrayFire backends</h3>\r\nIf you wish to create a project that allows you to use all the ArrayFire backends with ease, the best way to go is to copy the <em>HelloWorld sln/vcxproj/cpp</em> file trio and rename them to suit your project.\r\n\r\nAll the ArrayFire examples are pre-configured for all ArrayFire backends as well as the Unified API. These can be chosen from the Solution/Platform configuration drop down boxes.\r\n\r\nYou can alternately download the template project from <a href=\"https://github.com/arrayfire/arrayfire-template-projects\">ArrayFire Template Projects</a>\r\n<h3><a id=\"s3partD\" class=\"anchor\"></a>Part D: ArrayFire with CMake</h3>\r\n<em>NOTE:</em> The ArrayFire installer sets up CMake file and registry so that it can be found by CMake by simply using the <span class=\"lang:default decode:true  crayon-inline \">Find_PACKAGE(ArrayFire)</span>  command.\r\n\r\nIf you are writing a new ArrayFire project in C/C++ from scratch, we suggest you grab a copy of our <a href=\"https://github.com/arrayfire/arrayfire-template-projects\">CMake Project Example</a>; however, it is useful to read the documentation below in case you need to add ArrayFire to an existing project.\r\n\r\nAs <a href=\"#big-picture\">discussed above</a>, ArrayFire ships with a series of CMake scripts to make finding and using our library easy. The scripts will automatically find all versions of the ArrayFire library and pick the most powerful of the installed backends (typically CUDA).\r\n\r\nFirst create a file called <span class=\"lang:default decode:true  crayon-inline \">CMakeLists.txt</span>  in your project directory:\r\n<pre class=\"fragment\">cd your-project-directory\r\ntouch CMakeLists.txt\r\n</pre>\r\nand populate it with the following code:\r\n<pre class=\"fragment\">FIND_PACKAGE(ArrayFire)\r\nINCLUDE_DIRECTORIES(${ArrayFire_INCLUDE_DIRS})\r\n\r\n... [gather source files, etc.]\r\n\r\n# If you intend to use OpenCL, you need to find it\r\nFIND_PACKAGE(OpenCL)\r\nSET(EXTRA_LIBS ${CMAKE_THREAD_LIBS_INIT} ${OpenCL_LIBRARIES})\r\n\r\n# Or if you intend to use CUDA, you need it as well as NVVM:\r\nFIND_PACKAGE(CUDA)\r\nFIND_PACKAGE(NVVM) # this FIND script can be found in the ArrayFire CMake example repository\r\nSET(EXTRA_LIBS ${CMAKE_THREAD_LIBS_INIT} ${CUDA_LIBRARIES} ${NVVM_LIB})\r\n\r\nADD_EXECUTABLE(my_executable [list your source files here])\r\nTARGET_LINK_LIBRARIES(my_executable ${ArrayFire_LIBRARIES} ${EXTRA_LIBS})\r\n</pre>\r\nwhere <span class=\"lang:default decode:true  crayon-inline \">my_executable</span>  is the name of the executable you wish to create. See the <a href=\"https://cmake.org/documentation/\">CMake documentation</a> for more information on how to use CMake. Clearly the above code snippet precludes the use of both CUDA and OpenCL, see the <a href=\"https://github.com/bkloppenborg/arrayfire-cmake-example\">ArrayFire CMake Example</a> for an example of how to build executables for both backends from the same CMake script.\r\n\r\nIn the above code listing, the <span class=\"lang:default decode:true  crayon-inline \">FIND_PACKAGE</span>  will find the ArrayFire include files, libraries, and define several variables including:\r\n<pre class=\"fragment\">ArrayFire_INCLUDE_DIRS    - Location of ArrayFire\'s include directory.\r\nArrayFire_LIBRARIES       - Location of ArrayFire\'s libraries.\r\n                            This will default to a GPU backend if one\r\n                            is found\r\nArrayFire_FOUND           - True if ArrayFire has been located\r\n</pre>\r\nIf you wish to use a specific backend, the find script also defines these variables:\r\n<pre class=\"fragment\">ArrayFire_CPU_FOUND         - True of the ArrayFire CPU library has been found.\r\nArrayFire_CPU_LIBRARIES     - Location of ArrayFire\'s CPU library, if found\r\nArrayFire_CUDA_FOUND        - True of the ArrayFire CUDA library has been found.\r\nArrayFire_CUDA_LIBRARIES    - Location of ArrayFire\'s CUDA library, if found\r\nArrayFire_OpenCL_FOUND      - True of the ArrayFire OpenCL library has been found.\r\nArrayFire_OpenCL_LIBRARIES  - Location of ArrayFire\'s OpenCL library, if found\r\nArrayFire_Unified_FOUND     - True of the ArrayFire Unified library has been found.\r\nArrayFire_Unified_LIBRARIES - Location of ArrayFire\'s Unified library, if found\r\n</pre>\r\nTherefore, if you wish to target a specific specific backend, simply replace <span class=\"lang:default decode:true  crayon-inline \">${ArrayFire_LIBRARIES}</span>  with <span class=\"lang:default decode:true  crayon-inline \">${ArrayFire_CPU}</span> ,<span class=\"lang:default decode:true  crayon-inline \"> ${ArrayFire_OPENCL}</span> , <span class=\"lang:default decode:true  crayon-inline \">${ArrayFire_CUDA}</span> , or <span class=\"lang:default decode:true  crayon-inline \">${ArrayFire_Unified}</span>  in the <span class=\"lang:default decode:true  crayon-inline \">TARGET_LINK_LIBRARIES</span>  command above.\r\n\r\nNext we need to instruct CMake to create build instructions and then compile. We suggest using CMake\'s out-of-source build functionality to keep your build and source files cleanly separated. To do this open the CMake GUI.\r\n<ul>\r\n	<li>Under source directory, add the path to your project</li>\r\n	<li>Under build directory, add the path to your project and append /build</li>\r\n	<li>Click configure and choose Visual Studio 2013 Win 64 as the generator.</li>\r\n	<li>If configuration was successful, click generate. This will create a my-project.sln file under build. You can open this in Visual Studio and compile the ALL_BUILD project.</li>\r\n</ul>\r\nThe <a href=\"https://github.com/bkloppenborg/arrayfire-cmake-example\">ArrayFire CMake Example</a> is a CMake project used to demo how ArrayFire can be using with a CMake project.\r\n\r\nNote: The CMake project does not add the post build event to copy the NVVM DLLs in case of CUDA backend. You will need to either copy it manually to the exectuable directory, or pick another solution for it.\r\n\r\n</div>\r\n</div>','Setting up an ArrayFire project on Windows','','inherit','open','closed','','8546-revision-v1','','','2015-11-04 13:44:41','2015-11-04 13:44:41','',8546,'http://sandbox.arrayfire.com/8546-revision-v1/',0,'revision','',0),(8583,11,'2015-11-04 16:49:27','2015-11-04 16:49:27','<div class=\"header\">\r\n<div class=\"headertitle\">\r\n<div class=\"title\">Continuing our blog series \"<a href=\"http://sandbox.arrayfire.com/tag/learning-arrayfire-from-scratch/\">Learning ArrayFire from scratch</a>\" today we will discuss how to set up an ArrayFire project on Windows using Visual Studio or CMake.</div>\r\n</div>\r\n</div>\r\n<!--more-->\r\n\r\nIf you have not already done so, please make sure you have installed, configured, and tested ArrayFire following the <a class=\"el\" href=\"installing.htm\">installation instructions</a>.\r\n<div class=\"contents\">\r\n<div class=\"textblock\">\r\n<h2>The big picture</h2>\r\nThe ArrayFire Windows installer creates the following:\r\n<pre class=\"lang:default decode:true\">AF_PATH                 Environment variable to point to the installation location.\r\n                        This is normally C:/Program Files/ArrayFire/v*\r\nAF_PATH/include         Header files for ArrayFire (Include Dir)\r\nAF_PATH/lib             All ArrayFire backends libraries, dlls and dependency dlls \r\n                        (Library dir)\r\nAF_PATH/examples        Examples to get started. Some examples also have pre-built \r\n                        exectuables\r\nAF_PATH/cmake           CMake config files for automatic configuration by external \r\n                        projects\r\nAF_PATH/uninstall.exe   Uninstaller\r\nAF_PATH/*               Other miscellenous files including licenses, logos, copyrights</pre>\r\nThe installer also appends <span class=\"lang:default decode:true  crayon-inline \">%AF_PATH%/lib</span>  to the User <span class=\"lang:default decode:true  crayon-inline \">PATH</span>  variable (see the <a class=\"el\" href=\"installing.htm\">installation instructions</a> for further details).\r\n<h3>Dealing with CUDA NMMV DLLs</h3>\r\nWhen using CUDA with ArrayFire you may encounter a linker error indicating the NVVM DLLs are missing. This is because the NVVM DLLs are not part of the standard <span class=\"lang:default decode:true  crayon-inline \">CUDA_PATH\\bin</span>  installation directory that is added to your <span class=\"lang:default decode:true  crayon-inline \">PATH</span>  when the CUDA installer runs. Thus, NVVM will not be found during the linking stage. There are a few ways to deal with this issue:\r\n\r\n&nbsp;\r\n<ol type=\"1\">\r\n	<li>Copy the DLLs to the executable location. This is, by far, the cleanest solution and we suggest doing this with ArrayFire projects. To do so, create a post-build event to copy the NVVM DLL as discussed below in <a href=\"#s3partA\">Step 3 - Part A</a>.</li>\r\n	<li>Copy <span class=\"lang:default decode:true  crayon-inline\">CUDA_PATH\\nvvm\\bin\\nvvm64_30_0.dll</span>  to <span class=\"lang:default decode:true  crayon-inline \">CUDA_PATH\\bin</span> . This is a one time copy such that the NVVM DLL is now with all the other CUDA dlls and in a directory that is a part of PATH and hence the DLL can be detected automatically.</li>\r\n	<li>Add <span class=\"lang:default decode:true  crayon-inline \">%CUDA_PATH%\\nvvm\\bin</span>  to the system PATH environment variable. This will allow automatic detection by the system and No further copying will be required. ArrayFire does not add this to PATH since the CUDA installer doesn\'t add it to PATH.</li>\r\n</ol>\r\n<h2><a id=\"step1\" class=\"anchor\"></a>Step 1: Running pre-built executables</h2>\r\nThe ArrayFire installer ships with a few pre-built executables with the examples. These should run out of the box when double clicked.\r\n\r\nSome prebuilt examples are:\r\n<ul>\r\n	<li>Helloworld (examples/helloworld)</li>\r\n	<li>BLAS (examples/benchmarks)</li>\r\n	<li>FFT (examples/benchmarks)</li>\r\n	<li>Pi Estimation (examples/benchmarks)</li>\r\n	<li>Conway (Graphics) (examples/graphics)</li>\r\n</ul>\r\nNote: For the CUDA executables, you will need to copy <span class=\"lang:default decode:true  crayon-inline \">CUDA_PATH\\nvvm\\bin\\nvvm64_30_0.dll</span>  to the location of the executables.\r\n<h2><a id=\"step2\" class=\"anchor\"></a>Step 2: Build and Run a Project</h2>\r\n<ol type=\"1\">\r\n	<li>Open Visual Studio 2013. Load the HelloWorld solution which is located at <span class=\"lang:default decode:true  crayon-inline \">AF_PATH/examples/helloworld/helloworld.sln</span> .</li>\r\n	<li>Build the <span class=\"lang:default decode:true  crayon-inline \">helloworld</span>  example. Be sure to, select the platform/configuration of your choice using the platform drop-down (the options are CPU, CUDA, OpenCL, and Unified) and Solution Configuration drop down (options of Release and Debug) menus.</li>\r\n	<li>Run the <span class=\"lang:default decode:true  crayon-inline \">helloworld</span>  example.</li>\r\n</ol>\r\n<h2><a id=\"step3\" class=\"anchor\"></a>Step 3: Using ArrayFire within Visual Studio</h2>\r\nThis is divided into 4 parts:\r\n<ul>\r\n	<li><a href=\"#s3partA\">Part A: Adding ArrayFire to an existing solution (Single Backend)</a></li>\r\n	<li><a href=\"#s3partB\">Part B: Adding ArrayFire CUDA to a new/existing CUDA project</a></li>\r\n	<li><a href=\"#s3partC\">Part C: Project with all ArrayFire backends</a></li>\r\n	<li><a href=\"#s3partD\">Part D: ArrayFire with CMake</a></li>\r\n</ul>\r\n<h3><a id=\"s3partA\" class=\"anchor\"></a>Part A: Adding ArrayFire to an existing solution (Single Backend)</h3>\r\nNote: If you plan on using Native CUDA code in the project, use the steps under <a href=\"#s3partB\">Part B</a>.\r\n\r\nAdding a single backend to an existing project is quite simple.\r\n<ol type=\"1\">\r\n	<li>Add <code>\"<span class=\"lang:default decode:true  crayon-inline \">$(AF_PATH)/include;</span> \"</code> to <em>Project Properties -&gt; C/C++ -&gt; General -&gt; Additional Include Directories</em>.</li>\r\n	<li>Add <code>\"<span class=\"lang:default decode:true  crayon-inline \">$(AF_PATH)/lib;</span> \"</code> to <em>Project Properties -&gt; Linker -&gt; General -&gt; Additional Library Directories</em>.</li>\r\n	<li>Add <span class=\"lang:default decode:true  crayon-inline \">afcpu.lib</span>  or <span class=\"lang:default decode:true  crayon-inline \">afcuda.lib</span>  or <span class=\"lang:default decode:true  crayon-inline \">afopencl.lib</span>  to <em>Project Properties -&gt; Linker -&gt; Input -&gt; Additional Dependencies</em>. based on your preferred backend.</li>\r\n	<li>(Optional) You may choose to define <span class=\"lang:default decode:true  crayon-inline \">NOMINMAX, AF_&lt;CPU/CUDA/OPENCL&gt;</span>  and/or <span class=\"lang:default decode:true  crayon-inline \">AF_&lt;DEBUG/RELEASE&gt;</span>  in your projects. This can be added to <em>Project Properties -&gt; C/C++ -&gt; General -&gt; Preprocessor-&gt; Preprocessory definitions</em>.</li>\r\n</ol>\r\nIf you are using the CUDA backend, it is important to ensure that the CUDA NVVM DLLs are copied to the exectuable directory. This can be done by adding a post build event.\r\n\r\nOpen the <em>Project Properties -&gt; Build Events -&gt; Post Build Events</em> dialog and add the following lines to it.\r\n<div class=\"fragment\">\r\n<pre class=\"lang:default decode:true\">echo copy \"$(CUDA_PATH)\\nvvm\\bin\\nvvm64*.dll\" \"$(OutDir)\" \r\necho copy \"$(CUDA_PATH)\\nvvm\\bin\\nvvm64*.dll\" \"$(OutDir)\"</pre>\r\n<h3 class=\"line\"> <a id=\"s3partB\" class=\"anchor\"></a>Part B: Adding ArrayFire CUDA to a new/existing CUDA project</h3>\r\n</div>\r\nLastly, if your project contains custom CUDA code, the instructions are slightly different as it requires using a CUDA NVCC Project:\r\n<ol type=\"1\">\r\n	<li>Create a custom \"CUDA NVCC project\" in Visual Studio</li>\r\n	<li>Add <code>\"<span class=\"lang:default decode:true  crayon-inline \">$(AF_PATH)/include;</span> \"</code> to <em>Project Properties -&gt; CUDA C/C++ -&gt; General -&gt; Additional Include Directories</em>.</li>\r\n	<li>Add <code>\"<span class=\"lang:default decode:true  crayon-inline \">$(AF_PATH)/lib;</span> \"</code> to <em>Project Properties -&gt; Linker -&gt; General -&gt; Additional Library Directories</em>.</li>\r\n	<li>Add <span class=\"lang:default decode:true  crayon-inline \">afcpu.lib</span>  or <span class=\"lang:default decode:true  crayon-inline \">afcuda.lib</span>  or <span class=\"lang:default decode:true  crayon-inline \">afopencl.lib</span>  to <em>Project Properties -&gt; Linker -&gt; Input -&gt; Additional Dependencies</em>. based on your preferred backend.</li>\r\n	<li>(Optional) You may choose to define <span class=\"lang:default decode:true  crayon-inline \">NOMINMAX, AF_CUDA</span>  and/or <span class=\"lang:default decode:true  crayon-inline \">AF_&lt;DEBUG/RELEASE&gt;</span>  in your projects. This can be added to <em>Project Properties -&gt; C/C++ -&gt; General -&gt; Preprocessor-&gt; Preprocessory definitions</em>.</li>\r\n	<li>Pick a solution to handle the NVVM DLLs. We recommend the post build event method used in <a href=\"#s3partA\">Part A</a>.</li>\r\n</ol>\r\n<h3><a id=\"s3partC\" class=\"anchor\"></a>Part C: Project with all ArrayFire backends</h3>\r\nIf you wish to create a project that allows you to use all the ArrayFire backends with ease, the best way to go is to copy the <em>HelloWorld sln/vcxproj/cpp</em> file trio and rename them to suit your project.\r\n\r\nAll the ArrayFire examples are pre-configured for all ArrayFire backends as well as the Unified API. These can be chosen from the Solution/Platform configuration drop down boxes.\r\n\r\nYou can alternately download the template project from <a href=\"https://github.com/arrayfire/arrayfire-template-projects\">ArrayFire Template Projects</a>\r\n<h3><a id=\"s3partD\" class=\"anchor\"></a>Part D: ArrayFire with CMake</h3>\r\n<em>NOTE:</em> The ArrayFire installer sets up CMake file and registry so that it can be found by CMake by simply using the <span class=\"lang:default decode:true  crayon-inline \">Find_PACKAGE(ArrayFire)</span>  command.\r\n\r\nIf you are writing a new ArrayFire project in C/C++ from scratch, we suggest you grab a copy of our <a href=\"https://github.com/arrayfire/arrayfire-template-projects\">CMake Project Example</a>; however, it is useful to read the documentation below in case you need to add ArrayFire to an existing project.\r\n\r\nAs <a href=\"#big-picture\">discussed above</a>, ArrayFire ships with a series of CMake scripts to make finding and using our library easy. The scripts will automatically find all versions of the ArrayFire library and pick the most powerful of the installed backends (typically CUDA).\r\n\r\nFirst create a file called <span class=\"lang:default decode:true  crayon-inline \">CMakeLists.txt</span>  in your project directory:\r\n<pre class=\"fragment\">cd your-project-directory\r\ntouch CMakeLists.txt\r\n</pre>\r\nand populate it with the following code:\r\n<pre class=\"fragment\">FIND_PACKAGE(ArrayFire)\r\nINCLUDE_DIRECTORIES(${ArrayFire_INCLUDE_DIRS})\r\n\r\n... [gather source files, etc.]\r\n\r\n# If you intend to use OpenCL, you need to find it\r\nFIND_PACKAGE(OpenCL)\r\nSET(EXTRA_LIBS ${CMAKE_THREAD_LIBS_INIT} ${OpenCL_LIBRARIES})\r\n\r\n# Or if you intend to use CUDA, you need it as well as NVVM:\r\nFIND_PACKAGE(CUDA)\r\nFIND_PACKAGE(NVVM) # this FIND script can be found in the ArrayFire CMake example repository\r\nSET(EXTRA_LIBS ${CMAKE_THREAD_LIBS_INIT} ${CUDA_LIBRARIES} ${NVVM_LIB})\r\n\r\nADD_EXECUTABLE(my_executable [list your source files here])\r\nTARGET_LINK_LIBRARIES(my_executable ${ArrayFire_LIBRARIES} ${EXTRA_LIBS})\r\n</pre>\r\nwhere <span class=\"lang:default decode:true  crayon-inline \">my_executable</span>  is the name of the executable you wish to create. See the <a href=\"https://cmake.org/documentation/\">CMake documentation</a> for more information on how to use CMake. Clearly the above code snippet precludes the use of both CUDA and OpenCL, see the <a href=\"https://github.com/bkloppenborg/arrayfire-cmake-example\">ArrayFire CMake Example</a> for an example of how to build executables for both backends from the same CMake script.\r\n\r\nIn the above code listing, the <span class=\"lang:default decode:true  crayon-inline \">FIND_PACKAGE</span>  will find the ArrayFire include files, libraries, and define several variables including:\r\n<pre class=\"fragment\">ArrayFire_INCLUDE_DIRS    - Location of ArrayFire\'s include directory.\r\nArrayFire_LIBRARIES       - Location of ArrayFire\'s libraries.\r\n                            This will default to a GPU backend if one\r\n                            is found\r\nArrayFire_FOUND           - True if ArrayFire has been located\r\n</pre>\r\nIf you wish to use a specific backend, the find script also defines these variables:\r\n<pre class=\"fragment\">ArrayFire_CPU_FOUND         - True of the ArrayFire CPU library has been found.\r\nArrayFire_CPU_LIBRARIES     - Location of ArrayFire\'s CPU library, if found\r\nArrayFire_CUDA_FOUND        - True of the ArrayFire CUDA library has been found.\r\nArrayFire_CUDA_LIBRARIES    - Location of ArrayFire\'s CUDA library, if found\r\nArrayFire_OpenCL_FOUND      - True of the ArrayFire OpenCL library has been found.\r\nArrayFire_OpenCL_LIBRARIES  - Location of ArrayFire\'s OpenCL library, if found\r\nArrayFire_Unified_FOUND     - True of the ArrayFire Unified library has been found.\r\nArrayFire_Unified_LIBRARIES - Location of ArrayFire\'s Unified library, if found\r\n</pre>\r\nTherefore, if you wish to target a specific specific backend, simply replace <span class=\"lang:default decode:true  crayon-inline \">${ArrayFire_LIBRARIES}</span>  with <span class=\"lang:default decode:true  crayon-inline \">${ArrayFire_CPU}</span> ,<span class=\"lang:default decode:true  crayon-inline \"> ${ArrayFire_OPENCL}</span> , <span class=\"lang:default decode:true  crayon-inline \">${ArrayFire_CUDA}</span> , or <span class=\"lang:default decode:true  crayon-inline \">${ArrayFire_Unified}</span>  in the <span class=\"lang:default decode:true  crayon-inline \">TARGET_LINK_LIBRARIES</span>  command above.\r\n\r\nNext we need to instruct CMake to create build instructions and then compile. We suggest using CMake\'s out-of-source build functionality to keep your build and source files cleanly separated. To do this open the CMake GUI.\r\n<ul>\r\n	<li>Under source directory, add the path to your project</li>\r\n	<li>Under build directory, add the path to your project and append /build</li>\r\n	<li>Click configure and choose Visual Studio 2013 Win 64 as the generator.</li>\r\n	<li>If configuration was successful, click generate. This will create a my-project.sln file under build. You can open this in Visual Studio and compile the ALL_BUILD project.</li>\r\n</ul>\r\nThe <a href=\"https://github.com/bkloppenborg/arrayfire-cmake-example\">ArrayFire CMake Example</a> is a CMake project used to demo how ArrayFire can be using with a CMake project.\r\n\r\nNote: The CMake project does not add the post build event to copy the NVVM DLLs in case of CUDA backend. You will need to either copy it manually to the exectuable directory, or pick another solution for it.\r\n\r\n</div>\r\n</div>','Setting up an ArrayFire project on Windows','','inherit','open','closed','','8546-revision-v1','','','2015-11-04 16:49:27','2015-11-04 16:49:27','',8546,'http://sandbox.arrayfire.com/8546-revision-v1/',0,'revision','',0),(8584,11,'2015-11-04 16:51:21','2015-11-04 16:51:21','<div class=\"header\">\r\n<div class=\"headertitle\">\r\n<div class=\"title\">Continuing our blog series \"<a href=\"http://sandbox.arrayfire.com/tag/learning-arrayfire-from-scratch/\">Learning ArrayFire from scratch</a>\" today we will discuss how to set up an ArrayFire project on Windows using Visual Studio or CMake.</div>\r\n</div>\r\n</div>\r\n<!--more-->\r\n\r\nIf you have not already done so, please make sure you have installed, configured, and tested ArrayFire following the <a class=\"el\" href=\"installing.htm\">installation instructions</a>.\r\n<div class=\"contents\">\r\n<div class=\"textblock\">\r\n<h2>The big picture</h2>\r\nThe ArrayFire Windows installer creates the following:\r\n<pre class=\"lang:default decode:true\">AF_PATH                 Environment variable to point to the installation location.\r\n                        This is normally C:/Program Files/ArrayFire/v*\r\nAF_PATH/include         Header files for ArrayFire (Include Dir)\r\nAF_PATH/lib             All ArrayFire backends libraries, dlls and dependency dlls \r\n                        (Library dir)\r\nAF_PATH/examples        Examples to get started. Some examples also have pre-built \r\n                        exectuables\r\nAF_PATH/cmake           CMake config files for automatic configuration by external \r\n                        projects\r\nAF_PATH/uninstall.exe   Uninstaller\r\nAF_PATH/*               Other miscellenous files including licenses, logos, copyrights</pre>\r\nThe installer also appends <span class=\"lang:default decode:true  crayon-inline \">%AF_PATH%/lib</span>  to the User <span class=\"lang:default decode:true  crayon-inline \">PATH</span>  variable (see the <a class=\"el\" href=\"installing.htm\">installation instructions</a> for further details).\r\n<h3>Dealing with CUDA NMMV DLLs</h3>\r\nWhen using CUDA with ArrayFire you may encounter a linker error indicating the NVVM DLLs are missing. This is because the NVVM DLLs are not part of the standard <span class=\"lang:default decode:true  crayon-inline \">CUDA_PATH\\bin</span>  installation directory that is added to your <span class=\"lang:default decode:true  crayon-inline \">PATH</span>  when the CUDA installer runs. Thus, NVVM will not be found during the linking stage. There are a few ways to deal with this issue:\r\n\r\n&nbsp;\r\n<ol type=\"1\">\r\n	<li>Copy the DLLs to the executable location. This is, by far, the cleanest solution and we recommend doing this with ArrayFire projects. To do so, create a post-build event to copy the NVVM DLL as discussed below in <a href=\"#s3partA\">Step 3 - Part A</a>.</li>\r\n	<li>Copy <span class=\"lang:default decode:true  crayon-inline\">CUDA_PATH\\nvvm\\bin\\nvvm64_30_0.dll</span>  to <span class=\"lang:default decode:true  crayon-inline \">CUDA_PATH\\bin</span> . This is a one time copy such that the NVVM DLL is now with all the other CUDA dlls and in a directory that is a part of PATH and hence the DLL can be detected automatically.</li>\r\n	<li>Add <span class=\"lang:default decode:true  crayon-inline \">%CUDA_PATH%\\nvvm\\bin</span>  to the system PATH environment variable. This will allow automatic detection by the system and No further copying will be required. ArrayFire does not add this to PATH since the CUDA installer doesn\'t add it to PATH.</li>\r\n</ol>\r\n<h2><a id=\"step1\" class=\"anchor\"></a>Step 1: Running pre-built executables</h2>\r\nThe ArrayFire installer ships with a few pre-built executables with the examples. These should run out of the box when double clicked.\r\n\r\nSome prebuilt examples are:\r\n<ul>\r\n	<li>Helloworld (examples/helloworld)</li>\r\n	<li>BLAS (examples/benchmarks)</li>\r\n	<li>FFT (examples/benchmarks)</li>\r\n	<li>Pi Estimation (examples/benchmarks)</li>\r\n	<li>Conway (Graphics) (examples/graphics)</li>\r\n</ul>\r\nNote: For the CUDA executables, you will need to copy <span class=\"lang:default decode:true  crayon-inline \">CUDA_PATH\\nvvm\\bin\\nvvm64_30_0.dll</span>  to the location of the executables.\r\n<h2><a id=\"step2\" class=\"anchor\"></a>Step 2: Build and Run a Project</h2>\r\n<ol type=\"1\">\r\n	<li>Open Visual Studio 2013. Load the HelloWorld solution which is located at <span class=\"lang:default decode:true  crayon-inline \">AF_PATH/examples/helloworld/helloworld.sln</span> .</li>\r\n	<li>Build the <span class=\"lang:default decode:true  crayon-inline \">helloworld</span>  example. Be sure to, select the platform/configuration of your choice using the platform drop-down (the options are CPU, CUDA, OpenCL, and Unified) and Solution Configuration drop down (options of Release and Debug) menus.</li>\r\n	<li>Run the <span class=\"lang:default decode:true  crayon-inline \">helloworld</span>  example.</li>\r\n</ol>\r\n<h2><a id=\"step3\" class=\"anchor\"></a>Step 3: Using ArrayFire within Visual Studio</h2>\r\nThis is divided into 4 parts:\r\n<ul>\r\n	<li><a href=\"#s3partA\">Part A: Adding ArrayFire to an existing solution (Single Backend)</a></li>\r\n	<li><a href=\"#s3partB\">Part B: Adding ArrayFire CUDA to a new/existing CUDA project</a></li>\r\n	<li><a href=\"#s3partC\">Part C: Project with all ArrayFire backends</a></li>\r\n	<li><a href=\"#s3partD\">Part D: ArrayFire with CMake</a></li>\r\n</ul>\r\n<h3><a id=\"s3partA\" class=\"anchor\"></a>Part A: Adding ArrayFire to an existing solution (Single Backend)</h3>\r\nNote: If you plan on using Native CUDA code in the project, use the steps under <a href=\"#s3partB\">Part B</a>.\r\n\r\nAdding a single backend to an existing project is quite simple.\r\n<ol type=\"1\">\r\n	<li>Add <code>\"<span class=\"lang:default decode:true  crayon-inline \">$(AF_PATH)/include;</span> \"</code> to <em>Project Properties -&gt; C/C++ -&gt; General -&gt; Additional Include Directories</em>.</li>\r\n	<li>Add <code>\"<span class=\"lang:default decode:true  crayon-inline \">$(AF_PATH)/lib;</span> \"</code> to <em>Project Properties -&gt; Linker -&gt; General -&gt; Additional Library Directories</em>.</li>\r\n	<li>Add <span class=\"lang:default decode:true  crayon-inline \">afcpu.lib</span>  or <span class=\"lang:default decode:true  crayon-inline \">afcuda.lib</span>  or <span class=\"lang:default decode:true  crayon-inline \">afopencl.lib</span>  to <em>Project Properties -&gt; Linker -&gt; Input -&gt; Additional Dependencies</em>. based on your preferred backend.</li>\r\n	<li>(Optional) You may choose to define <span class=\"lang:default decode:true  crayon-inline \">NOMINMAX, AF_&lt;CPU/CUDA/OPENCL&gt;</span>  and/or <span class=\"lang:default decode:true  crayon-inline \">AF_&lt;DEBUG/RELEASE&gt;</span>  in your projects. This can be added to <em>Project Properties -&gt; C/C++ -&gt; General -&gt; Preprocessor-&gt; Preprocessory definitions</em>.</li>\r\n</ol>\r\nIf you are using the CUDA backend, it is important to ensure that the CUDA NVVM DLLs are copied to the exectuable directory. This can be done by adding a post build event.\r\n\r\nOpen the <em>Project Properties -&gt; Build Events -&gt; Post Build Events</em> dialog and add the following lines to it.\r\n<div class=\"fragment\">\r\n<pre class=\"lang:default decode:true\">echo copy \"$(CUDA_PATH)\\nvvm\\bin\\nvvm64*.dll\" \"$(OutDir)\" \r\necho copy \"$(CUDA_PATH)\\nvvm\\bin\\nvvm64*.dll\" \"$(OutDir)\"</pre>\r\n<h3 class=\"line\"> <a id=\"s3partB\" class=\"anchor\"></a>Part B: Adding ArrayFire CUDA to a new/existing CUDA project</h3>\r\n</div>\r\nLastly, if your project contains custom CUDA code, the instructions are slightly different as it requires using a CUDA NVCC Project:\r\n<ol type=\"1\">\r\n	<li>Create a custom \"CUDA NVCC project\" in Visual Studio</li>\r\n	<li>Add <code>\"<span class=\"lang:default decode:true  crayon-inline \">$(AF_PATH)/include;</span> \"</code> to <em>Project Properties -&gt; CUDA C/C++ -&gt; General -&gt; Additional Include Directories</em>.</li>\r\n	<li>Add <code>\"<span class=\"lang:default decode:true  crayon-inline \">$(AF_PATH)/lib;</span> \"</code> to <em>Project Properties -&gt; Linker -&gt; General -&gt; Additional Library Directories</em>.</li>\r\n	<li>Add <span class=\"lang:default decode:true  crayon-inline \">afcpu.lib</span>  or <span class=\"lang:default decode:true  crayon-inline \">afcuda.lib</span>  or <span class=\"lang:default decode:true  crayon-inline \">afopencl.lib</span>  to <em>Project Properties -&gt; Linker -&gt; Input -&gt; Additional Dependencies</em>. based on your preferred backend.</li>\r\n	<li>(Optional) You may choose to define <span class=\"lang:default decode:true  crayon-inline \">NOMINMAX, AF_CUDA</span>  and/or <span class=\"lang:default decode:true  crayon-inline \">AF_&lt;DEBUG/RELEASE&gt;</span>  in your projects. This can be added to <em>Project Properties -&gt; C/C++ -&gt; General -&gt; Preprocessor-&gt; Preprocessory definitions</em>.</li>\r\n	<li>Pick a solution to handle the NVVM DLLs. We recommend the post build event method used in <a href=\"#s3partA\">Part A</a>.</li>\r\n</ol>\r\n<h3><a id=\"s3partC\" class=\"anchor\"></a>Part C: Project with all ArrayFire backends</h3>\r\nIf you wish to create a project that allows you to use all the ArrayFire backends with ease, the best way to go is to copy the <em>HelloWorld sln/vcxproj/cpp</em> file trio and rename them to suit your project.\r\n\r\nAll the ArrayFire examples are pre-configured for all ArrayFire backends as well as the Unified API. These can be chosen from the Solution/Platform configuration drop down boxes.\r\n\r\nYou can alternately download the template project from <a href=\"https://github.com/arrayfire/arrayfire-template-projects\">ArrayFire Template Projects</a>\r\n<h3><a id=\"s3partD\" class=\"anchor\"></a>Part D: ArrayFire with CMake</h3>\r\n<em>NOTE:</em> The ArrayFire installer sets up CMake file and registry so that it can be found by CMake by simply using the <span class=\"lang:default decode:true  crayon-inline \">Find_PACKAGE(ArrayFire)</span>  command.\r\n\r\nIf you are writing a new ArrayFire project in C/C++ from scratch, we suggest you grab a copy of our <a href=\"https://github.com/arrayfire/arrayfire-template-projects\">CMake Project Example</a>; however, it is useful to read the documentation below in case you need to add ArrayFire to an existing project.\r\n\r\nAs <a href=\"#big-picture\">discussed above</a>, ArrayFire ships with a series of CMake scripts to make finding and using our library easy. The scripts will automatically find all versions of the ArrayFire library and pick the most powerful of the installed backends (typically CUDA).\r\n\r\nFirst create a file called <span class=\"lang:default decode:true  crayon-inline \">CMakeLists.txt</span>  in your project directory:\r\n<pre class=\"fragment\">cd your-project-directory\r\ntouch CMakeLists.txt\r\n</pre>\r\nand populate it with the following code:\r\n<pre class=\"fragment\">FIND_PACKAGE(ArrayFire)\r\nINCLUDE_DIRECTORIES(${ArrayFire_INCLUDE_DIRS})\r\n\r\n... [gather source files, etc.]\r\n\r\n# If you intend to use OpenCL, you need to find it\r\nFIND_PACKAGE(OpenCL)\r\nSET(EXTRA_LIBS ${CMAKE_THREAD_LIBS_INIT} ${OpenCL_LIBRARIES})\r\n\r\n# Or if you intend to use CUDA, you need it as well as NVVM:\r\nFIND_PACKAGE(CUDA)\r\nFIND_PACKAGE(NVVM) # this FIND script can be found in the ArrayFire CMake example repository\r\nSET(EXTRA_LIBS ${CMAKE_THREAD_LIBS_INIT} ${CUDA_LIBRARIES} ${NVVM_LIB})\r\n\r\nADD_EXECUTABLE(my_executable [list your source files here])\r\nTARGET_LINK_LIBRARIES(my_executable ${ArrayFire_LIBRARIES} ${EXTRA_LIBS})\r\n</pre>\r\nwhere <span class=\"lang:default decode:true  crayon-inline \">my_executable</span>  is the name of the executable you wish to create. See the <a href=\"https://cmake.org/documentation/\">CMake documentation</a> for more information on how to use CMake. Clearly the above code snippet precludes the use of both CUDA and OpenCL, see the <a href=\"https://github.com/bkloppenborg/arrayfire-cmake-example\">ArrayFire CMake Example</a> for an example of how to build executables for both backends from the same CMake script.\r\n\r\nIn the above code listing, the <span class=\"lang:default decode:true  crayon-inline \">FIND_PACKAGE</span>  will find the ArrayFire include files, libraries, and define several variables including:\r\n<pre class=\"fragment\">ArrayFire_INCLUDE_DIRS    - Location of ArrayFire\'s include directory.\r\nArrayFire_LIBRARIES       - Location of ArrayFire\'s libraries.\r\n                            This will default to a GPU backend if one\r\n                            is found\r\nArrayFire_FOUND           - True if ArrayFire has been located\r\n</pre>\r\nIf you wish to use a specific backend, the find script also defines these variables:\r\n<pre class=\"fragment\">ArrayFire_CPU_FOUND         - True of the ArrayFire CPU library has been found.\r\nArrayFire_CPU_LIBRARIES     - Location of ArrayFire\'s CPU library, if found\r\nArrayFire_CUDA_FOUND        - True of the ArrayFire CUDA library has been found.\r\nArrayFire_CUDA_LIBRARIES    - Location of ArrayFire\'s CUDA library, if found\r\nArrayFire_OpenCL_FOUND      - True of the ArrayFire OpenCL library has been found.\r\nArrayFire_OpenCL_LIBRARIES  - Location of ArrayFire\'s OpenCL library, if found\r\nArrayFire_Unified_FOUND     - True of the ArrayFire Unified library has been found.\r\nArrayFire_Unified_LIBRARIES - Location of ArrayFire\'s Unified library, if found\r\n</pre>\r\nTherefore, if you wish to target a specific specific backend, simply replace <span class=\"lang:default decode:true  crayon-inline \">${ArrayFire_LIBRARIES}</span>  with <span class=\"lang:default decode:true  crayon-inline \">${ArrayFire_CPU}</span> ,<span class=\"lang:default decode:true  crayon-inline \"> ${ArrayFire_OPENCL}</span> , <span class=\"lang:default decode:true  crayon-inline \">${ArrayFire_CUDA}</span> , or <span class=\"lang:default decode:true  crayon-inline \">${ArrayFire_Unified}</span>  in the <span class=\"lang:default decode:true  crayon-inline \">TARGET_LINK_LIBRARIES</span>  command above.\r\n\r\nNext we need to instruct CMake to create build instructions and then compile. We suggest using CMake\'s out-of-source build functionality to keep your build and source files cleanly separated. To do this open the CMake GUI.\r\n<ul>\r\n	<li>Under source directory, add the path to your project</li>\r\n	<li>Under build directory, add the path to your project and append /build</li>\r\n	<li>Click configure and choose Visual Studio 2013 Win 64 as the generator.</li>\r\n	<li>If configuration was successful, click generate. This will create a my-project.sln file under build. You can open this in Visual Studio and compile the ALL_BUILD project.</li>\r\n</ul>\r\nThe <a href=\"https://github.com/bkloppenborg/arrayfire-cmake-example\">ArrayFire CMake Example</a> is a CMake project used to demo how ArrayFire can be using with a CMake project.\r\n\r\nNote: The CMake project does not add the post build event to copy the NVVM DLLs in case of CUDA backend. You will need to either copy it manually to the exectuable directory, or pick another solution for it.\r\n\r\n</div>\r\n</div>','Setting up an ArrayFire project on Windows','','inherit','open','closed','','8546-revision-v1','','','2015-11-04 16:51:21','2015-11-04 16:51:21','',8546,'http://sandbox.arrayfire.com/8546-revision-v1/',0,'revision','',0),(8585,18528,'2015-11-06 13:56:56','2015-11-06 13:56:56','<div class=\"header\">\n<div class=\"headertitle\">\n<div class=\"title\">Continuing our blog series \"<a href=\"http://sandbox.arrayfire.com/tag/learning-arrayfire-from-scratch/\">Learning ArrayFire from scratch</a>\" today we will discuss how to set up an ArrayFire project on Windows using Visual Studio or CMake.</div>\n</div>\n</div>\n<!--more-->\n\nIf you have not already done so, please make sure you have installed, configured, and tested ArrayFire following the <a class=\"el\" href=\"installing.htm\">installation instructions</a>.\n<div class=\"contents\">\n<div class=\"textblock\">\n<h2>The big picture</h2>\nThe ArrayFire Windows installer creates the following:\n<pre class=\"lang:default decode:true\">AF_PATH                 Environment variable to point to the installation location.\n                        This is normally C:/Program Files/ArrayFire/v*\nAF_PATH/include         Header files for ArrayFire (Include Dir)\nAF_PATH/lib             All ArrayFire backends libraries, dlls and dependency dlls \n                        (Library dir)\nAF_PATH/examples        Examples to get started. Some examples also have pre-built \n                        exectuables\nAF_PATH/cmake           CMake config files for automatic configuration by external \n                        projects\nAF_PATH/uninstall.exe   Uninstaller\nAF_PATH/*               Other miscellenous files including licenses, logos, copyrights</pre>\nThe installer also appends <span class=\"lang:default decode:true  crayon-inline \">%AF_PATH%/lib</span>  to the User <span class=\"lang:default decode:true  crayon-inline \">PATH</span>  variable (see the <a class=\"el\" href=\"installing.htm\">installation instructions</a> for further details).\n<h4>Dealing with CUDA NVVM DLLs</h4>\nWhen using CUDA with ArrayFire you may encounter a linker error indicating the NVVM DLLs are missing. This is because the NVVM DLLs are not part of the standard <span class=\"lang:default decode:true  crayon-inline \">CUDA_PATH\\bin</span>  installation directory that is added to your <span class=\"lang:default decode:true  crayon-inline \">PATH</span>  when the CUDA installer runs. Thus, NVVM will not be found during the linking stage. There are a few ways to deal with this issue:\n\n&nbsp;\n<ol type=\"1\">\n	<li>Copy the DLLs to the executable location. This is, by far, the cleanest solution and we recommend doing this with ArrayFire projects. To do so, create a post-build event to copy the NVVM DLL as discussed below in <a href=\"#s3partA\">Step 3 - Part A</a>.</li>\n	<li>Copy <span class=\"lang:default decode:true  crayon-inline\">CUDA_PATH\\nvvm\\bin\\nvvm64_30_0.dll</span>  to <span class=\"lang:default decode:true  crayon-inline \">CUDA_PATH\\bin</span> . This is a one time copy such that the NVVM DLL is now with all the other CUDA dlls and in a directory that is a part of PATH and hence the DLL can be detected automatically.</li>\n	<li>Add <span class=\"lang:default decode:true  crayon-inline \">%CUDA_PATH%\\nvvm\\bin</span>  to the system PATH environment variable. This will allow automatic detection by the system and No further copying will be required. ArrayFire does not add this to PATH since the CUDA installer doesn\'t add it to PATH.</li>\n</ol>\n<h3><a id=\"step1\" class=\"anchor\"></a>Step 1: Running pre-built executables</h3>\nThe ArrayFire installer ships with a few pre-built executables with the examples. These should run out of the box when double clicked.\n\nSome prebuilt examples are:\n<ul>\n	<li>Helloworld (examples/helloworld)</li>\n	<li>BLAS (examples/benchmarks)</li>\n	<li>FFT (examples/benchmarks)</li>\n	<li>Pi Estimation (examples/benchmarks)</li>\n	<li>Conway (Graphics) (examples/graphics)</li>\n</ul>\nNote: For the CUDA executables, you will need to copy <span class=\"lang:default decode:true  crayon-inline \">CUDA_PATH\\nvvm\\bin\\nvvm64_30_0.dll</span>  to the location of the executables.\n<h3><a id=\"step2\" class=\"anchor\"></a>Step 2: Build and Run a Project</h3>\n<ol type=\"1\">\n	<li>Open Visual Studio 2013. Load the HelloWorld solution which is located at <span class=\"lang:default decode:true  crayon-inline \">AF_PATH/examples/helloworld/helloworld.sln</span> .</li>\n	<li>Build the <span class=\"lang:default decode:true  crayon-inline \">helloworld</span>  example. Be sure to, select the platform/configuration of your choice using the platform drop-down (the options are CPU, CUDA, OpenCL, and Unified) and Solution Configuration drop down (options of Release and Debug) menus.</li>\n	<li>Run the <span class=\"lang:default decode:true  crayon-inline \">helloworld</span>  example.</li>\n</ol>\n<h2><a id=\"step3\" class=\"anchor\"></a>Step 3: Using ArrayFire within Visual Studio</h2>\nThis is divided into 4 parts:\n<ul>\n	<li><a href=\"#s3partA\">Part A: Adding ArrayFire to an existing solution (Single Backend)</a></li>\n	<li><a href=\"#s3partB\">Part B: Adding ArrayFire CUDA to a new/existing CUDA project</a></li>\n	<li><a href=\"#s3partC\">Part C: Project with all ArrayFire backends</a></li>\n	<li><a href=\"#s3partD\">Part D: ArrayFire with CMake</a></li>\n</ul>\n<h3><a id=\"s3partA\" class=\"anchor\"></a>Part A: Adding ArrayFire to an existing solution (Single Backend)</h3>\nNote: If you plan on using Native CUDA code in the project, use the steps under <a href=\"#s3partB\">Part B</a>.\n\nAdding a single backend to an existing project is quite simple.\n<ol type=\"1\">\n	<li>Add <code>\"<span class=\"lang:default decode:true  crayon-inline \">$(AF_PATH)/include;</span> \"</code> to <em>Project Properties -&gt; C/C++ -&gt; General -&gt; Additional Include Directories</em>.</li>\n	<li>Add <code>\"<span class=\"lang:default decode:true  crayon-inline \">$(AF_PATH)/lib;</span> \"</code> to <em>Project Properties -&gt; Linker -&gt; General -&gt; Additional Library Directories</em>.</li>\n	<li>Add <span class=\"lang:default decode:true  crayon-inline \">afcpu.lib</span>  or <span class=\"lang:default decode:true  crayon-inline \">afcuda.lib</span>  or <span class=\"lang:default decode:true  crayon-inline \">afopencl.lib</span>  to <em>Project Properties -&gt; Linker -&gt; Input -&gt; Additional Dependencies</em>. based on your preferred backend.</li>\n	<li>(Optional) You may choose to define <span class=\"lang:default decode:true  crayon-inline \">NOMINMAX, AF_&lt;CPU/CUDA/OPENCL&gt;</span>  and/or <span class=\"lang:default decode:true  crayon-inline \">AF_&lt;DEBUG/RELEASE&gt;</span>  in your projects. This can be added to <em>Project Properties -&gt; C/C++ -&gt; General -&gt; Preprocessor-&gt; Preprocessory definitions</em>.</li>\n</ol>\nIf you are using the CUDA backend, it is important to ensure that the CUDA NVVM DLLs are copied to the exectuable directory. This can be done by adding a post build event.\n\nOpen the <em>Project Properties -&gt; Build Events -&gt; Post Build Events</em> dialog and add the following lines to it.\n<div class=\"fragment\">\n<pre class=\"lang:default decode:true\">echo copy \"$(CUDA_PATH)\\nvvm\\bin\\nvvm64*.dll\" \"$(OutDir)\" \necho copy \"$(CUDA_PATH)\\nvvm\\bin\\nvvm64*.dll\" \"$(OutDir)\"</pre>\n<h3 class=\"line\"> <a id=\"s3partB\" class=\"anchor\"></a>Part B: Adding ArrayFire CUDA to a new/existing CUDA project</h3>\n</div>\nLastly, if your project contains custom CUDA code, the instructions are slightly different as it requires using a CUDA NVCC Project:\n<ol type=\"1\">\n	<li>Create a custom \"CUDA NVCC project\" in Visual Studio</li>\n	<li>Add <code>\"<span class=\"lang:default decode:true  crayon-inline \">$(AF_PATH)/include;</span> \"</code> to <em>Project Properties -&gt; CUDA C/C++ -&gt; General -&gt; Additional Include Directories</em>.</li>\n	<li>Add <code>\"<span class=\"lang:default decode:true  crayon-inline \">$(AF_PATH)/lib;</span> \"</code> to <em>Project Properties -&gt; Linker -&gt; General -&gt; Additional Library Directories</em>.</li>\n	<li>Add <span class=\"lang:default decode:true  crayon-inline \">afcpu.lib</span>  or <span class=\"lang:default decode:true  crayon-inline \">afcuda.lib</span>  or <span class=\"lang:default decode:true  crayon-inline \">afopencl.lib</span>  to <em>Project Properties -&gt; Linker -&gt; Input -&gt; Additional Dependencies</em>. based on your preferred backend.</li>\n	<li>(Optional) You may choose to define <span class=\"lang:default decode:true  crayon-inline \">NOMINMAX, AF_CUDA</span>  and/or <span class=\"lang:default decode:true  crayon-inline \">AF_&lt;DEBUG/RELEASE&gt;</span>  in your projects. This can be added to <em>Project Properties -&gt; C/C++ -&gt; General -&gt; Preprocessor-&gt; Preprocessory definitions</em>.</li>\n	<li>Pick a solution to handle the NVVM DLLs. We recommend the post build event method used in <a href=\"#s3partA\">Part A</a>.</li>\n</ol>\n<h3><a id=\"s3partC\" class=\"anchor\"></a>Part C: Project with all ArrayFire backends</h3>\nIf you wish to create a project that allows you to use all the ArrayFire backends with ease, the best way to go is to copy the <em>HelloWorld sln/vcxproj/cpp</em> file trio and rename them to suit your project.\n\nAll the ArrayFire examples are pre-configured for all ArrayFire backends as well as the Unified API. These can be chosen from the Solution/Platform configuration drop down boxes.\n\nYou can alternately download the template project from <a href=\"https://github.com/arrayfire/arrayfire-template-projects\">ArrayFire Template Projects</a>\n<h3><a id=\"s3partD\" class=\"anchor\"></a>Part D: ArrayFire with CMake</h3>\n<em>NOTE:</em> The ArrayFire installer sets up CMake file and registry so that it can be found by CMake by simply using the <span class=\"lang:default decode:true  crayon-inline \">Find_PACKAGE(ArrayFire)</span>  command.\n\nIf you are writing a new ArrayFire project in C/C++ from scratch, we suggest you grab a copy of our <a href=\"https://github.com/arrayfire/arrayfire-template-projects\">CMake Project Example</a>; however, it is useful to read the documentation below in case you need to add ArrayFire to an existing project.\n\nAs <a href=\"#big-picture\">discussed above</a>, ArrayFire ships with a series of CMake scripts to make finding and using our library easy. The scripts will automatically find all versions of the ArrayFire library and pick the most powerful of the installed backends (typically CUDA).\n\nFirst create a file called <span class=\"lang:default decode:true  crayon-inline \">CMakeLists.txt</span>  in your project directory:\n<pre class=\"fragment\">cd your-project-directory\ntouch CMakeLists.txt\n</pre>\nand populate it with the following code:\n<pre class=\"fragment\">FIND_PACKAGE(ArrayFire)\nINCLUDE_DIRECTORIES(${ArrayFire_INCLUDE_DIRS})\n\n... [gather source files, etc.]\n\n# If you intend to use OpenCL, you need to find it\nFIND_PACKAGE(OpenCL)\nSET(EXTRA_LIBS ${CMAKE_THREAD_LIBS_INIT} ${OpenCL_LIBRARIES})\n\n# Or if you intend to use CUDA, you need it as well as NVVM:\nFIND_PACKAGE(CUDA)\nFIND_PACKAGE(NVVM) # this FIND script can be found in the ArrayFire CMake example repository\nSET(EXTRA_LIBS ${CMAKE_THREAD_LIBS_INIT} ${CUDA_LIBRARIES} ${NVVM_LIB})\n\nADD_EXECUTABLE(my_executable [list your source files here])\nTARGET_LINK_LIBRARIES(my_executable ${ArrayFire_LIBRARIES} ${EXTRA_LIBS})\n</pre>\nwhere <span class=\"lang:default decode:true  crayon-inline \">my_executable</span>  is the name of the executable you wish to create. See the <a href=\"https://cmake.org/documentation/\">CMake documentation</a> for more information on how to use CMake. Clearly the above code snippet precludes the use of both CUDA and OpenCL, see the <a href=\"https://github.com/bkloppenborg/arrayfire-cmake-example\">ArrayFire CMake Example</a> for an example of how to build executables for both backends from the same CMake script.\n\nIn the above code listing, the <span class=\"lang:default decode:true  crayon-inline \">FIND_PACKAGE</span>  will find the ArrayFire include files, libraries, and define several variables including:\n<pre class=\"fragment\">ArrayFire_INCLUDE_DIRS    - Location of ArrayFire\'s include directory.\nArrayFire_LIBRARIES       - Location of ArrayFire\'s libraries.\n                            This will default to a GPU backend if one\n                            is found\nArrayFire_FOUND           - True if ArrayFire has been located\n</pre>\nIf you wish to use a specific backend, the find script also defines these variables:\n<pre class=\"fragment\">ArrayFire_CPU_FOUND         - True of the ArrayFire CPU library has been found.\nArrayFire_CPU_LIBRARIES     - Location of ArrayFire\'s CPU library, if found\nArrayFire_CUDA_FOUND        - True of the ArrayFire CUDA library has been found.\nArrayFire_CUDA_LIBRARIES    - Location of ArrayFire\'s CUDA library, if found\nArrayFire_OpenCL_FOUND      - True of the ArrayFire OpenCL library has been found.\nArrayFire_OpenCL_LIBRARIES  - Location of ArrayFire\'s OpenCL library, if found\nArrayFire_Unified_FOUND     - True of the ArrayFire Unified library has been found.\nArrayFire_Unified_LIBRARIES - Location of ArrayFire\'s Unified library, if found\n</pre>\nTherefore, if you wish to target a specific specific backend, simply replace <span class=\"lang:default decode:true  crayon-inline \">${ArrayFire_LIBRARIES}</span>  with <span class=\"lang:default decode:true  crayon-inline \">${ArrayFire_CPU}</span> ,<span class=\"lang:default decode:true  crayon-inline \"> ${ArrayFire_OPENCL}</span> , <span class=\"lang:default decode:true  crayon-inline \">${ArrayFire_CUDA}</span> , or <span class=\"lang:default decode:true  crayon-inline \">${ArrayFire_Unified}</span>  in the <span class=\"lang:default decode:true  crayon-inline \">TARGET_LINK_LIBRARIES</span>  command above.\n\nNext we need to instruct CMake to create build instructions and then compile. We suggest using CMake\'s out-of-source build functionality to keep your build and source files cleanly separated. To do this open the CMake GUI.\n<ul>\n	<li>Under source directory, add the path to your project</li>\n	<li>Under build directory, add the path to your project and append /build</li>\n	<li>Click configure and choose Visual Studio 2013 Win 64 as the generator.</li>\n	<li>If configuration was successful, click generate. This will create a my-project.sln file under build. You can open this in Visual Studio and compile the ALL_BUILD project.</li>\n</ul>\nThe <a href=\"https://github.com/bkloppenborg/arrayfire-cmake-example\">ArrayFire CMake Example</a> is a CMake project used to demo how ArrayFire can be using with a CMake project.\n\nNote: The CMake project does not add the post build event to copy the NVVM DLLs in case of CUDA backend. You will need to either copy it manually to the exectuable directory, or pick another solution for it.\n\n</div>\n</div>','Setting up an ArrayFire project on Windows','','inherit','open','closed','','8546-autosave-v1','','','2015-11-06 13:56:56','2015-11-06 13:56:56','',8546,'http://sandbox.arrayfire.com/8546-autosave-v1/',0,'revision','',0),(8586,18528,'2015-11-06 13:57:18','2015-11-06 13:57:18','<div class=\"header\">\r\n<div class=\"headertitle\">\r\n<div class=\"title\">Continuing our blog series \"<a href=\"http://sandbox.arrayfire.com/tag/learning-arrayfire-from-scratch/\">Learning ArrayFire from scratch</a>\" today we will discuss how to set up an ArrayFire project on Windows using Visual Studio or CMake.</div>\r\n</div>\r\n</div>\r\n<!--more-->\r\n\r\nIf you have not already done so, please make sure you have installed, configured, and tested ArrayFire following the <a class=\"el\" href=\"installing.htm\">installation instructions</a>.\r\n<div class=\"contents\">\r\n<div class=\"textblock\">\r\n<h2>The big picture</h2>\r\nThe ArrayFire Windows installer creates the following:\r\n<pre class=\"lang:default decode:true\">AF_PATH                 Environment variable to point to the installation location.\r\n                        This is normally C:/Program Files/ArrayFire/v*\r\nAF_PATH/include         Header files for ArrayFire (Include Dir)\r\nAF_PATH/lib             All ArrayFire backends libraries, dlls and dependency dlls \r\n                        (Library dir)\r\nAF_PATH/examples        Examples to get started. Some examples also have pre-built \r\n                        exectuables\r\nAF_PATH/cmake           CMake config files for automatic configuration by external \r\n                        projects\r\nAF_PATH/uninstall.exe   Uninstaller\r\nAF_PATH/*               Other miscellenous files including licenses, logos, copyrights</pre>\r\nThe installer also appends <span class=\"lang:default decode:true  crayon-inline \">%AF_PATH%/lib</span>  to the User <span class=\"lang:default decode:true  crayon-inline \">PATH</span>  variable (see the <a class=\"el\" href=\"installing.htm\">installation instructions</a> for further details).\r\n<h4>Dealing with CUDA NVVM DLLs</h4>\r\nWhen using CUDA with ArrayFire you may encounter a linker error indicating the NVVM DLLs are missing. This is because the NVVM DLLs are not part of the standard <span class=\"lang:default decode:true  crayon-inline \">CUDA_PATH\\bin</span>  installation directory that is added to your <span class=\"lang:default decode:true  crayon-inline \">PATH</span>  when the CUDA installer runs. Thus, NVVM will not be found during the linking stage. There are a few ways to deal with this issue:\r\n\r\n&nbsp;\r\n<ol type=\"1\">\r\n	<li>Copy the DLLs to the executable location. This is, by far, the cleanest solution and we recommend doing this with ArrayFire projects. To do so, create a post-build event to copy the NVVM DLL as discussed below in <a href=\"#s3partA\">Step 3 - Part A</a>.</li>\r\n	<li>Copy <span class=\"lang:default decode:true  crayon-inline\">CUDA_PATH\\nvvm\\bin\\nvvm64_30_0.dll</span>  to <span class=\"lang:default decode:true  crayon-inline \">CUDA_PATH\\bin</span> . This is a one time copy such that the NVVM DLL is now with all the other CUDA dlls and in a directory that is a part of PATH and hence the DLL can be detected automatically.</li>\r\n	<li>Add <span class=\"lang:default decode:true  crayon-inline \">%CUDA_PATH%\\nvvm\\bin</span>  to the system PATH environment variable. This will allow automatic detection by the system and No further copying will be required. ArrayFire does not add this to PATH since the CUDA installer doesn\'t add it to PATH.</li>\r\n</ol>\r\n<h3><a id=\"step1\" class=\"anchor\"></a>Step 1: Running pre-built executables</h3>\r\nThe ArrayFire installer ships with a few pre-built executables with the examples. These should run out of the box when double clicked.\r\n\r\nSome prebuilt examples are:\r\n<ul>\r\n	<li>Helloworld (examples/helloworld)</li>\r\n	<li>BLAS (examples/benchmarks)</li>\r\n	<li>FFT (examples/benchmarks)</li>\r\n	<li>Pi Estimation (examples/benchmarks)</li>\r\n	<li>Conway (Graphics) (examples/graphics)</li>\r\n</ul>\r\nNote: For the CUDA executables, you will need to copy <span class=\"lang:default decode:true  crayon-inline \">CUDA_PATH\\nvvm\\bin\\nvvm64_30_0.dll</span>  to the location of the executables.\r\n<h3><a id=\"step2\" class=\"anchor\"></a>Step 2: Build and Run a Project</h3>\r\n<ol type=\"1\">\r\n	<li>Open Visual Studio 2013. Load the HelloWorld solution which is located at <span class=\"lang:default decode:true  crayon-inline \">AF_PATH/examples/helloworld/helloworld.sln</span> .</li>\r\n	<li>Build the <span class=\"lang:default decode:true  crayon-inline \">helloworld</span>  example. Be sure to, select the platform/configuration of your choice using the platform drop-down (the options are CPU, CUDA, OpenCL, and Unified) and Solution Configuration drop down (options of Release and Debug) menus.</li>\r\n	<li>Run the <span class=\"lang:default decode:true  crayon-inline \">helloworld</span>  example.</li>\r\n</ol>\r\n<h3><a id=\"step3\" class=\"anchor\"></a>Step 3: Using ArrayFire within Visual Studio</h3>\r\nThis is divided into 4 parts:\r\n<ul>\r\n	<li><a href=\"#s3partA\">Part A: Adding ArrayFire to an existing solution (Single Backend)</a></li>\r\n	<li><a href=\"#s3partB\">Part B: Adding ArrayFire CUDA to a new/existing CUDA project</a></li>\r\n	<li><a href=\"#s3partC\">Part C: Project with all ArrayFire backends</a></li>\r\n	<li><a href=\"#s3partD\">Part D: ArrayFire with CMake</a></li>\r\n</ul>\r\n<h4><a id=\"s3partA\" class=\"anchor\"></a>Part A: Adding ArrayFire to an existing solution (Single Backend)</h4>\r\nNote: If you plan on using Native CUDA code in the project, use the steps under <a href=\"#s3partB\">Part B</a>.\r\n\r\nAdding a single backend to an existing project is quite simple.\r\n<ol type=\"1\">\r\n	<li>Add <code>\"<span class=\"lang:default decode:true  crayon-inline \">$(AF_PATH)/include;</span> \"</code> to <em>Project Properties -&gt; C/C++ -&gt; General -&gt; Additional Include Directories</em>.</li>\r\n	<li>Add <code>\"<span class=\"lang:default decode:true  crayon-inline \">$(AF_PATH)/lib;</span> \"</code> to <em>Project Properties -&gt; Linker -&gt; General -&gt; Additional Library Directories</em>.</li>\r\n	<li>Add <span class=\"lang:default decode:true  crayon-inline \">afcpu.lib</span>  or <span class=\"lang:default decode:true  crayon-inline \">afcuda.lib</span>  or <span class=\"lang:default decode:true  crayon-inline \">afopencl.lib</span>  to <em>Project Properties -&gt; Linker -&gt; Input -&gt; Additional Dependencies</em>. based on your preferred backend.</li>\r\n	<li>(Optional) You may choose to define <span class=\"lang:default decode:true  crayon-inline \">NOMINMAX, AF_&lt;CPU/CUDA/OPENCL&gt;</span>  and/or <span class=\"lang:default decode:true  crayon-inline \">AF_&lt;DEBUG/RELEASE&gt;</span>  in your projects. This can be added to <em>Project Properties -&gt; C/C++ -&gt; General -&gt; Preprocessor-&gt; Preprocessory definitions</em>.</li>\r\n</ol>\r\nIf you are using the CUDA backend, it is important to ensure that the CUDA NVVM DLLs are copied to the exectuable directory. This can be done by adding a post build event.\r\n\r\nOpen the <em>Project Properties -&gt; Build Events -&gt; Post Build Events</em> dialog and add the following lines to it.\r\n<div class=\"fragment\">\r\n<pre class=\"lang:default decode:true\">echo copy \"$(CUDA_PATH)\\nvvm\\bin\\nvvm64*.dll\" \"$(OutDir)\" \r\necho copy \"$(CUDA_PATH)\\nvvm\\bin\\nvvm64*.dll\" \"$(OutDir)\"</pre>\r\n<h4 class=\"line\"> <a id=\"s3partB\" class=\"anchor\"></a>Part B: Adding ArrayFire CUDA to a new/existing CUDA project</h4>\r\n</div>\r\nLastly, if your project contains custom CUDA code, the instructions are slightly different as it requires using a CUDA NVCC Project:\r\n<ol type=\"1\">\r\n	<li>Create a custom \"CUDA NVCC project\" in Visual Studio</li>\r\n	<li>Add <code>\"<span class=\"lang:default decode:true  crayon-inline \">$(AF_PATH)/include;</span> \"</code> to <em>Project Properties -&gt; CUDA C/C++ -&gt; General -&gt; Additional Include Directories</em>.</li>\r\n	<li>Add <code>\"<span class=\"lang:default decode:true  crayon-inline \">$(AF_PATH)/lib;</span> \"</code> to <em>Project Properties -&gt; Linker -&gt; General -&gt; Additional Library Directories</em>.</li>\r\n	<li>Add <span class=\"lang:default decode:true  crayon-inline \">afcpu.lib</span>  or <span class=\"lang:default decode:true  crayon-inline \">afcuda.lib</span>  or <span class=\"lang:default decode:true  crayon-inline \">afopencl.lib</span>  to <em>Project Properties -&gt; Linker -&gt; Input -&gt; Additional Dependencies</em>. based on your preferred backend.</li>\r\n	<li>(Optional) You may choose to define <span class=\"lang:default decode:true  crayon-inline \">NOMINMAX, AF_CUDA</span>  and/or <span class=\"lang:default decode:true  crayon-inline \">AF_&lt;DEBUG/RELEASE&gt;</span>  in your projects. This can be added to <em>Project Properties -&gt; C/C++ -&gt; General -&gt; Preprocessor-&gt; Preprocessory definitions</em>.</li>\r\n	<li>Pick a solution to handle the NVVM DLLs. We recommend the post build event method used in <a href=\"#s3partA\">Part A</a>.</li>\r\n</ol>\r\n<h4><a id=\"s3partC\" class=\"anchor\"></a>Part C: Project with all ArrayFire backends</h4>\r\nIf you wish to create a project that allows you to use all the ArrayFire backends with ease, the best way to go is to copy the <em>HelloWorld sln/vcxproj/cpp</em> file trio and rename them to suit your project.\r\n\r\nAll the ArrayFire examples are pre-configured for all ArrayFire backends as well as the Unified API. These can be chosen from the Solution/Platform configuration drop down boxes.\r\n\r\nYou can alternately download the template project from <a href=\"https://github.com/arrayfire/arrayfire-template-projects\">ArrayFire Template Projects</a>\r\n<h4><a id=\"s3partD\" class=\"anchor\"></a>Part D: ArrayFire with CMake</h4>\r\n<em>NOTE:</em> The ArrayFire installer sets up CMake file and registry so that it can be found by CMake by simply using the <span class=\"lang:default decode:true  crayon-inline \">Find_PACKAGE(ArrayFire)</span>  command.\r\n\r\nIf you are writing a new ArrayFire project in C/C++ from scratch, we suggest you grab a copy of our <a href=\"https://github.com/arrayfire/arrayfire-template-projects\">CMake Project Example</a>; however, it is useful to read the documentation below in case you need to add ArrayFire to an existing project.\r\n\r\nAs <a href=\"#big-picture\">discussed above</a>, ArrayFire ships with a series of CMake scripts to make finding and using our library easy. The scripts will automatically find all versions of the ArrayFire library and pick the most powerful of the installed backends (typically CUDA).\r\n\r\nFirst create a file called <span class=\"lang:default decode:true  crayon-inline \">CMakeLists.txt</span>  in your project directory:\r\n<pre class=\"fragment\">cd your-project-directory\r\ntouch CMakeLists.txt\r\n</pre>\r\nand populate it with the following code:\r\n<pre class=\"fragment\">FIND_PACKAGE(ArrayFire)\r\nINCLUDE_DIRECTORIES(${ArrayFire_INCLUDE_DIRS})\r\n\r\n... [gather source files, etc.]\r\n\r\n# If you intend to use OpenCL, you need to find it\r\nFIND_PACKAGE(OpenCL)\r\nSET(EXTRA_LIBS ${CMAKE_THREAD_LIBS_INIT} ${OpenCL_LIBRARIES})\r\n\r\n# Or if you intend to use CUDA, you need it as well as NVVM:\r\nFIND_PACKAGE(CUDA)\r\nFIND_PACKAGE(NVVM) # this FIND script can be found in the ArrayFire CMake example repository\r\nSET(EXTRA_LIBS ${CMAKE_THREAD_LIBS_INIT} ${CUDA_LIBRARIES} ${NVVM_LIB})\r\n\r\nADD_EXECUTABLE(my_executable [list your source files here])\r\nTARGET_LINK_LIBRARIES(my_executable ${ArrayFire_LIBRARIES} ${EXTRA_LIBS})\r\n</pre>\r\nwhere <span class=\"lang:default decode:true  crayon-inline \">my_executable</span>  is the name of the executable you wish to create. See the <a href=\"https://cmake.org/documentation/\">CMake documentation</a> for more information on how to use CMake. Clearly the above code snippet precludes the use of both CUDA and OpenCL, see the <a href=\"https://github.com/bkloppenborg/arrayfire-cmake-example\">ArrayFire CMake Example</a> for an example of how to build executables for both backends from the same CMake script.\r\n\r\nIn the above code listing, the <span class=\"lang:default decode:true  crayon-inline \">FIND_PACKAGE</span>  will find the ArrayFire include files, libraries, and define several variables including:\r\n<pre class=\"fragment\">ArrayFire_INCLUDE_DIRS    - Location of ArrayFire\'s include directory.\r\nArrayFire_LIBRARIES       - Location of ArrayFire\'s libraries.\r\n                            This will default to a GPU backend if one\r\n                            is found\r\nArrayFire_FOUND           - True if ArrayFire has been located\r\n</pre>\r\nIf you wish to use a specific backend, the find script also defines these variables:\r\n<pre class=\"fragment\">ArrayFire_CPU_FOUND         - True of the ArrayFire CPU library has been found.\r\nArrayFire_CPU_LIBRARIES     - Location of ArrayFire\'s CPU library, if found\r\nArrayFire_CUDA_FOUND        - True of the ArrayFire CUDA library has been found.\r\nArrayFire_CUDA_LIBRARIES    - Location of ArrayFire\'s CUDA library, if found\r\nArrayFire_OpenCL_FOUND      - True of the ArrayFire OpenCL library has been found.\r\nArrayFire_OpenCL_LIBRARIES  - Location of ArrayFire\'s OpenCL library, if found\r\nArrayFire_Unified_FOUND     - True of the ArrayFire Unified library has been found.\r\nArrayFire_Unified_LIBRARIES - Location of ArrayFire\'s Unified library, if found\r\n</pre>\r\nTherefore, if you wish to target a specific specific backend, simply replace <span class=\"lang:default decode:true  crayon-inline \">${ArrayFire_LIBRARIES}</span>  with <span class=\"lang:default decode:true  crayon-inline \">${ArrayFire_CPU}</span> ,<span class=\"lang:default decode:true  crayon-inline \"> ${ArrayFire_OPENCL}</span> , <span class=\"lang:default decode:true  crayon-inline \">${ArrayFire_CUDA}</span> , or <span class=\"lang:default decode:true  crayon-inline \">${ArrayFire_Unified}</span>  in the <span class=\"lang:default decode:true  crayon-inline \">TARGET_LINK_LIBRARIES</span>  command above.\r\n\r\nNext we need to instruct CMake to create build instructions and then compile. We suggest using CMake\'s out-of-source build functionality to keep your build and source files cleanly separated. To do this open the CMake GUI.\r\n<ul>\r\n	<li>Under source directory, add the path to your project</li>\r\n	<li>Under build directory, add the path to your project and append /build</li>\r\n	<li>Click configure and choose Visual Studio 2013 Win 64 as the generator.</li>\r\n	<li>If configuration was successful, click generate. This will create a my-project.sln file under build. You can open this in Visual Studio and compile the ALL_BUILD project.</li>\r\n</ul>\r\nThe <a href=\"https://github.com/bkloppenborg/arrayfire-cmake-example\">ArrayFire CMake Example</a> is a CMake project used to demo how ArrayFire can be using with a CMake project.\r\n\r\nNote: The CMake project does not add the post build event to copy the NVVM DLLs in case of CUDA backend. You will need to either copy it manually to the exectuable directory, or pick another solution for it.\r\n\r\n</div>\r\n</div>','Setting up an ArrayFire project on Windows','','inherit','open','closed','','8546-revision-v1','','','2015-11-06 13:57:18','2015-11-06 13:57:18','',8546,'http://sandbox.arrayfire.com/8546-revision-v1/',0,'revision','',0),(8587,18528,'2015-11-06 13:57:56','2015-11-06 13:57:56','<div class=\"header\">\r\n<div class=\"headertitle\">\r\n<div class=\"title\">Continuing our blog series \"<a href=\"http://sandbox.arrayfire.com/tag/learning-arrayfire-from-scratch/\">Learning ArrayFire from scratch</a>\" today we will discuss how to set up an ArrayFire project on Windows using Visual Studio or CMake.</div>\r\n</div>\r\n</div>\r\n<!--more-->\r\n\r\nIf you have not already done so, please make sure you have installed, configured, and tested ArrayFire following the <a class=\"el\" href=\"installing.htm\">installation instructions</a>.\r\n<div class=\"contents\">\r\n<div class=\"textblock\">\r\n<h3>The big picture</h3>\r\nThe ArrayFire Windows installer creates the following:\r\n<pre class=\"lang:default decode:true\">AF_PATH                 Environment variable to point to the installation location.\r\n                        This is normally C:/Program Files/ArrayFire/v*\r\nAF_PATH/include         Header files for ArrayFire (Include Dir)\r\nAF_PATH/lib             All ArrayFire backends libraries, dlls and dependency dlls \r\n                        (Library dir)\r\nAF_PATH/examples        Examples to get started. Some examples also have pre-built \r\n                        exectuables\r\nAF_PATH/cmake           CMake config files for automatic configuration by external \r\n                        projects\r\nAF_PATH/uninstall.exe   Uninstaller\r\nAF_PATH/*               Other miscellenous files including licenses, logos, copyrights</pre>\r\nThe installer also appends <span class=\"lang:default decode:true  crayon-inline \">%AF_PATH%/lib</span>  to the User <span class=\"lang:default decode:true  crayon-inline \">PATH</span>  variable (see the <a class=\"el\" href=\"installing.htm\">installation instructions</a> for further details).\r\n<h4>Dealing with CUDA NVVM DLLs</h4>\r\nWhen using CUDA with ArrayFire you may encounter a linker error indicating the NVVM DLLs are missing. This is because the NVVM DLLs are not part of the standard <span class=\"lang:default decode:true  crayon-inline \">CUDA_PATH\\bin</span>  installation directory that is added to your <span class=\"lang:default decode:true  crayon-inline \">PATH</span>  when the CUDA installer runs. Thus, NVVM will not be found during the linking stage. There are a few ways to deal with this issue:\r\n\r\n&nbsp;\r\n<ol type=\"1\">\r\n	<li>Copy the DLLs to the executable location. This is, by far, the cleanest solution and we recommend doing this with ArrayFire projects. To do so, create a post-build event to copy the NVVM DLL as discussed below in <a href=\"#s3partA\">Step 3 - Part A</a>.</li>\r\n	<li>Copy <span class=\"lang:default decode:true  crayon-inline\">CUDA_PATH\\nvvm\\bin\\nvvm64_30_0.dll</span>  to <span class=\"lang:default decode:true  crayon-inline \">CUDA_PATH\\bin</span> . This is a one time copy such that the NVVM DLL is now with all the other CUDA dlls and in a directory that is a part of PATH and hence the DLL can be detected automatically.</li>\r\n	<li>Add <span class=\"lang:default decode:true  crayon-inline \">%CUDA_PATH%\\nvvm\\bin</span>  to the system PATH environment variable. This will allow automatic detection by the system and No further copying will be required. ArrayFire does not add this to PATH since the CUDA installer doesn\'t add it to PATH.</li>\r\n</ol>\r\n<h3><a id=\"step1\" class=\"anchor\"></a>Step 1: Running pre-built executables</h3>\r\nThe ArrayFire installer ships with a few pre-built executables with the examples. These should run out of the box when double clicked.\r\n\r\nSome prebuilt examples are:\r\n<ul>\r\n	<li>Helloworld (examples/helloworld)</li>\r\n	<li>BLAS (examples/benchmarks)</li>\r\n	<li>FFT (examples/benchmarks)</li>\r\n	<li>Pi Estimation (examples/benchmarks)</li>\r\n	<li>Conway (Graphics) (examples/graphics)</li>\r\n</ul>\r\nNote: For the CUDA executables, you will need to copy <span class=\"lang:default decode:true  crayon-inline \">CUDA_PATH\\nvvm\\bin\\nvvm64_30_0.dll</span>  to the location of the executables.\r\n<h3><a id=\"step2\" class=\"anchor\"></a>Step 2: Build and Run a Project</h3>\r\n<ol type=\"1\">\r\n	<li>Open Visual Studio 2013. Load the HelloWorld solution which is located at <span class=\"lang:default decode:true  crayon-inline \">AF_PATH/examples/helloworld/helloworld.sln</span> .</li>\r\n	<li>Build the <span class=\"lang:default decode:true  crayon-inline \">helloworld</span>  example. Be sure to, select the platform/configuration of your choice using the platform drop-down (the options are CPU, CUDA, OpenCL, and Unified) and Solution Configuration drop down (options of Release and Debug) menus.</li>\r\n	<li>Run the <span class=\"lang:default decode:true  crayon-inline \">helloworld</span>  example.</li>\r\n</ol>\r\n<h3><a id=\"step3\" class=\"anchor\"></a>Step 3: Using ArrayFire within Visual Studio</h3>\r\nThis is divided into 4 parts:\r\n<ul>\r\n	<li><a href=\"#s3partA\">Part A: Adding ArrayFire to an existing solution (Single Backend)</a></li>\r\n	<li><a href=\"#s3partB\">Part B: Adding ArrayFire CUDA to a new/existing CUDA project</a></li>\r\n	<li><a href=\"#s3partC\">Part C: Project with all ArrayFire backends</a></li>\r\n	<li><a href=\"#s3partD\">Part D: ArrayFire with CMake</a></li>\r\n</ul>\r\n<h4><a id=\"s3partA\" class=\"anchor\"></a>Part A: Adding ArrayFire to an existing solution (Single Backend)</h4>\r\nNote: If you plan on using Native CUDA code in the project, use the steps under <a href=\"#s3partB\">Part B</a>.\r\n\r\nAdding a single backend to an existing project is quite simple.\r\n<ol type=\"1\">\r\n	<li>Add <code>\"<span class=\"lang:default decode:true  crayon-inline \">$(AF_PATH)/include;</span> \"</code> to <em>Project Properties -&gt; C/C++ -&gt; General -&gt; Additional Include Directories</em>.</li>\r\n	<li>Add <code>\"<span class=\"lang:default decode:true  crayon-inline \">$(AF_PATH)/lib;</span> \"</code> to <em>Project Properties -&gt; Linker -&gt; General -&gt; Additional Library Directories</em>.</li>\r\n	<li>Add <span class=\"lang:default decode:true  crayon-inline \">afcpu.lib</span>  or <span class=\"lang:default decode:true  crayon-inline \">afcuda.lib</span>  or <span class=\"lang:default decode:true  crayon-inline \">afopencl.lib</span>  to <em>Project Properties -&gt; Linker -&gt; Input -&gt; Additional Dependencies</em>. based on your preferred backend.</li>\r\n	<li>(Optional) You may choose to define <span class=\"lang:default decode:true  crayon-inline \">NOMINMAX, AF_&lt;CPU/CUDA/OPENCL&gt;</span>  and/or <span class=\"lang:default decode:true  crayon-inline \">AF_&lt;DEBUG/RELEASE&gt;</span>  in your projects. This can be added to <em>Project Properties -&gt; C/C++ -&gt; General -&gt; Preprocessor-&gt; Preprocessory definitions</em>.</li>\r\n</ol>\r\nIf you are using the CUDA backend, it is important to ensure that the CUDA NVVM DLLs are copied to the exectuable directory. This can be done by adding a post build event.\r\n\r\nOpen the <em>Project Properties -&gt; Build Events -&gt; Post Build Events</em> dialog and add the following lines to it.\r\n<div class=\"fragment\">\r\n<pre class=\"lang:default decode:true\">echo copy \"$(CUDA_PATH)\\nvvm\\bin\\nvvm64*.dll\" \"$(OutDir)\" \r\necho copy \"$(CUDA_PATH)\\nvvm\\bin\\nvvm64*.dll\" \"$(OutDir)\"</pre>\r\n<h4 class=\"line\"> <a id=\"s3partB\" class=\"anchor\"></a>Part B: Adding ArrayFire CUDA to a new/existing CUDA project</h4>\r\n</div>\r\nLastly, if your project contains custom CUDA code, the instructions are slightly different as it requires using a CUDA NVCC Project:\r\n<ol type=\"1\">\r\n	<li>Create a custom \"CUDA NVCC project\" in Visual Studio</li>\r\n	<li>Add <code>\"<span class=\"lang:default decode:true  crayon-inline \">$(AF_PATH)/include;</span> \"</code> to <em>Project Properties -&gt; CUDA C/C++ -&gt; General -&gt; Additional Include Directories</em>.</li>\r\n	<li>Add <code>\"<span class=\"lang:default decode:true  crayon-inline \">$(AF_PATH)/lib;</span> \"</code> to <em>Project Properties -&gt; Linker -&gt; General -&gt; Additional Library Directories</em>.</li>\r\n	<li>Add <span class=\"lang:default decode:true  crayon-inline \">afcpu.lib</span>  or <span class=\"lang:default decode:true  crayon-inline \">afcuda.lib</span>  or <span class=\"lang:default decode:true  crayon-inline \">afopencl.lib</span>  to <em>Project Properties -&gt; Linker -&gt; Input -&gt; Additional Dependencies</em>. based on your preferred backend.</li>\r\n	<li>(Optional) You may choose to define <span class=\"lang:default decode:true  crayon-inline \">NOMINMAX, AF_CUDA</span>  and/or <span class=\"lang:default decode:true  crayon-inline \">AF_&lt;DEBUG/RELEASE&gt;</span>  in your projects. This can be added to <em>Project Properties -&gt; C/C++ -&gt; General -&gt; Preprocessor-&gt; Preprocessory definitions</em>.</li>\r\n	<li>Pick a solution to handle the NVVM DLLs. We recommend the post build event method used in <a href=\"#s3partA\">Part A</a>.</li>\r\n</ol>\r\n<h4><a id=\"s3partC\" class=\"anchor\"></a>Part C: Project with all ArrayFire backends</h4>\r\nIf you wish to create a project that allows you to use all the ArrayFire backends with ease, the best way to go is to copy the <em>HelloWorld sln/vcxproj/cpp</em> file trio and rename them to suit your project.\r\n\r\nAll the ArrayFire examples are pre-configured for all ArrayFire backends as well as the Unified API. These can be chosen from the Solution/Platform configuration drop down boxes.\r\n\r\nYou can alternately download the template project from <a href=\"https://github.com/arrayfire/arrayfire-template-projects\">ArrayFire Template Projects</a>\r\n<h4><a id=\"s3partD\" class=\"anchor\"></a>Part D: ArrayFire with CMake</h4>\r\n<em>NOTE:</em> The ArrayFire installer sets up CMake file and registry so that it can be found by CMake by simply using the <span class=\"lang:default decode:true  crayon-inline \">Find_PACKAGE(ArrayFire)</span>  command.\r\n\r\nIf you are writing a new ArrayFire project in C/C++ from scratch, we suggest you grab a copy of our <a href=\"https://github.com/arrayfire/arrayfire-template-projects\">CMake Project Example</a>; however, it is useful to read the documentation below in case you need to add ArrayFire to an existing project.\r\n\r\nAs <a href=\"#big-picture\">discussed above</a>, ArrayFire ships with a series of CMake scripts to make finding and using our library easy. The scripts will automatically find all versions of the ArrayFire library and pick the most powerful of the installed backends (typically CUDA).\r\n\r\nFirst create a file called <span class=\"lang:default decode:true  crayon-inline \">CMakeLists.txt</span>  in your project directory:\r\n<pre class=\"fragment\">cd your-project-directory\r\ntouch CMakeLists.txt\r\n</pre>\r\nand populate it with the following code:\r\n<pre class=\"fragment\">FIND_PACKAGE(ArrayFire)\r\nINCLUDE_DIRECTORIES(${ArrayFire_INCLUDE_DIRS})\r\n\r\n... [gather source files, etc.]\r\n\r\n# If you intend to use OpenCL, you need to find it\r\nFIND_PACKAGE(OpenCL)\r\nSET(EXTRA_LIBS ${CMAKE_THREAD_LIBS_INIT} ${OpenCL_LIBRARIES})\r\n\r\n# Or if you intend to use CUDA, you need it as well as NVVM:\r\nFIND_PACKAGE(CUDA)\r\nFIND_PACKAGE(NVVM) # this FIND script can be found in the ArrayFire CMake example repository\r\nSET(EXTRA_LIBS ${CMAKE_THREAD_LIBS_INIT} ${CUDA_LIBRARIES} ${NVVM_LIB})\r\n\r\nADD_EXECUTABLE(my_executable [list your source files here])\r\nTARGET_LINK_LIBRARIES(my_executable ${ArrayFire_LIBRARIES} ${EXTRA_LIBS})\r\n</pre>\r\nwhere <span class=\"lang:default decode:true  crayon-inline \">my_executable</span>  is the name of the executable you wish to create. See the <a href=\"https://cmake.org/documentation/\">CMake documentation</a> for more information on how to use CMake. Clearly the above code snippet precludes the use of both CUDA and OpenCL, see the <a href=\"https://github.com/bkloppenborg/arrayfire-cmake-example\">ArrayFire CMake Example</a> for an example of how to build executables for both backends from the same CMake script.\r\n\r\nIn the above code listing, the <span class=\"lang:default decode:true  crayon-inline \">FIND_PACKAGE</span>  will find the ArrayFire include files, libraries, and define several variables including:\r\n<pre class=\"fragment\">ArrayFire_INCLUDE_DIRS    - Location of ArrayFire\'s include directory.\r\nArrayFire_LIBRARIES       - Location of ArrayFire\'s libraries.\r\n                            This will default to a GPU backend if one\r\n                            is found\r\nArrayFire_FOUND           - True if ArrayFire has been located\r\n</pre>\r\nIf you wish to use a specific backend, the find script also defines these variables:\r\n<pre class=\"fragment\">ArrayFire_CPU_FOUND         - True of the ArrayFire CPU library has been found.\r\nArrayFire_CPU_LIBRARIES     - Location of ArrayFire\'s CPU library, if found\r\nArrayFire_CUDA_FOUND        - True of the ArrayFire CUDA library has been found.\r\nArrayFire_CUDA_LIBRARIES    - Location of ArrayFire\'s CUDA library, if found\r\nArrayFire_OpenCL_FOUND      - True of the ArrayFire OpenCL library has been found.\r\nArrayFire_OpenCL_LIBRARIES  - Location of ArrayFire\'s OpenCL library, if found\r\nArrayFire_Unified_FOUND     - True of the ArrayFire Unified library has been found.\r\nArrayFire_Unified_LIBRARIES - Location of ArrayFire\'s Unified library, if found\r\n</pre>\r\nTherefore, if you wish to target a specific specific backend, simply replace <span class=\"lang:default decode:true  crayon-inline \">${ArrayFire_LIBRARIES}</span>  with <span class=\"lang:default decode:true  crayon-inline \">${ArrayFire_CPU}</span> ,<span class=\"lang:default decode:true  crayon-inline \"> ${ArrayFire_OPENCL}</span> , <span class=\"lang:default decode:true  crayon-inline \">${ArrayFire_CUDA}</span> , or <span class=\"lang:default decode:true  crayon-inline \">${ArrayFire_Unified}</span>  in the <span class=\"lang:default decode:true  crayon-inline \">TARGET_LINK_LIBRARIES</span>  command above.\r\n\r\nNext we need to instruct CMake to create build instructions and then compile. We suggest using CMake\'s out-of-source build functionality to keep your build and source files cleanly separated. To do this open the CMake GUI.\r\n<ul>\r\n	<li>Under source directory, add the path to your project</li>\r\n	<li>Under build directory, add the path to your project and append /build</li>\r\n	<li>Click configure and choose Visual Studio 2013 Win 64 as the generator.</li>\r\n	<li>If configuration was successful, click generate. This will create a my-project.sln file under build. You can open this in Visual Studio and compile the ALL_BUILD project.</li>\r\n</ul>\r\nThe <a href=\"https://github.com/bkloppenborg/arrayfire-cmake-example\">ArrayFire CMake Example</a> is a CMake project used to demo how ArrayFire can be using with a CMake project.\r\n\r\nNote: The CMake project does not add the post build event to copy the NVVM DLLs in case of CUDA backend. You will need to either copy it manually to the exectuable directory, or pick another solution for it.\r\n\r\n</div>\r\n</div>','Setting up an ArrayFire project on Windows','','inherit','open','closed','','8546-revision-v1','','','2015-11-06 13:57:56','2015-11-06 13:57:56','',8546,'http://sandbox.arrayfire.com/8546-revision-v1/',0,'revision','',0),(8588,11,'2015-11-06 14:29:54','2015-11-06 14:29:54','<div class=\"header\">\r\n<div class=\"headertitle\">\r\n<div class=\"title\">Continuing our blog series \"<a href=\"http://sandbox.arrayfire.com/tag/learning-arrayfire-from-scratch/\">Learning ArrayFire from scratch</a>\" today we will discuss how to set up an ArrayFire project on Windows using Visual Studio or CMake.</div>\r\n</div>\r\n</div>\r\n<!--more-->\r\n\r\nIf you have not already done so, please make sure you have installed, configured, and tested ArrayFire following the <a class=\"el\" href=\"installing.htm\">installation instructions</a>.\r\n<div class=\"contents\">\r\n<div class=\"textblock\">\r\n<h3>The big picture</h3>\r\nThe ArrayFire Windows installer creates the following:\r\n<pre class=\"lang:default decode:true\">AF_PATH                 Environment variable to point to the installation location.\r\n                        This is normally C:/Program Files/ArrayFire/v*\r\nAF_PATH/include         Header files for ArrayFire (Include Dir)\r\nAF_PATH/lib             All ArrayFire backends libraries, dlls and dependency dlls \r\n                        (Library dir)\r\nAF_PATH/examples        Examples to get started. Some examples also have pre-built \r\n                        exectuables\r\nAF_PATH/cmake           CMake config files for automatic configuration by external \r\n                        projects\r\nAF_PATH/uninstall.exe   Uninstaller\r\nAF_PATH/*               Other miscellenous files including licenses, logos, copyrights</pre>\r\nThe installer also appends <span class=\"lang:default decode:true  crayon-inline \">%AF_PATH%/lib</span>  to the User <span class=\"lang:default decode:true  crayon-inline \">PATH</span>  variable (see the <a class=\"el\" href=\"installing.htm\">installation instructions</a> for further details).\r\n<h4>Dealing with CUDA NVVM DLLs</h4>\r\nWhen using CUDA with ArrayFire you may encounter a linker error indicating the NVVM DLLs are missing. This is because the NVVM DLLs are not part of the standard <span class=\"lang:default decode:true  crayon-inline \">CUDA_PATH\\bin</span>  installation directory that is added to your <span class=\"lang:default decode:true  crayon-inline \">PATH</span>  when the CUDA installer runs. Thus, NVVM will not be found during the linking stage. There are a few ways to deal with this issue:\r\n\r\n&nbsp;\r\n<ol type=\"1\">\r\n	<li>Copy the DLLs to the executable location. This is, by far, the cleanest solution and we recommend doing this with ArrayFire projects. To do so, create a post-build event to copy the NVVM DLL as discussed below in <a href=\"#s3partA\">Step 3 - Part A</a>.</li>\r\n	<li>Copy <span class=\"lang:default decode:true  crayon-inline\">CUDA_PATH\\nvvm\\bin\\nvvm64_30_0.dll</span>  to <span class=\"lang:default decode:true  crayon-inline \">CUDA_PATH\\bin</span> . This is a one time copy such that the NVVM DLL is now with all the other CUDA dlls and in a directory that is a part of PATH and hence the DLL can be detected automatically.</li>\r\n	<li>Add <span class=\"lang:default decode:true  crayon-inline \">%CUDA_PATH%\\nvvm\\bin</span>  to the system PATH environment variable. This will allow automatic detection by the system and No further copying will be required. ArrayFire does not add this to PATH since the CUDA installer doesn\'t add it to PATH.</li>\r\n</ol>\r\n<h3><a id=\"step1\" class=\"anchor\"></a>Step 1: Running pre-built executables</h3>\r\nThe ArrayFire installer ships with a few pre-built executables with the examples. These should run out of the box when double clicked.\r\n\r\nSome prebuilt examples are:\r\n<ul>\r\n	<li>Helloworld (examples/helloworld)</li>\r\n	<li>BLAS (examples/benchmarks)</li>\r\n	<li>FFT (examples/benchmarks)</li>\r\n	<li>Pi Estimation (examples/benchmarks)</li>\r\n	<li>Conway (Graphics) (examples/graphics)</li>\r\n</ul>\r\nNote: For the CUDA executables, you will need to copy <span class=\"lang:default decode:true  crayon-inline \">CUDA_PATH\\nvvm\\bin\\nvvm64_30_0.dll</span>  to the location of the executables.\r\n<h3><a id=\"step2\" class=\"anchor\"></a>Step 2: Build and Run a Project</h3>\r\n<ol type=\"1\">\r\n	<li>Open Visual Studio 2013. Load the HelloWorld solution which is located at <span class=\"lang:default decode:true  crayon-inline \">AF_PATH/examples/helloworld/helloworld.sln</span> .</li>\r\n	<li>Build the <span class=\"lang:default decode:true  crayon-inline \">helloworld</span>  example. Be sure to, select the platform/configuration of your choice using the platform drop-down (the options are CPU, CUDA, OpenCL, and Unified) and Solution Configuration drop down (options of Release and Debug) menus.</li>\r\n	<li>Run the <span class=\"lang:default decode:true  crayon-inline \">helloworld</span>  example.</li>\r\n</ol>\r\n<h3><a id=\"step3\" class=\"anchor\"></a>Step 3: Using ArrayFire within Visual Studio</h3>\r\nThis is divided into 4 parts:\r\n<ul>\r\n	<li><a href=\"#s3partA\">Part A: Adding ArrayFire to an existing solution (Single Backend)</a></li>\r\n	<li><a href=\"#s3partB\">Part B: Adding ArrayFire CUDA to a new/existing CUDA project</a></li>\r\n	<li><a href=\"#s3partC\">Part C: Project with all ArrayFire backends</a></li>\r\n	<li><a href=\"#s3partD\">Part D: ArrayFire with CMake</a></li>\r\n</ul>\r\n<h4><a id=\"s3partA\" class=\"anchor\"></a>Part A: Adding ArrayFire to an existing solution (Single Backend)</h4>\r\nNote: If you plan on using native CUDA code in the project, use the steps under <a href=\"#s3partB\">Part B</a>.\r\n\r\nAdding a single backend to an existing project is quite simple.\r\n<ol type=\"1\">\r\n	<li>Add <code>\"<span class=\"lang:default decode:true  crayon-inline \">$(AF_PATH)/include;</span> \"</code> to <em>Project Properties -&gt; C/C++ -&gt; General -&gt; Additional Include Directories</em>.</li>\r\n	<li>Add <code>\"<span class=\"lang:default decode:true  crayon-inline \">$(AF_PATH)/lib;</span> \"</code> to <em>Project Properties -&gt; Linker -&gt; General -&gt; Additional Library Directories</em>.</li>\r\n	<li>Add <span class=\"lang:default decode:true  crayon-inline \">afcpu.lib</span>  or <span class=\"lang:default decode:true  crayon-inline \">afcuda.lib</span>  or <span class=\"lang:default decode:true  crayon-inline \">afopencl.lib</span>  to <em>Project Properties -&gt; Linker -&gt; Input -&gt; Additional Dependencies</em>. based on your preferred backend.</li>\r\n	<li>(Optional) You may choose to define <span class=\"lang:default decode:true  crayon-inline \">NOMINMAX, AF_&lt;CPU/CUDA/OPENCL&gt;</span>  and/or <span class=\"lang:default decode:true  crayon-inline \">AF_&lt;DEBUG/RELEASE&gt;</span>  in your projects. This can be added to <em>Project Properties -&gt; C/C++ -&gt; General -&gt; Preprocessor-&gt; Preprocessory definitions</em>.</li>\r\n</ol>\r\nIf you are using the CUDA backend, it is important to ensure that the CUDA NVVM DLLs are copied to the exectuable directory. This can be done by adding a post build event.\r\n\r\nOpen the <em>Project Properties -&gt; Build Events -&gt; Post Build Events</em> dialog and add the following lines to it.\r\n<div class=\"fragment\">\r\n<pre class=\"lang:default decode:true\">echo copy \"$(CUDA_PATH)\\nvvm\\bin\\nvvm64*.dll\" \"$(OutDir)\" \r\necho copy \"$(CUDA_PATH)\\nvvm\\bin\\nvvm64*.dll\" \"$(OutDir)\"</pre>\r\n<h4 class=\"line\"> <a id=\"s3partB\" class=\"anchor\"></a>Part B: Adding ArrayFire CUDA to a new/existing CUDA project</h4>\r\n</div>\r\nIf your project contains custom CUDA code, the instructions are slightly different as it requires using a CUDA NVCC Project:\r\n<ol type=\"1\">\r\n	<li>Create a custom \"CUDA NVCC project\" in Visual Studio</li>\r\n	<li>Add <code>\"<span class=\"lang:default decode:true  crayon-inline \">$(AF_PATH)/include;</span> \"</code> to <em>Project Properties -&gt; CUDA C/C++ -&gt; General -&gt; Additional Include Directories</em>.</li>\r\n	<li>Add <code>\"<span class=\"lang:default decode:true  crayon-inline \">$(AF_PATH)/lib;</span> \"</code> to <em>Project Properties -&gt; Linker -&gt; General -&gt; Additional Library Directories</em>.</li>\r\n	<li>Add <span class=\"lang:default decode:true  crayon-inline \">afcpu.lib</span>  or <span class=\"lang:default decode:true  crayon-inline \">afcuda.lib</span>  or <span class=\"lang:default decode:true  crayon-inline \">afopencl.lib</span>  to <em>Project Properties -&gt; Linker -&gt; Input -&gt; Additional Dependencies</em>. based on your preferred backend.</li>\r\n	<li>(Optional) You may choose to define <span class=\"lang:default decode:true  crayon-inline \">NOMINMAX, AF_CUDA</span>  and/or <span class=\"lang:default decode:true  crayon-inline \">AF_&lt;DEBUG/RELEASE&gt;</span>  in your projects. This can be added to <em>Project Properties -&gt; C/C++ -&gt; General -&gt; Preprocessor-&gt; Preprocessory definitions</em>.</li>\r\n	<li>Pick a solution to handle the NVVM DLLs. We recommend the post build event method used in <a href=\"#s3partA\">Part A</a>.</li>\r\n</ol>\r\n<h4><a id=\"s3partC\" class=\"anchor\"></a>Part C: Project with all ArrayFire backends</h4>\r\nIf you wish to create a project that allows you to use all the ArrayFire backends with ease, the best way to go is to copy the <em>HelloWorld sln/vcxproj/cpp</em> file trio and rename them to suit your project.\r\n\r\nAll the ArrayFire examples are pre-configured for all ArrayFire backends as well as the Unified API. These can be chosen from the Solution/Platform configuration drop down boxes.\r\n\r\nYou can alternately download the template project from <a href=\"https://github.com/arrayfire/arrayfire-project-templates\">ArrayFire Project Templates</a>\r\n<h4><a id=\"s3partD\" class=\"anchor\"></a>Part D: ArrayFire with CMake</h4>\r\n<em>NOTE:</em> The ArrayFire installer sets up CMake file and registry so that it can be found by CMake by simply using the <span class=\"lang:default decode:true  crayon-inline \">Find_PACKAGE(ArrayFire)</span>  command.\r\n\r\nIf you are writing a new ArrayFire project in C/C++ from scratch, we suggest you grab a copy of our <a href=\"https://github.com/arrayfire/arrayfire-project-templates\">CMake Project Example</a>; however, it is useful to read the documentation below in case you need to add ArrayFire to an existing project.\r\n\r\nAs <a href=\"#big-picture\">discussed above</a>, ArrayFire ships with a series of CMake scripts to make finding and using our library easy. The scripts will automatically find all versions of the ArrayFire library and pick the most powerful of the installed backends (typically CUDA).\r\n\r\nFirst create a file called <span class=\"lang:default decode:true  crayon-inline \">CMakeLists.txt</span>  in your project directory:\r\n<pre class=\"fragment\">cd your-project-directory\r\ntouch CMakeLists.txt\r\n</pre>\r\nand populate it with the following code:\r\n<pre class=\"fragment\">FIND_PACKAGE(ArrayFire)\r\nINCLUDE_DIRECTORIES(${ArrayFire_INCLUDE_DIRS})\r\n\r\n... [gather source files, etc.]\r\n\r\n# If you intend to use OpenCL, you need to find it\r\nFIND_PACKAGE(OpenCL)\r\nSET(EXTRA_LIBS ${CMAKE_THREAD_LIBS_INIT} ${OpenCL_LIBRARIES})\r\n\r\n# Or if you intend to use CUDA, you need it as well as NVVM:\r\nFIND_PACKAGE(CUDA)\r\nFIND_PACKAGE(NVVM) # this FIND script can be found in the ArrayFire CMake example repository\r\nSET(EXTRA_LIBS ${CMAKE_THREAD_LIBS_INIT} ${CUDA_LIBRARIES} ${NVVM_LIB})\r\n\r\nADD_EXECUTABLE(my_executable [list your source files here])\r\nTARGET_LINK_LIBRARIES(my_executable ${ArrayFire_LIBRARIES} ${EXTRA_LIBS})\r\n</pre>\r\nwhere <span class=\"lang:default decode:true  crayon-inline \">my_executable</span>  is the name of the executable you wish to create. See the <a href=\"https://cmake.org/documentation/\">CMake documentation</a> for more information on how to use CMake. Clearly the above code snippet precludes the use of both CUDA and OpenCL, see the <a href=\"https://github.com/bkloppenborg/arrayfire-cmake-example\">ArrayFire CMake Example</a> for an example of how to build executables for both backends from the same CMake script.\r\n\r\nIn the above code listing, the <span class=\"lang:default decode:true  crayon-inline \">FIND_PACKAGE</span>  will find the ArrayFire include files, libraries, and define several variables including:\r\n<pre class=\"fragment\">ArrayFire_INCLUDE_DIRS    - Location of ArrayFire\'s include directory.\r\nArrayFire_LIBRARIES       - Location of ArrayFire\'s libraries.\r\n                            This will default to a GPU backend if one\r\n                            is found\r\nArrayFire_FOUND           - True if ArrayFire has been located\r\n</pre>\r\nIf you wish to use a specific backend, the find script also defines these variables:\r\n<pre class=\"fragment\">ArrayFire_CPU_FOUND         - True of the ArrayFire CPU library has been found.\r\nArrayFire_CPU_LIBRARIES     - Location of ArrayFire\'s CPU library, if found\r\nArrayFire_CUDA_FOUND        - True of the ArrayFire CUDA library has been found.\r\nArrayFire_CUDA_LIBRARIES    - Location of ArrayFire\'s CUDA library, if found\r\nArrayFire_OpenCL_FOUND      - True of the ArrayFire OpenCL library has been found.\r\nArrayFire_OpenCL_LIBRARIES  - Location of ArrayFire\'s OpenCL library, if found\r\nArrayFire_Unified_FOUND     - True of the ArrayFire Unified library has been found.\r\nArrayFire_Unified_LIBRARIES - Location of ArrayFire\'s Unified library, if found\r\n</pre>\r\nTherefore, if you wish to target a specific specific backend, simply replace <span class=\"lang:default decode:true  crayon-inline \">${ArrayFire_LIBRARIES}</span>  with <span class=\"lang:default decode:true  crayon-inline \">${ArrayFire_CPU}</span> ,<span class=\"lang:default decode:true  crayon-inline \"> ${ArrayFire_OPENCL}</span> , <span class=\"lang:default decode:true  crayon-inline \">${ArrayFire_CUDA}</span> , or <span class=\"lang:default decode:true  crayon-inline \">${ArrayFire_Unified}</span>  in the <span class=\"lang:default decode:true  crayon-inline \">TARGET_LINK_LIBRARIES</span>  command above.\r\n\r\nNext we need to instruct CMake to create build instructions and then compile. We suggest using CMake\'s out-of-source build functionality to keep your build and source files cleanly separated. To do this open the CMake GUI.\r\n<ul>\r\n	<li>Under source directory, add the path to your project</li>\r\n	<li>Under build directory, add the path to your project and append /build</li>\r\n	<li>Click configure and choose Visual Studio 2013 Win 64 as the generator.</li>\r\n	<li>If configuration was successful, click generate. This will create a my-project.sln file under build. You can open this in Visual Studio and compile the ALL_BUILD project.</li>\r\n</ul>\r\nThe <a href=\"https://github.com/bkloppenborg/arrayfire-cmake-example\">ArrayFire CMake Example</a> is a CMake project used to demo how ArrayFire can be using with a CMake project.\r\n\r\nNote: The CMake project does not add the post build event to copy the NVVM DLLs in case of CUDA backend. You will need to either copy it manually to the exectuable directory, or pick another solution for it.\r\n\r\n</div>\r\n</div>','Setting up an ArrayFire project on Windows','','inherit','open','closed','','8546-revision-v1','','','2015-11-06 14:29:54','2015-11-06 14:29:54','',8546,'http://sandbox.arrayfire.com/8546-revision-v1/',0,'revision','',0),(8589,18528,'2015-11-06 20:49:45','2015-11-06 20:49:45','<div class=\"header\">\r\n<div class=\"headertitle\">\r\n<div class=\"title\">Continuing our blog series \"<a href=\"http://sandbox.arrayfire.com/tag/learning-arrayfire-from-scratch/\">Learning ArrayFire from scratch</a>\" today we will discuss how to set up an ArrayFire project on Windows using Visual Studio or CMake.</div>\r\n</div>\r\n</div>\r\n<!--more-->\r\n\r\nIf you have not already done so, please make sure you have installed, configured, and tested ArrayFire following the <a class=\"el\" href=\"installing.htm\">installation instructions</a>.\r\n<div class=\"contents\">\r\n<div class=\"textblock\">\r\n<h3>The big picture</h3>\r\nThe ArrayFire Windows installer creates the following:\r\n<pre class=\"lang:default highlight:0 decode:true \">AF_PATH                 Environment variable to point to the installation location.\r\n                        This is normally C:/Program Files/ArrayFire/v*\r\nAF_PATH/include         Header files for ArrayFire (Include Dir)\r\nAF_PATH/lib             All ArrayFire backends libraries, dlls and dependency dlls \r\n                        (Library dir)\r\nAF_PATH/examples        Examples to get started. Some examples also have pre-built \r\n                        exectuables\r\nAF_PATH/cmake           CMake config files for automatic configuration by external \r\n                        projects\r\nAF_PATH/uninstall.exe   Uninstaller\r\nAF_PATH/*               Other miscellenous files including licenses, logos, copyrights</pre>\r\nThe installer also appends <span class=\"lang:default decode:true  crayon-inline \">%AF_PATH%/lib</span>  to the User <span class=\"lang:default decode:true  crayon-inline \">PATH</span>  variable (see the <a class=\"el\" href=\"installing.htm\">installation instructions</a> for further details).\r\n<h4>Dealing with CUDA NVVM DLLs</h4>\r\nWhen using CUDA with ArrayFire you may encounter a linker error indicating the NVVM DLLs are missing. This is because the NVVM DLLs are not part of the standard <span class=\"lang:default decode:true  crayon-inline \">CUDA_PATH\\bin</span>  installation directory that is added to your <span class=\"lang:default decode:true  crayon-inline \">PATH</span>  when the CUDA installer runs. Thus, NVVM will not be found during the linking stage. There are a few ways to deal with this issue:\r\n<ol type=\"1\">\r\n	<li>Copy the DLLs to the executable location. This is, by far, the cleanest solution and we recommend doing this with ArrayFire projects. To do so, create a post-build event to copy the NVVM DLL as discussed below in <a href=\"#s3partA\">Step 3 - Part A</a>.</li>\r\n	<li>Copy <span class=\"lang:default decode:true  crayon-inline\">CUDA_PATH\\nvvm\\bin\\nvvm64_30_0.dll</span>  to <span class=\"lang:default decode:true  crayon-inline \">CUDA_PATH\\bin</span> . This is a one time copy such that the NVVM DLL is now with all the other CUDA dlls and in a directory that is a part of PATH and hence the DLL can be detected automatically.</li>\r\n	<li>Add <span class=\"lang:default decode:true  crayon-inline \">%CUDA_PATH%\\nvvm\\bin</span>  to the system PATH environment variable. This will allow automatic detection by the system and No further copying will be required. ArrayFire does not add this to PATH since the CUDA installer doesn\'t add it to PATH.</li>\r\n</ol>\r\n<h3><a id=\"step1\" class=\"anchor\"></a>Step 1: Running pre-built executables</h3>\r\nThe ArrayFire installer ships with a few pre-built executables with the examples. These should run out of the box when double clicked.\r\n\r\nSome prebuilt examples are:\r\n<ul>\r\n	<li>Helloworld (examples/helloworld)</li>\r\n	<li>BLAS (examples/benchmarks)</li>\r\n	<li>FFT (examples/benchmarks)</li>\r\n	<li>Pi Estimation (examples/benchmarks)</li>\r\n	<li>Conway (Graphics) (examples/graphics)</li>\r\n</ul>\r\nNote: For the CUDA executables, you will need to copy <span class=\"lang:default decode:true  crayon-inline \">CUDA_PATH\\nvvm\\bin\\nvvm64_30_0.dll</span>  to the location of the executables.\r\n<h3><a id=\"step2\" class=\"anchor\"></a>Step 2: Build and Run a Project</h3>\r\n<ol type=\"1\">\r\n	<li>Open Visual Studio 2013. Load the HelloWorld solution which is located at <span class=\"lang:default decode:true  crayon-inline \">AF_PATH/examples/helloworld/helloworld.sln</span> .</li>\r\n	<li>Build the <span class=\"lang:default decode:true  crayon-inline \">helloworld</span>  example. Be sure to, select the platform/configuration of your choice using the platform drop-down (the options are CPU, CUDA, OpenCL, and Unified) and Solution Configuration drop down (options of Release and Debug) menus.</li>\r\n	<li>Run the <span class=\"lang:default decode:true  crayon-inline \">helloworld</span>  example.</li>\r\n</ol>\r\n<h3><a id=\"step3\" class=\"anchor\"></a>Step 3: Using ArrayFire within Visual Studio</h3>\r\nThis is divided into 4 parts:\r\n<ul>\r\n	<li><a href=\"#s3partA\">Part A: Adding ArrayFire to an existing solution (Single Backend)</a></li>\r\n	<li><a href=\"#s3partB\">Part B: Adding ArrayFire CUDA to a new/existing CUDA project</a></li>\r\n	<li><a href=\"#s3partC\">Part C: Project with all ArrayFire backends</a></li>\r\n	<li><a href=\"#s3partD\">Part D: ArrayFire with CMake</a></li>\r\n</ul>\r\n<h4><a id=\"s3partA\" class=\"anchor\"></a>Part A: Adding ArrayFire to an existing solution (Single Backend)</h4>\r\nNote: If you plan on using native CUDA code in the project, use the steps under <a href=\"#s3partB\">Part B</a>.\r\n\r\nAdding a single backend to an existing project is quite simple.\r\n<ol type=\"1\">\r\n	<li>Add <code>\"<span class=\"lang:default decode:true  crayon-inline \">$(AF_PATH)/include;</span> \"</code> to <em>Project Properties -&gt; C/C++ -&gt; General -&gt; Additional Include Directories</em>.</li>\r\n	<li>Add <code>\"<span class=\"lang:default decode:true  crayon-inline \">$(AF_PATH)/lib;</span> \"</code> to <em>Project Properties -&gt; Linker -&gt; General -&gt; Additional Library Directories</em>.</li>\r\n	<li>Add <span class=\"lang:default decode:true  crayon-inline \">afcpu.lib</span>  or <span class=\"lang:default decode:true  crayon-inline \">afcuda.lib</span>  or <span class=\"lang:default decode:true  crayon-inline \">afopencl.lib</span>  to <em>Project Properties -&gt; Linker -&gt; Input -&gt; Additional Dependencies</em>. based on your preferred backend.</li>\r\n	<li>(Optional) You may choose to define <span class=\"lang:default decode:true  crayon-inline \">NOMINMAX, AF_&lt;CPU/CUDA/OPENCL&gt;</span>  and/or <span class=\"lang:default decode:true  crayon-inline \">AF_&lt;DEBUG/RELEASE&gt;</span>  in your projects. This can be added to <em>Project Properties -&gt; C/C++ -&gt; General -&gt; Preprocessor-&gt; Preprocessory definitions</em>.</li>\r\n</ol>\r\nIf you are using the CUDA backend, it is important to ensure that the CUDA NVVM DLLs are copied to the exectuable directory. This can be done by adding a post build event.\r\n\r\nOpen the <em>Project Properties -&gt; Build Events -&gt; Post Build Events</em> dialog and add the following lines to it.\r\n<div class=\"fragment\">\r\n<pre class=\"lang:default decode:true\">echo copy \"$(CUDA_PATH)\\nvvm\\bin\\nvvm64*.dll\" \"$(OutDir)\" \r\necho copy \"$(CUDA_PATH)\\nvvm\\bin\\nvvm64*.dll\" \"$(OutDir)\"</pre>\r\n<h4 class=\"line\"> <a id=\"s3partB\" class=\"anchor\"></a>Part B: Adding ArrayFire CUDA to a new/existing CUDA project</h4>\r\n</div>\r\nIf your project contains custom CUDA code, the instructions are slightly different as it requires using a CUDA NVCC Project:\r\n<ol type=\"1\">\r\n	<li>Create a custom \"CUDA NVCC project\" in Visual Studio</li>\r\n	<li>Add <code>\"<span class=\"lang:default decode:true  crayon-inline \">$(AF_PATH)/include;</span> \"</code> to <em>Project Properties -&gt; CUDA C/C++ -&gt; General -&gt; Additional Include Directories</em>.</li>\r\n	<li>Add <code>\"<span class=\"lang:default decode:true  crayon-inline \">$(AF_PATH)/lib;</span> \"</code> to <em>Project Properties -&gt; Linker -&gt; General -&gt; Additional Library Directories</em>.</li>\r\n	<li>Add <span class=\"lang:default decode:true  crayon-inline \">afcpu.lib</span>  or <span class=\"lang:default decode:true  crayon-inline \">afcuda.lib</span>  or <span class=\"lang:default decode:true  crayon-inline \">afopencl.lib</span>  to <em>Project Properties -&gt; Linker -&gt; Input -&gt; Additional Dependencies</em>. based on your preferred backend.</li>\r\n	<li>(Optional) You may choose to define <span class=\"lang:default decode:true  crayon-inline \">NOMINMAX, AF_CUDA</span>  and/or <span class=\"lang:default decode:true  crayon-inline \">AF_&lt;DEBUG/RELEASE&gt;</span>  in your projects. This can be added to <em>Project Properties -&gt; C/C++ -&gt; General -&gt; Preprocessor-&gt; Preprocessory definitions</em>.</li>\r\n	<li>Pick a solution to handle the NVVM DLLs. We recommend the post build event method used in <a href=\"#s3partA\">Part A</a>.</li>\r\n</ol>\r\n<h4><a id=\"s3partC\" class=\"anchor\"></a>Part C: Project with all ArrayFire backends</h4>\r\nIf you wish to create a project that allows you to use all the ArrayFire backends with ease, the best way to go is to copy the <em>HelloWorld sln/vcxproj/cpp</em> file trio and rename them to suit your project.\r\n\r\nAll the ArrayFire examples are pre-configured for all ArrayFire backends as well as the Unified API. These can be chosen from the Solution/Platform configuration drop down boxes.\r\n\r\nYou can alternately download the template project from <a href=\"https://github.com/arrayfire/arrayfire-project-templates\">ArrayFire Project Templates</a>\r\n<h4><a id=\"s3partD\" class=\"anchor\"></a>Part D: ArrayFire with CMake</h4>\r\n<em>NOTE:</em> The ArrayFire installer sets up CMake file and registry so that it can be found by CMake by simply using the <span class=\"lang:default decode:true  crayon-inline \">Find_PACKAGE(ArrayFire)</span>  command.\r\n\r\nIf you are writing a new ArrayFire project in C/C++ from scratch, we suggest you grab a copy of our <a href=\"https://github.com/arrayfire/arrayfire-project-templates\">CMake Project Example</a>; however, it is useful to read the documentation below in case you need to add ArrayFire to an existing project.\r\n\r\nAs <a href=\"#big-picture\">discussed above</a>, ArrayFire ships with a series of CMake scripts to make finding and using our library easy. The scripts will automatically find all versions of the ArrayFire library and pick the most powerful of the installed backends (typically CUDA).\r\n\r\nFirst create a file called <span class=\"lang:default decode:true  crayon-inline \">CMakeLists.txt</span>  in your project directory:\r\n<pre class=\"fragment\">cd your-project-directory\r\ntouch CMakeLists.txt\r\n</pre>\r\nand populate it with the following code:\r\n<pre class=\"fragment\">FIND_PACKAGE(ArrayFire)\r\nINCLUDE_DIRECTORIES(${ArrayFire_INCLUDE_DIRS})\r\n\r\n... [gather source files, etc.]\r\n\r\n# If you intend to use OpenCL, you need to find it\r\nFIND_PACKAGE(OpenCL)\r\nSET(EXTRA_LIBS ${CMAKE_THREAD_LIBS_INIT} ${OpenCL_LIBRARIES})\r\n\r\n# Or if you intend to use CUDA, you need it as well as NVVM:\r\nFIND_PACKAGE(CUDA)\r\nFIND_PACKAGE(NVVM) # this FIND script can be found in the ArrayFire CMake example repository\r\nSET(EXTRA_LIBS ${CMAKE_THREAD_LIBS_INIT} ${CUDA_LIBRARIES} ${NVVM_LIB})\r\n\r\nADD_EXECUTABLE(my_executable [list your source files here])\r\nTARGET_LINK_LIBRARIES(my_executable ${ArrayFire_LIBRARIES} ${EXTRA_LIBS})\r\n</pre>\r\nwhere <span class=\"lang:default decode:true  crayon-inline \">my_executable</span>  is the name of the executable you wish to create. See the <a href=\"https://cmake.org/documentation/\">CMake documentation</a> for more information on how to use CMake. Clearly the above code snippet precludes the use of both CUDA and OpenCL, see the <a href=\"https://github.com/bkloppenborg/arrayfire-cmake-example\">ArrayFire CMake Example</a> for an example of how to build executables for both backends from the same CMake script.\r\n\r\nIn the above code listing, the <span class=\"lang:default decode:true  crayon-inline \">FIND_PACKAGE</span>  will find the ArrayFire include files, libraries, and define several variables including:\r\n<pre class=\"fragment\">ArrayFire_INCLUDE_DIRS    - Location of ArrayFire\'s include directory.\r\nArrayFire_LIBRARIES       - Location of ArrayFire\'s libraries.\r\n                            This will default to a GPU backend if one\r\n                            is found\r\nArrayFire_FOUND           - True if ArrayFire has been located\r\n</pre>\r\nIf you wish to use a specific backend, the find script also defines these variables:\r\n<pre class=\"fragment\">ArrayFire_CPU_FOUND         - True of the ArrayFire CPU library has been found.\r\nArrayFire_CPU_LIBRARIES     - Location of ArrayFire\'s CPU library, if found\r\nArrayFire_CUDA_FOUND        - True of the ArrayFire CUDA library has been found.\r\nArrayFire_CUDA_LIBRARIES    - Location of ArrayFire\'s CUDA library, if found\r\nArrayFire_OpenCL_FOUND      - True of the ArrayFire OpenCL library has been found.\r\nArrayFire_OpenCL_LIBRARIES  - Location of ArrayFire\'s OpenCL library, if found\r\nArrayFire_Unified_FOUND     - True of the ArrayFire Unified library has been found.\r\nArrayFire_Unified_LIBRARIES - Location of ArrayFire\'s Unified library, if found\r\n</pre>\r\nTherefore, if you wish to target a specific specific backend, simply replace <span class=\"lang:default decode:true  crayon-inline \">${ArrayFire_LIBRARIES}</span>  with <span class=\"lang:default decode:true  crayon-inline \">${ArrayFire_CPU}</span> ,<span class=\"lang:default decode:true  crayon-inline \"> ${ArrayFire_OPENCL}</span> , <span class=\"lang:default decode:true  crayon-inline \">${ArrayFire_CUDA}</span> , or <span class=\"lang:default decode:true  crayon-inline \">${ArrayFire_Unified}</span>  in the <span class=\"lang:default decode:true  crayon-inline \">TARGET_LINK_LIBRARIES</span>  command above.\r\n\r\nNext we need to instruct CMake to create build instructions and then compile. We suggest using CMake\'s out-of-source build functionality to keep your build and source files cleanly separated. To do this open the CMake GUI.\r\n<ul>\r\n	<li>Under source directory, add the path to your project</li>\r\n	<li>Under build directory, add the path to your project and append /build</li>\r\n	<li>Click configure and choose Visual Studio 2013 Win 64 as the generator.</li>\r\n	<li>If configuration was successful, click generate. This will create a my-project.sln file under build. You can open this in Visual Studio and compile the ALL_BUILD project.</li>\r\n</ul>\r\nThe <a href=\"https://github.com/bkloppenborg/arrayfire-cmake-example\">ArrayFire CMake Example</a> is a CMake project used to demo how ArrayFire can be using with a CMake project.\r\n\r\nNote: The CMake project does not add the post build event to copy the NVVM DLLs in case of CUDA backend. You will need to either copy it manually to the exectuable directory, or pick another solution for it.\r\n\r\n</div>\r\n</div>','Setting up an ArrayFire project on Windows','','inherit','open','closed','','8546-revision-v1','','','2015-11-06 20:49:45','2015-11-06 20:49:45','',8546,'http://sandbox.arrayfire.com/8546-revision-v1/',0,'revision','',0);
INSERT INTO `wp_posts` VALUES (8590,18528,'2015-11-06 20:50:33','2015-11-06 20:50:33','Continuing our blog series \"<a href=\"http://sandbox.arrayfire.com/tag/learning-arrayfire-from-scratch/\">Learning ArrayFire from scratch</a>\" today we will discuss how to set up an ArrayFire project on Linux using CMake or standard makefiles.\r\n\r\n<!--more-->\r\n\r\nOnce you have <a class=\"el\" href=\"installing.htm\">installed</a> ArrayFire on your system, the next thing to do is set up your build system. On Linux, you can create ArrayFire projects using almost any editor, compiler, or build system. The only requirements are that you include the ArrayFire header directories and link with the ArrayFire library you intend to use.\r\n<h4>The big picture</h4>\r\nOn Linux, we suggest you install ArrayFire to the <span class=\"lang:default decode:true  crayon-inline\">/usr/local/</span>  directory so that all of the include files and libraries are part of your standard path. The installer will populate files in the following sub-directories:\r\n<pre class=\"lang:default highlight:0 decode:true fragment \">include/arrayfire.h         - Primary ArrayFire include file\r\ninclude/af/*.h              - Additional include files\r\nlib/libaf*                  - CPU, CUDA, and OpenCL libraries (.a, .so)\r\nlib/libforge*               - Visualization library\r\nshare/ArrayFire/cmake/*     - CMake config (find) scripts\r\nshare/ArrayFire/examples/*  - All ArrayFire examples\r\n</pre>\r\nBecause ArrayFire follows standard installation practices, you can use basically any build system to create and compile projects that use ArrayFire. Among the many possible build systems on Linux we suggest using ArrayFire with either CMake or Makefiles with CMake being our preferred build system.\r\n<h4>Prerequisite software</h4>\r\nTo build ArrayFire projects you will need a compiler\r\n<h5>Fedora, Centos and Redhat</h5>\r\nInstall EPEL repo (not required for Fedora)\r\n<div class=\"fragment\">\r\n<div class=\"line\">\r\n<pre class=\"lang:default decode:true \">yum install epel-release\r\nyum update</pre>\r\nInstall build dependencies\r\n\r\n</div>\r\n</div>\r\n<pre class=\"lang:default decode:true\">yum install gcc gcc-c++ cmake make</pre>\r\n<h5><strong>Debian and Ubuntu</strong></h5>\r\nInstall common dependencies\r\n<div class=\"fragment\">\r\n<div class=\"line\">\r\n<pre class=\"lang:default decode:true\">apt-get install build-essential cmake cmake-curses-gui</pre>\r\n</div>\r\n</div>\r\n<h4>CMake</h4>\r\nWe recommend that the CMake build system be used to create ArrayFire projects.f you are writing a new ArrayFire project in C/C++ from scratch, we suggest you grab a copy of our <a href=\"https://github.com/bkloppenborg/arrayfire-cmake-example\">CMake Project Example</a>; however, it is useful to read the documentation below in case you need to add ArrayFire to an existing project.\r\n\r\nAs <a href=\"#big-picture\">discussed above</a>, ArrayFire ships with a series of CMake scripts to make finding and using our library easy. The scripts will automatically find all versions of the ArrayFire library and pick the most powerful of the installed backends (typically CUDA).\r\n\r\nFirst create a file called <span class=\"lang:default decode:true  crayon-inline \">CMakeLists.txt</span>  in your project directory:\r\n<pre class=\"fragment\">cd your-project-directory\r\ntouch CMakeLists.txt\r\n</pre>\r\nand populate it with the following code:\r\n<pre class=\"fragment\">FIND_PACKAGE(ArrayFire)\r\nINCLUDE_DIRECTORIES(${ArrayFire_INCLUDE_DIRS})\r\n\r\n... [gather source files, etc.]\r\n\r\n# If you intend to use OpenCL, you need to find it\r\nFIND_PACKAGE(OpenCL)\r\nSET(EXTRA_LIBS ${CMAKE_THREAD_LIBS_INIT} ${OpenCL_LIBRARIES})\r\n\r\n# Or if you intend to use CUDA, you need it as well as NVVM:\r\nFIND_PACKAGE(CUDA)\r\nFIND_PACKAGE(NVVM) # this FIND script can be found in the ArrayFire CMake example repository\r\nSET(EXTRA_LIBS ${CMAKE_THREAD_LIBS_INIT} ${CUDA_LIBRARIES} ${NVVM_LIB})\r\n\r\nADD_EXECUTABLE(my_executable [list your source files here])\r\nTARGET_LINK_LIBRARIES(my_executable ${ArrayFire_LIBRARIES} ${EXTRA_LIBS})\r\n</pre>\r\nwhere <span class=\"lang:default decode:true  crayon-inline \">my_executable</span>  is the name of the executable you wish to create. See the <a href=\"https://cmake.org/documentation/\">CMake documentation</a> for more information on how to use CMake. Clearly the above code snippet precludes the use of both CUDA and OpenCL, see the <a href=\"https://github.com/bkloppenborg/arrayfire-cmake-example\">ArrayFire CMake Example</a> for an example of how to build executables for both backends from the same CMake script.\r\n<pre class=\"fragment\">ArrayFire_INCLUDE_DIRS    - Location of ArrayFire\'s include directory.\r\nArrayFire_LIBRARIES       - Location of ArrayFire\'s libraries. \r\n                            This will default to a GPU backend \r\n                            if one is found\r\nArrayFire_FOUND           - True if ArrayFire has been located\r\n</pre>\r\nIf you wish to use a specific backend, the find script also defines these variables:\r\n<pre class=\"fragment\">ArrayFire_CPU_FOUND         - True of the ArrayFire CPU library has been found.\r\nArrayFire_CPU_LIBRARIES     - Location of ArrayFire\'s CPU library, if found\r\nArrayFire_CUDA_FOUND        - True of the ArrayFire CUDA library has been found.\r\nArrayFire_CUDA_LIBRARIES    - Location of ArrayFire\'s CUDA library, if found\r\nArrayFire_OpenCL_FOUND      - True of the ArrayFire OpenCL library has been found.\r\nArrayFire_OpenCL_LIBRARIES  - Location of ArrayFire\'s OpenCL library, if found\r\nArrayFire_Unified_FOUND     - True of the ArrayFire Unified library has been found.\r\nArrayFire_Unified_LIBRARIES - Location of ArrayFire\'s Unified library, if found\r\n</pre>\r\nTherefore, if you wish to target a specific specific backend, simply replace <span class=\"lang:default decode:true  crayon-inline \">${ArrayFire_LIBRARIES}</span>  with<span class=\"lang:default decode:true  crayon-inline \">${ArrayFire_CPU}</span> , <span class=\"lang:default decode:true  crayon-inline \">${ArrayFire_OPENCL}</span> , <span class=\"lang:default decode:true  crayon-inline \">${ArrayFire_CUDA}</span> , or <span class=\"lang:default decode:true  crayon-inline \">${ArrayFire_Unified}</span>  in the<span class=\"lang:default decode:true  crayon-inline \">TARGET_LINK_LIBRARIES</span>  command above.\r\n\r\nNext we need to instruct CMake to create build instructions and then compile. We suggest using CMake\'s out-of-source build functionality to keep your build and source files cleanly separated. To do this:\r\n<pre class=\"fragment\">cd your-project-directory\r\nmkdir build\r\ncd build\r\ncmake ..\r\nmake\r\n</pre>\r\n<em>NOTE:</em> If you have installed ArrayFire to a non-standard location, CMake can still help you out. When you execute CMake specify the path to the <span class=\"lang:default decode:true  crayon-inline \">ArrayFireConfig*</span>  files that are found in the <span class=\"lang:default decode:true  crayon-inline \">share/ArrayFire/cmake</span>  subdirectory of the installation folder. For example, if ArrayFire were installed locally to <span class=\"lang:default decode:true  crayon-inline \">/opt/ArrayFire</span>  then you would modify the <span class=\"lang:default decode:true  crayon-inline \">cmake</span> command above to contain the following definition:\r\n<pre class=\"fragment\">cmake -DArrayFire_DIR=/opt/ArrayFire/share/ArrayFire/cmake ..\r\n</pre>\r\nYou can also specify this information in the <span class=\"lang:default decode:true  crayon-inline \">ccmake</span>  command-line interface.\r\n<h4>MakeFiles</h4>\r\nBuilding ArrayFire projects with Makefiles is fairly similar to CMake except you must specify all paths and libraries manually. As with any make project, you need to specify the include path to the directory containing <span class=\"lang:default decode:true  crayon-inline \">arrayfire.h</span> file. This should be <span class=\"lang:default decode:true  crayon-inline \">-I /usr/local/include</span>  if you followed our installation instructions. Similarly, you will need to specify the path to the ArrayFire library using the <code>-L</code> option (e.g. <span class=\"lang:default decode:true  crayon-inline \">-L/usr/local/lib</span> ) followed by the specific ArrayFire library you wish to use using the <code>-l</code> option (for example <span class=\"lang:default decode:true  crayon-inline\">-lafcpu</span> , <span class=\"lang:default decode:true  crayon-inline\">-lafopencl</span> , <span class=\"lang:default decode:true  crayon-inline \">-lafcuda</span> , or <span class=\"lang:default decode:true  crayon-inline \">-laf</span>  for the CPU, OpenCL, CUDA, and unified backends respectively.\r\n\r\nHere is a minimial example MakeFile which uses ArrayFire\'s CPU backend:\r\n<pre class=\"fragment\">LIBS=-lafcpu\r\nLIB_PATHS=-L/usr/lib\r\nINCLUDES=-I/usr/include\r\nCC=g++ $(COMPILER_OPTIONS)\r\nCOMPILER_OPTIONS=-std=c++11 -g\r\n\r\nall: main.cpp Makefile\r\n    $(CC) main.cpp -o test $(INCLUDES) $(LIBS) $(LIB_PATHS)</pre>\r\n&nbsp;','Setting up an ArrayFire project on Linux','','inherit','open','closed','','8568-revision-v1','','','2015-11-06 20:50:33','2015-11-06 20:50:33','',8568,'http://sandbox.arrayfire.com/8568-revision-v1/',0,'revision','',0),(8592,18528,'2015-11-10 17:56:29','2015-11-10 17:56:29','<div class=\"header\">\r\n<div class=\"headertitle\">\r\n<div class=\"title\">Continuing our blog series \"<a href=\"http://sandbox.arrayfire.com/tag/learning-arrayfire-from-scratch/\">Learning ArrayFire from scratch</a>\" today we will discuss how to set up an ArrayFire project on OSX using XCode, CMake, or Makefiles.</div>\r\n</div>\r\n</div>\r\n<!--more-->\r\n\r\nOnce you have <a class=\"el\" href=\"installing.htm\">installed</a> ArrayFire on your system, the next thing to do is set up your build system. On OSX, you may create ArrayFire project using almost any editor, compiler, or build system. The only requirement is that you can include the ArrayFire header directory, and link with the ArrayFire library you intend to use.\r\n<h3>The big picture</h3>\r\nBy default, the ArrayFire OSX installer will place several files in your computer\'s <span class=\"lang:default decode:true  crayon-inline \">/usr/local</span>  directory. The installer will populate this directory with files in the following sub-directories:\r\n<pre class=\"lang:default highlight:0 decode:true fragment \">include/arrayfire.h         - Primary ArrayFire include file\r\ninclude/af/*.h              - Additional include files\r\nlib/libaf*                  - CPU, CUDA, and OpenCL libraries (.a, .so)\r\nlib/libforge*               - Visualization library\r\nshare/ArrayFire/cmake/*     - CMake config (find) scripts\r\nshare/ArrayFire/examples/*  - All ArrayFire examples\r\n</pre>\r\nBecause ArrayFire follows standard installation practices, you can use basically any build system to create and compile projects that use ArrayFire. Among the many possible build systems on Linux we suggest using ArrayFire with either CMake or Makefiles with CMake being our preferred build system.\r\n<h3>XCode</h3>\r\nAlthough we recommend using CMake to build ArrayFire projects on OSX (because you can save on re-compiling some files for multiple-backend deployments), you can use XCode if this is your preferred development platform. To save some time, we have created an sample XCode project in our <a href=\"https://github.com/arrayfire/arrayfire-project-templates\">ArrayFire Project Templates repository</a> which is configured to build code for the CPU, OpenCL, CUDA, and Unified backends.\r\n\r\nTo set up a basic C/C++ project in XCode do the following:\r\n<ol type=\"1\">\r\n	<li>Start up XCode. Choose OSX -&gt; Application, Command Line Tool for the project:\r\n<div class=\"image\"><a href=\"http://sandbox.arrayfire.com/wp-content/uploads/2015/11/xcode-startup.png\"><img class=\"alignnone wp-image-8596\" src=\"http://sandbox.arrayfire.com/wp-content/uploads/2015/11/xcode-startup.png\" alt=\"xcode-startup\" width=\"650\" height=\"387\" /></a></div></li>\r\n	<li>Fill in the details for your project and choose either C or C++ for the project:\r\n<div class=\"image\"><a href=\"http://sandbox.arrayfire.com/wp-content/uploads/2015/11/project-options.png\"><img class=\"alignnone wp-image-8597\" src=\"http://sandbox.arrayfire.com/wp-content/uploads/2015/11/project-options.png\" alt=\"project-options\" width=\"650\" height=\"393\" /></a></div></li>\r\n	<li>Next we need to configure the build settings. In the left-hand pane, click on the project. In the center pane, click on \"Build Settings\" followed by the \"All\" button:\r\n<div class=\"image\"><a href=\"http://sandbox.arrayfire.com/wp-content/uploads/2015/11/build-settings1.png\"><img class=\"alignnone wp-image-8600\" src=\"http://sandbox.arrayfire.com/wp-content/uploads/2015/11/build-settings1.png\" alt=\"build-settings\" width=\"900\" height=\"602\" /></a></div></li>\r\n	<li>Now search for \"Header Search Paths\" and add <span class=\"lang:default decode:true  crayon-inline \">/usr/local/include</span>  to the list:\r\n<div class=\"image\"><a href=\"http://sandbox.arrayfire.com/wp-content/uploads/2015/11/header-search-paths.png\"><img class=\"alignnone wp-image-8601\" src=\"http://sandbox.arrayfire.com/wp-content/uploads/2015/11/header-search-paths.png\" alt=\"header-search-paths\" width=\"650\" height=\"279\" /></a></div></li>\r\n	<li>Then search for \"Library Search Paths\" and add <span class=\"lang:default decode:true  crayon-inline \">/usr/local/lib</span>  to the list:\r\n<div class=\"image\"><a href=\"http://sandbox.arrayfire.com/wp-content/uploads/2015/11/library-search-paths.png\"><img class=\"alignnone wp-image-8602\" src=\"http://sandbox.arrayfire.com/wp-content/uploads/2015/11/library-search-paths.png\" alt=\"library-search-paths\" width=\"650\" height=\"285\" /></a></div></li>\r\n	<li>Next, we need to make sure the executable is linked with an ArrayFire library: To do this, click the \"Build Phases\" tab and expand the \"Link with Binary Library\" menu:\r\n<div class=\"image\"><a href=\"http://sandbox.arrayfire.com/wp-content/uploads/2015/11/build-phases.png\"><img class=\"alignnone wp-image-8603\" src=\"http://sandbox.arrayfire.com/wp-content/uploads/2015/11/build-phases.png\" alt=\"build-phases\" width=\"900\" height=\"269\" /></a></div></li>\r\n	<li>In the search dialog that pops up, choose the \"Add Other\" button from the lower right. Specify the<span class=\"lang:default decode:true  crayon-inline \">/usr/local/lib</span>  folder:\r\n<div class=\"image\"><a href=\"http://sandbox.arrayfire.com/wp-content/uploads/2015/11/library-folder-path.png\"><img class=\"alignnone wp-image-8599\" src=\"http://sandbox.arrayfire.com/wp-content/uploads/2015/11/library-folder-path.png\" alt=\"library-folder-path\" width=\"650\" height=\"567\" /></a></div></li>\r\n	<li>Next, select the ArrayFire library with which you wish to link your program. Your options will be:</li>\r\n</ol>\r\n<div class=\"fragment\">\r\n<div class=\"line\">\r\n<pre class=\"lang:default highlight:0 decode:true\">libafcuda.*.dylib   - CUDA backend\r\nlibafopencl.*.dylib - OpenCL backend\r\nlibafcpu.*.dylib    - CPU backend\r\nlibaf.*.dylib       - Unified backend</pre>\r\nIn the picture below, we have elected to link with the OpenCL backend:\r\n\r\n<a href=\"http://sandbox.arrayfire.com/wp-content/uploads/2015/11/pick-arrayfire-library.png\"><img class=\"alignnone wp-image-8598\" src=\"http://sandbox.arrayfire.com/wp-content/uploads/2015/11/pick-arrayfire-library.png\" alt=\"pick-arrayfire-library\" width=\"650\" height=\"566\" /></a>\r\n\r\n</div>\r\n</div>\r\n9. Lastly, lets test ArrayFire\'s functionality. In the left hand pane open the main.cpp` file and insert the following code:\r\n<div class=\"image\"></div>\r\n<div class=\"fragment\">\r\n<div class=\"line\">\r\n<pre class=\"lang:default decode:true\"> // Include the ArrayFire header file\r\n#include &lt;arrayfire.h&gt;\r\n \r\nint main(int argc, const char * argv[]) {\r\n   // Gather some information about the ArrayFire device\r\n   af::info();\r\n   return 0;\r\n}</pre>\r\n&nbsp;\r\n\r\n</div>\r\n</div>\r\nFinally, click the build button and you should see some information about your graphics card in the lower-section of your screen:\r\n<div class=\"image\"><a href=\"http://sandbox.arrayfire.com/wp-content/uploads/2015/11/afinfo-result.png\"><img class=\"alignnone wp-image-8594 size-full\" src=\"http://sandbox.arrayfire.com/wp-content/uploads/2015/11/afinfo-result.png\" alt=\"afinfo-result\" width=\"477\" height=\"135\" /></a></div>\r\n<h3>CMake</h3>\r\nWe recommend that the CMake build system be used to create ArrayFire projects. If you are writing a new ArrayFire project in C/C++ from scratch, we suggest you grab a copy of our <a href=\"https://github.com/arrayfire/arrayfire-project-templates\">CMake Project Example</a>; however, it is useful to read the documentation below in case you need to add ArrayFire to an existing project.\r\n\r\nAs <a href=\"#big-picture\">discussed above</a>, ArrayFire ships with a series of CMake scripts to make finding and using our library easy. The scripts will automatically find all versions of the ArrayFire library and pick the most powerful of the installed backends (typically CUDA).\r\n\r\nFirst create a file called<span class=\"lang:default decode:true  crayon-inline \"> CMakeLists.txt</span>  in your project directory:\r\n<pre class=\"lang:default decode:true fragment\">cd your-project-directory\r\ntouch CMakeLists.txt\r\n</pre>\r\nand populate it with the following code:\r\n<pre class=\"fragment\">FIND_PACKAGE(ArrayFire)\r\nINCLUDE_DIRECTORIES(${ArrayFire_INCLUDE_DIRS})\r\n\r\n... [gather source files, etc.]\r\n\r\n# If you intend to use OpenCL, you need to find it\r\nFIND_PACKAGE(OpenCL)\r\nSET(EXTRA_LIBS ${CMAKE_THREAD_LIBS_INIT} ${OpenCL_LIBRARIES})\r\n\r\n# Or if you intend to use CUDA, you need it as well as NVVM:\r\nFIND_PACKAGE(CUDA)\r\nFIND_PACKAGE(NVVM) # this FIND script can be found in the ArrayFire CMake example repository\r\nSET(EXTRA_LIBS ${CMAKE_THREAD_LIBS_INIT} ${CUDA_LIBRARIES} ${NVVM_LIB})\r\n\r\nADD_EXECUTABLE(my_executable [list your source files here])\r\nTARGET_LINK_LIBRARIES(my_executable ${ArrayFire_LIBRARIES} ${EXTRA_LIBS})\r\n</pre>\r\nwhere <span class=\"lang:default decode:true  crayon-inline \">my_executable</span>  is the name of the executable you wish to create. See the <a href=\"https://cmake.org/documentation/\">CMake documentation</a> for more information on how to use CMake. Clearly the above code snippet precludes the use of both CUDA and OpenCL, see the<a href=\"https://github.com/bkloppenborg/arrayfire-cmake-example\">ArrayFire CMake Example</a> for an example of how to build executables for both backends from the same CMake script.\r\n\r\nIn the above code listing, the <span class=\"lang:default decode:true  crayon-inline \">FIND_PACKAGE</span>  will find the ArrayFire include files, libraries, and define several variables including:\r\n<pre class=\"lang:default highlight:0 decode:true fragment\">ArrayFire_INCLUDE_DIRS    - Location of ArrayFire\'s include directory.\r\nArrayFire_LIBRARIES       - Location of ArrayFire\'s libraries.\r\n                            This will default to a GPU backend if one\r\n                            is found\r\nArrayFire_FOUND           - True if ArrayFire has been located\r\n</pre>\r\nIf you wish to use a specific backend, the find script also defines these variables:\r\n<pre class=\"lang:default highlight:0 decode:true fragment \">ArrayFire_CPU_FOUND         - True of the ArrayFire CPU library has been found.\r\nArrayFire_CPU_LIBRARIES     - Location of ArrayFire\'s CPU library, if found\r\nArrayFire_CUDA_FOUND        - True of the ArrayFire CUDA library has been found.\r\nArrayFire_CUDA_LIBRARIES    - Location of ArrayFire\'s CUDA library, if found\r\nArrayFire_OpenCL_FOUND      - True of the ArrayFire OpenCL library has been found.\r\nArrayFire_OpenCL_LIBRARIES  - Location of ArrayFire\'s OpenCL library, if found\r\nArrayFire_Unified_FOUND     - True of the ArrayFire Unified library has been found.\r\nArrayFire_Unified_LIBRARIES - Location of ArrayFire\'s Unified library, if found\r\n</pre>\r\nTherefore, if you wish to target a specific specific backend, simply replace <span class=\"lang:default decode:true  crayon-inline \">${ArrayFire_LIBRARIES}</span>  with<span class=\"lang:default decode:true  crayon-inline \">${ArrayFire_CPU}</span> , <span class=\"lang:default decode:true  crayon-inline \">${ArrayFire_OPENCL}</span> , <span class=\"lang:default decode:true  crayon-inline \">${ArrayFire_CUDA}</span> , or <code>${ArrayFire_Unified}</code> in the<span class=\"lang:default decode:true  crayon-inline \">TARGET_LINK_LIBRARIES</span>  command above. If you intend on building your software to link with all of these backends, please see the <a href=\"https://github.com/arrayfire/arrayfire-project-templates\">CMake Project Example</a> which makes use of some fairly fun CMake tricks to avoid re-compiling code whenever possible.\r\n\r\nNext we need to instruct CMake to create build instructions and then compile. We suggest using CMake\'s out-of-source build functionality to keep your build and source files cleanly separated. To do this:\r\n<pre class=\"fragment\">cd your-project-directory\r\nmkdir build\r\ncd build\r\ncmake ..\r\nmake\r\n</pre>\r\n<em>NOTE:</em> If you have installed ArrayFire to a non-standard location, CMake can still help you out. When you execute CMake specify the path to the <span class=\"lang:default decode:true  crayon-inline \">ArrayFireConfig*</span>  files that are found in the <span class=\"lang:default decode:true  crayon-inline \">share/ArrayFire/cmake</span>  subdirectory of the installation folder. For example, if ArrayFire were installed locally to <span class=\"lang:default decode:true  crayon-inline \">/opt/ArrayFire</span>  then you would modify the <span class=\"lang:default decode:true  crayon-inline \">cmake</span> command above to contain the following definition:\r\n<pre class=\"fragment\">cmake -DArrayFire_DIR=/opt/ArrayFire/share/ArrayFire/cmake ..\r\n</pre>\r\nYou can also specify this information in the ccmake command-line interface.\r\n<h3>MakeFiles</h3>\r\nBuilding ArrayFire projects with Makefiles is fairly similar to CMake except you must specify all paths and libraries manually. As with any make project, you need to specify the include path to the directory containing <code><a class=\"el\" href=\"arrayfire_8h.htm\">arrayfire.h</a></code> file. This should be <span class=\"lang:default decode:true  crayon-inline \">-I /usr/local/include</span>  if you followed our installation instructions. Similarly, you will need to specify the path to the ArrayFire library using the <span class=\"lang:default decode:true  crayon-inline \">-L</span>  option (e.g. <span class=\"lang:default decode:true  crayon-inline \">-L/usr/local/lib</span> ) followed by the specific ArrayFire library you wish to use using the <code>-l</code> option (for example <span class=\"lang:default decode:true  crayon-inline \">-lafcpu</span> , <span class=\"lang:default decode:true  crayon-inline \">-lafopencl</span> , <span class=\"lang:default decode:true  crayon-inline \">-lafcuda</span> , or <span class=\"lang:default decode:true  crayon-inline \">-laf</span>  for the CPU, OpenCL, CUDA, and unified backends respectively.\r\n\r\nHere is a minimial example MakeFile which uses ArrayFire\'s CPU backend:\r\n<pre class=\"fragment\">LIBS=-lafcpu\r\nLIB_PATHS=-L/usr/lib\r\nINCLUDES=-I/usr/include\r\nCC=g++ $(COMPILER_OPTIONS)\r\nCOMPILER_OPTIONS=-std=c++11 -g\r\n\r\nall: main.cpp Makefile\r\n    $(CC) main.cpp -o test $(INCLUDES) $(LIBS) $(LIB_PATHS)</pre>','Setting up an ArrayFire Project on OSX','','publish','open','closed','','setting-up-an-arrayfire-project-on-osx','','','2015-11-10 17:56:29','2015-11-10 17:56:29','',0,'http://sandbox.arrayfire.com/?p=8592',0,'post','',0),(8593,18528,'2015-11-06 22:05:35','2015-11-06 22:05:35','<div class=\"header\">\r\n<div class=\"headertitle\">\r\n<div class=\"title\">Continuing our blog series \"<a href=\"http://sandbox.arrayfire.com/tag/learning-arrayfire-from-scratch/\">Learning ArrayFire from scratch</a>\" today we will discuss how to set up an ArrayFire project on OSX using XCode, CMake, or Makefiles.</div>\r\n<div class=\"title\"></div>\r\n</div>\r\n</div>\r\n<!--more-->','Setting up an ArrayFire Project on OSX','','inherit','open','closed','','8592-revision-v1','','','2015-11-06 22:05:35','2015-11-06 22:05:35','',8592,'http://sandbox.arrayfire.com/8592-revision-v1/',0,'revision','',0),(8594,18528,'2015-11-06 22:07:27','2015-11-06 22:07:27','','afinfo-result','','inherit','open','closed','','afinfo-result','','','2015-11-06 22:07:27','2015-11-06 22:07:27','',8592,'http://sandbox.arrayfire.com/wp-content/uploads/2015/11/afinfo-result.png',0,'attachment','image/png',0),(8595,18528,'2015-11-06 22:07:39','2015-11-06 22:07:39','','build-settings','','inherit','open','closed','','build-settings','','','2015-11-06 22:07:39','2015-11-06 22:07:39','',8592,'http://sandbox.arrayfire.com/wp-content/uploads/2015/11/build-settings.png',0,'attachment','image/png',0),(8596,18528,'2015-11-06 22:08:04','2015-11-06 22:08:04','','xcode-startup','','inherit','open','closed','','xcode-startup','','','2015-11-06 22:08:04','2015-11-06 22:08:04','',8592,'http://sandbox.arrayfire.com/wp-content/uploads/2015/11/xcode-startup.png',0,'attachment','image/png',0),(8597,18528,'2015-11-06 22:08:33','2015-11-06 22:08:33','','project-options','','inherit','open','closed','','project-options','','','2015-11-06 22:08:33','2015-11-06 22:08:33','',8592,'http://sandbox.arrayfire.com/wp-content/uploads/2015/11/project-options.png',0,'attachment','image/png',0),(8598,18528,'2015-11-06 22:10:26','2015-11-06 22:10:26','','pick-arrayfire-library','','inherit','open','closed','','pick-arrayfire-library','','','2015-11-06 22:10:26','2015-11-06 22:10:26','',8592,'http://sandbox.arrayfire.com/wp-content/uploads/2015/11/pick-arrayfire-library.png',0,'attachment','image/png',0),(8599,18528,'2015-11-06 22:10:51','2015-11-06 22:10:51','','library-folder-path','','inherit','open','closed','','library-folder-path','','','2015-11-06 22:10:51','2015-11-06 22:10:51','',8592,'http://sandbox.arrayfire.com/wp-content/uploads/2015/11/library-folder-path.png',0,'attachment','image/png',0),(8600,18528,'2015-11-06 22:11:09','2015-11-06 22:11:09','','build-settings','','inherit','open','closed','','build-settings-2','','','2015-11-06 22:11:09','2015-11-06 22:11:09','',8592,'http://sandbox.arrayfire.com/wp-content/uploads/2015/11/build-settings1.png',0,'attachment','image/png',0),(8601,18528,'2015-11-06 22:11:21','2015-11-06 22:11:21','','header-search-paths','','inherit','open','closed','','header-search-paths','','','2015-11-06 22:11:21','2015-11-06 22:11:21','',8592,'http://sandbox.arrayfire.com/wp-content/uploads/2015/11/header-search-paths.png',0,'attachment','image/png',0),(8602,18528,'2015-11-06 22:11:33','2015-11-06 22:11:33','','library-search-paths','','inherit','open','closed','','library-search-paths','','','2015-11-06 22:11:33','2015-11-06 22:11:33','',8592,'http://sandbox.arrayfire.com/wp-content/uploads/2015/11/library-search-paths.png',0,'attachment','image/png',0),(8603,18528,'2015-11-06 22:11:43','2015-11-06 22:11:43','','build-phases','','inherit','open','closed','','build-phases','','','2015-11-06 22:11:43','2015-11-06 22:11:43','',8592,'http://sandbox.arrayfire.com/wp-content/uploads/2015/11/build-phases.png',0,'attachment','image/png',0),(8604,18528,'2015-11-06 22:18:18','2015-11-06 22:18:18','<div class=\"header\">\r\n<div class=\"headertitle\">\r\n<div class=\"title\">Continuing our blog series \"<a href=\"http://sandbox.arrayfire.com/tag/learning-arrayfire-from-scratch/\">Learning ArrayFire from scratch</a>\" today we will discuss how to set up an ArrayFire project on OSX using XCode, CMake, or Makefiles.</div>\r\n</div>\r\n</div>\r\n<!--more-->\r\n\r\nOnce you have <a class=\"el\" href=\"installing.htm\">installed</a> ArrayFire on your system, the next thing to do is set up your build system. On OSX, you may create ArrayFire project using almost any editor, compiler, or build system. The only requirement is that you can include the ArrayFire header directory, and link with the ArrayFire library you intend to use.\r\n<h2>The big picture</h2>\r\nBy default, the ArrayFire OSX installer will place several files in your computer\'s <span class=\"lang:default decode:true  crayon-inline \">/usr/local</span>  directory. The installer will populate this directory with files in the following sub-directories:\r\n<pre class=\"fragment\">include/arrayfire.h         - Primary ArrayFire include file\r\ninclude/af/*.h              - Additional include files\r\nlib/libaf*                  - CPU, CUDA, and OpenCL libraries (.a, .so)\r\nlib/libforge*               - Visualization library\r\nshare/ArrayFire/cmake/*     - CMake config (find) scripts\r\nshare/ArrayFire/examples/*  - All ArrayFire examples\r\n</pre>\r\nBecause ArrayFire follows standard installation practices, you can use basically any build system to create and compile projects that use ArrayFire. Among the many possible build systems on Linux we suggest using ArrayFire with either CMake or Makefiles with CMake being our preferred build system.\r\n<h2>XCode</h2>\r\nAlthough we recommend using CMake to build ArrayFire projects on OSX, you can use XCode if this is your preferred development platform. To set up a basic C/C++ project in XCode do the following:\r\n<ol type=\"1\">\r\n	<li>Start up XCode. Choose OSX -&gt; Application, Command Line Tool for the project:\r\n<div class=\"image\"><a href=\"http://sandbox.arrayfire.com/wp-content/uploads/2015/11/xcode-startup.png\"><img class=\"alignnone wp-image-8596\" src=\"http://sandbox.arrayfire.com/wp-content/uploads/2015/11/xcode-startup.png\" alt=\"xcode-startup\" width=\"650\" height=\"387\" /></a></div></li>\r\n	<li>Fill in the details for your project and choose either C or C++ for the project:\r\n<div class=\"image\"><a href=\"http://sandbox.arrayfire.com/wp-content/uploads/2015/11/project-options.png\"><img class=\"alignnone wp-image-8597\" src=\"http://sandbox.arrayfire.com/wp-content/uploads/2015/11/project-options.png\" alt=\"project-options\" width=\"650\" height=\"393\" /></a></div></li>\r\n	<li>Next we need to configure the build settings. In the left-hand pane, click on the project. In the center pane, click on \"Build Settings\" followed by the \"All\" button:\r\n<div class=\"image\"><a href=\"http://sandbox.arrayfire.com/wp-content/uploads/2015/11/build-settings1.png\"><img class=\"alignnone wp-image-8600\" src=\"http://sandbox.arrayfire.com/wp-content/uploads/2015/11/build-settings1.png\" alt=\"build-settings\" width=\"900\" height=\"602\" /></a></div></li>\r\n	<li>Now search for \"Header Search Paths\" and add <code>/usr/local/include</code> to the list:\r\n<div class=\"image\"><a href=\"http://sandbox.arrayfire.com/wp-content/uploads/2015/11/header-search-paths.png\"><img class=\"alignnone wp-image-8601\" src=\"http://sandbox.arrayfire.com/wp-content/uploads/2015/11/header-search-paths.png\" alt=\"header-search-paths\" width=\"650\" height=\"279\" /></a></div></li>\r\n	<li>Then search for \"Library Search Paths\" and add <code>/usr/local/lib</code> to the list:\r\n<div class=\"image\"><a href=\"http://sandbox.arrayfire.com/wp-content/uploads/2015/11/library-search-paths.png\"><img class=\"alignnone wp-image-8602\" src=\"http://sandbox.arrayfire.com/wp-content/uploads/2015/11/library-search-paths.png\" alt=\"library-search-paths\" width=\"650\" height=\"285\" /></a></div></li>\r\n	<li>Next, we need to make sure the executable is linked with an ArrayFire library: To do this, click the \"Build Phases\" tab and expand the \"Link with Binary Library\" menu:\r\n<div class=\"image\"><a href=\"http://sandbox.arrayfire.com/wp-content/uploads/2015/11/build-phases.png\"><img class=\"alignnone wp-image-8603\" src=\"http://sandbox.arrayfire.com/wp-content/uploads/2015/11/build-phases.png\" alt=\"build-phases\" width=\"900\" height=\"269\" /></a></div></li>\r\n	<li>In the search dialog that pops up, choose the \"Add Other\" button from the lower right. Specify the<code>/usr/local/lib</code> folder:\r\n<div class=\"image\"><a href=\"http://sandbox.arrayfire.com/wp-content/uploads/2015/11/library-folder-path.png\"><img class=\"alignnone wp-image-8599\" src=\"http://sandbox.arrayfire.com/wp-content/uploads/2015/11/library-folder-path.png\" alt=\"library-folder-path\" width=\"650\" height=\"567\" /></a></div></li>\r\n	<li>Lastly, select the ArrayFire library with which you wish to link your program. Your options will be:</li>\r\n</ol>\r\n<div class=\"fragment\">\r\n<div class=\"line\">\r\n<pre class=\"lang:default decode:true \">libafcuda.*.dylib   - CUDA backend\r\nlibafopencl.*.dylib - OpenCL backend\r\nlibafcpu.*.dylib    - CPU backend\r\nlibaf.*.dylib       - Unified backend</pre>\r\nIn the picture below, we have elected to link with the OpenCL backend:\r\n\r\n<a href=\"http://sandbox.arrayfire.com/wp-content/uploads/2015/11/pick-arrayfire-library.png\"><img class=\"alignnone wp-image-8598\" src=\"http://sandbox.arrayfire.com/wp-content/uploads/2015/11/pick-arrayfire-library.png\" alt=\"pick-arrayfire-library\" width=\"650\" height=\"566\" /></a>\r\n\r\n</div>\r\n</div>\r\n9. Lastly, lets test ArrayFire\'s functionality. In the left hand pane open the main.cpp` file and insert the following code:\r\n<div class=\"image\"></div>\r\n<div class=\"fragment\">\r\n<div class=\"line\">\r\n<pre class=\"lang:default decode:true \"> // Include the ArrayFire header file\r\n#include &lt;arrayfire.h&gt;\r\n \r\nint main(int argc, const char * argv[]) {\r\n   // Gather some information about the ArrayFire device\r\n   af::info();\r\n   return 0;\r\n}</pre>\r\n&nbsp;\r\n\r\n</div>\r\n</div>\r\nFinally, click the build button and you should see some information about your graphics card in the lower-section of your screen:\r\n<div class=\"image\"><a href=\"http://sandbox.arrayfire.com/wp-content/uploads/2015/11/afinfo-result.png\"><img class=\"alignnone size-medium wp-image-8594\" src=\"http://sandbox.arrayfire.com/wp-content/uploads/2015/11/afinfo-result-300x85.png\" alt=\"afinfo-result\" width=\"300\" height=\"85\" /></a></div>\r\n<h2>CMake</h2>\r\nWe recommend that the CMake build system be used to create ArrayFire projects. If you are writing a new ArrayFire project in C/C++ from scratch, we suggest you grab a copy of our <a href=\"https://github.com/arrayfire/arrayfire-project-templates\">CMake Project Example</a>; however, it is useful to read the documentation below in case you need to add ArrayFire to an existing project.\r\n\r\nAs <a href=\"#big-picture\">discussed above</a>, ArrayFire ships with a series of CMake scripts to make finding and using our library easy. The scripts will automatically find all versions of the ArrayFire library and pick the most powerful of the installed backends (typically CUDA).\r\n\r\nFirst create a file called <code>CMakeLists.txt</code> in your project directory:\r\n<pre class=\"fragment\">cd your-project-directory\r\ntouch CMakeLists.txt\r\n</pre>\r\nand populate it with the following code:\r\n<pre class=\"fragment\">FIND_PACKAGE(ArrayFire)\r\nINCLUDE_DIRECTORIES(${ArrayFire_INCLUDE_DIRS})\r\n\r\n... [gather source files, etc.]\r\n\r\n# If you intend to use OpenCL, you need to find it\r\nFIND_PACKAGE(OpenCL)\r\nSET(EXTRA_LIBS ${CMAKE_THREAD_LIBS_INIT} ${OpenCL_LIBRARIES})\r\n\r\n# Or if you intend to use CUDA, you need it as well as NVVM:\r\nFIND_PACKAGE(CUDA)\r\nFIND_PACKAGE(NVVM) # this FIND script can be found in the ArrayFire CMake example repository\r\nSET(EXTRA_LIBS ${CMAKE_THREAD_LIBS_INIT} ${CUDA_LIBRARIES} ${NVVM_LIB})\r\n\r\nADD_EXECUTABLE(my_executable [list your source files here])\r\nTARGET_LINK_LIBRARIES(my_executable ${ArrayFire_LIBRARIES} ${EXTRA_LIBS})\r\n</pre>\r\nwhere <code>my_executable</code> is the name of the executable you wish to create. See the <a href=\"https://cmake.org/documentation/\">CMake documentation</a> for more information on how to use CMake. Clearly the above code snippet precludes the use of both CUDA and OpenCL, see the<a href=\"https://github.com/bkloppenborg/arrayfire-cmake-example\">ArrayFire CMake Example</a> for an example of how to build executables for both backends from the same CMake script.\r\n\r\nIn the above code listing, the <code>FIND_PACKAGE</code> will find the ArrayFire include files, libraries, and define several variables including:\r\n<pre class=\"fragment\">ArrayFire_INCLUDE_DIRS    - Location of ArrayFire\'s include directory.\r\nArrayFire_LIBRARIES       - Location of ArrayFire\'s libraries.\r\n                            This will default to a GPU backend if one\r\n                            is found\r\nArrayFire_FOUND           - True if ArrayFire has been located\r\n</pre>\r\nIf you wish to use a specific backend, the find script also defines these variables:\r\n<pre class=\"fragment\">ArrayFire_CPU_FOUND         - True of the ArrayFire CPU library has been found.\r\nArrayFire_CPU_LIBRARIES     - Location of ArrayFire\'s CPU library, if found\r\nArrayFire_CUDA_FOUND        - True of the ArrayFire CUDA library has been found.\r\nArrayFire_CUDA_LIBRARIES    - Location of ArrayFire\'s CUDA library, if found\r\nArrayFire_OpenCL_FOUND      - True of the ArrayFire OpenCL library has been found.\r\nArrayFire_OpenCL_LIBRARIES  - Location of ArrayFire\'s OpenCL library, if found\r\nArrayFire_Unified_FOUND     - True of the ArrayFire Unified library has been found.\r\nArrayFire_Unified_LIBRARIES - Location of ArrayFire\'s Unified library, if found\r\n</pre>\r\nTherefore, if you wish to target a specific specific backend, simply replace <code>${ArrayFire_LIBRARIES}</code> with<code>${ArrayFire_CPU}</code>, <code>${ArrayFire_OPENCL}</code>, <code>${ArrayFire_CUDA}</code>, or <code>${ArrayFire_Unified}</code> in the<code>TARGET_LINK_LIBRARIES</code> command above. If you intend on building your software to link with all of these backends, please see the <a href=\"https://github.com/arrayfire/arrayfire-project-templates\">CMake Project Example</a> which makes use of some fairly fun CMake tricks to avoid re-compiling code whenever possible.\r\n\r\nNext we need to instruct CMake to create build instructions and then compile. We suggest using CMake\'s out-of-source build functionality to keep your build and source files cleanly separated. To do this:\r\n<pre class=\"fragment\">cd your-project-directory\r\nmkdir build\r\ncd build\r\ncmake ..\r\nmake\r\n</pre>\r\n<em>NOTE:</em> If you have installed ArrayFire to a non-standard location, CMake can still help you out. When you execute CMake specify the path to the <code>ArrayFireConfig*</code> files that are found in the <code>share/ArrayFire/cmake</code> subdirectory of the installation folder. For example, if ArrayFire were installed locally to <code>/opt/ArrayFire</code> then you would modify the <code>cmake</code>command above to contain the following definition:\r\n<pre class=\"fragment\">cmake -DArrayFire_DIR=/opt/ArrayFire/share/ArrayFire/cmake ..\r\n</pre>\r\nYou can also specify this information in the ccmake command-line interface.\r\n<h2>MakeFiles</h2>\r\nBuilding ArrayFire projects with Makefiles is fairly similar to CMake except you must specify all paths and libraries manually. As with any make project, you need to specify the include path to the directory containing <code><a class=\"el\" href=\"arrayfire_8h.htm\">arrayfire.h</a></code> file. This should be <code>-I /usr/local/include</code> if you followed our installation instructions. Similarly, you will need to specify the path to the ArrayFire library using the <code>-L</code> option (e.g. <code>-L/usr/local/lib</code>) followed by the specific ArrayFire library you wish to use using the <code>-l</code> option (for example <code>-lafcpu</code>, <code>-lafopencl</code>, <code>-lafcuda</code>, or <code>-laf</code> for the CPU, OpenCL, CUDA, and unified backends respectively.\r\n\r\nHere is a minimial example MakeFile which uses ArrayFire\'s CPU backend:\r\n<pre class=\"fragment\">LIBS=-lafcpu\r\nLIB_PATHS=-L/usr/lib\r\nINCLUDES=-I/usr/include\r\nCC=g++ $(COMPILER_OPTIONS)\r\nCOMPILER_OPTIONS=-std=c++11 -g\r\n\r\nall: main.cpp Makefile\r\n    $(CC) main.cpp -o test $(INCLUDES) $(LIBS) $(LIB_PATHS)</pre>','Setting up an ArrayFire Project on OSX','','inherit','open','closed','','8592-revision-v1','','','2015-11-06 22:18:18','2015-11-06 22:18:18','',8592,'http://sandbox.arrayfire.com/8592-revision-v1/',0,'revision','',0),(8605,18528,'2015-11-06 22:21:20','2015-11-06 22:21:20','<div class=\"header\">\r\n<div class=\"headertitle\">\r\n<div class=\"title\">Continuing our blog series \"<a href=\"http://sandbox.arrayfire.com/tag/learning-arrayfire-from-scratch/\">Learning ArrayFire from scratch</a>\" today we will discuss how to set up an ArrayFire project on OSX using XCode, CMake, or Makefiles.</div>\r\n</div>\r\n</div>\r\n<!--more-->\r\n\r\nOnce you have <a class=\"el\" href=\"installing.htm\">installed</a> ArrayFire on your system, the next thing to do is set up your build system. On OSX, you may create ArrayFire project using almost any editor, compiler, or build system. The only requirement is that you can include the ArrayFire header directory, and link with the ArrayFire library you intend to use.\r\n<h2>The big picture</h2>\r\nBy default, the ArrayFire OSX installer will place several files in your computer\'s <span class=\"lang:default decode:true  crayon-inline \">/usr/local</span>  directory. The installer will populate this directory with files in the following sub-directories:\r\n<pre class=\"fragment\">include/arrayfire.h         - Primary ArrayFire include file\r\ninclude/af/*.h              - Additional include files\r\nlib/libaf*                  - CPU, CUDA, and OpenCL libraries (.a, .so)\r\nlib/libforge*               - Visualization library\r\nshare/ArrayFire/cmake/*     - CMake config (find) scripts\r\nshare/ArrayFire/examples/*  - All ArrayFire examples\r\n</pre>\r\nBecause ArrayFire follows standard installation practices, you can use basically any build system to create and compile projects that use ArrayFire. Among the many possible build systems on Linux we suggest using ArrayFire with either CMake or Makefiles with CMake being our preferred build system.\r\n<h2>XCode</h2>\r\nAlthough we recommend using CMake to build ArrayFire projects on OSX, you can use XCode if this is your preferred development platform. To set up a basic C/C++ project in XCode do the following:\r\n<ol type=\"1\">\r\n	<li>Start up XCode. Choose OSX -&gt; Application, Command Line Tool for the project:\r\n<div class=\"image\"><a href=\"http://sandbox.arrayfire.com/wp-content/uploads/2015/11/xcode-startup.png\"><img class=\"alignnone wp-image-8596\" src=\"http://sandbox.arrayfire.com/wp-content/uploads/2015/11/xcode-startup.png\" alt=\"xcode-startup\" width=\"650\" height=\"387\" /></a></div></li>\r\n	<li>Fill in the details for your project and choose either C or C++ for the project:\r\n<div class=\"image\"><a href=\"http://sandbox.arrayfire.com/wp-content/uploads/2015/11/project-options.png\"><img class=\"alignnone wp-image-8597\" src=\"http://sandbox.arrayfire.com/wp-content/uploads/2015/11/project-options.png\" alt=\"project-options\" width=\"650\" height=\"393\" /></a></div></li>\r\n	<li>Next we need to configure the build settings. In the left-hand pane, click on the project. In the center pane, click on \"Build Settings\" followed by the \"All\" button:\r\n<div class=\"image\"><a href=\"http://sandbox.arrayfire.com/wp-content/uploads/2015/11/build-settings1.png\"><img class=\"alignnone wp-image-8600\" src=\"http://sandbox.arrayfire.com/wp-content/uploads/2015/11/build-settings1.png\" alt=\"build-settings\" width=\"900\" height=\"602\" /></a></div></li>\r\n	<li>Now search for \"Header Search Paths\" and add <span class=\"lang:default decode:true  crayon-inline \">/usr/local/include</span>  to the list:\r\n<div class=\"image\"><a href=\"http://sandbox.arrayfire.com/wp-content/uploads/2015/11/header-search-paths.png\"><img class=\"alignnone wp-image-8601\" src=\"http://sandbox.arrayfire.com/wp-content/uploads/2015/11/header-search-paths.png\" alt=\"header-search-paths\" width=\"650\" height=\"279\" /></a></div></li>\r\n	<li>Then search for \"Library Search Paths\" and add <span class=\"lang:default decode:true  crayon-inline \">/usr/local/lib</span>  to the list:\r\n<div class=\"image\"><a href=\"http://sandbox.arrayfire.com/wp-content/uploads/2015/11/library-search-paths.png\"><img class=\"alignnone wp-image-8602\" src=\"http://sandbox.arrayfire.com/wp-content/uploads/2015/11/library-search-paths.png\" alt=\"library-search-paths\" width=\"650\" height=\"285\" /></a></div></li>\r\n	<li>Next, we need to make sure the executable is linked with an ArrayFire library: To do this, click the \"Build Phases\" tab and expand the \"Link with Binary Library\" menu:\r\n<div class=\"image\"><a href=\"http://sandbox.arrayfire.com/wp-content/uploads/2015/11/build-phases.png\"><img class=\"alignnone wp-image-8603\" src=\"http://sandbox.arrayfire.com/wp-content/uploads/2015/11/build-phases.png\" alt=\"build-phases\" width=\"900\" height=\"269\" /></a></div></li>\r\n	<li>In the search dialog that pops up, choose the \"Add Other\" button from the lower right. Specify the<span class=\"lang:default decode:true  crayon-inline \">/usr/local/lib</span>  folder:\r\n<div class=\"image\"><a href=\"http://sandbox.arrayfire.com/wp-content/uploads/2015/11/library-folder-path.png\"><img class=\"alignnone wp-image-8599\" src=\"http://sandbox.arrayfire.com/wp-content/uploads/2015/11/library-folder-path.png\" alt=\"library-folder-path\" width=\"650\" height=\"567\" /></a></div></li>\r\n	<li>Lastly, select the ArrayFire library with which you wish to link your program. Your options will be:</li>\r\n</ol>\r\n<div class=\"fragment\">\r\n<div class=\"line\">\r\n<pre class=\"lang:default decode:true \">libafcuda.*.dylib   - CUDA backend\r\nlibafopencl.*.dylib - OpenCL backend\r\nlibafcpu.*.dylib    - CPU backend\r\nlibaf.*.dylib       - Unified backend</pre>\r\nIn the picture below, we have elected to link with the OpenCL backend:\r\n\r\n<a href=\"http://sandbox.arrayfire.com/wp-content/uploads/2015/11/pick-arrayfire-library.png\"><img class=\"alignnone wp-image-8598\" src=\"http://sandbox.arrayfire.com/wp-content/uploads/2015/11/pick-arrayfire-library.png\" alt=\"pick-arrayfire-library\" width=\"650\" height=\"566\" /></a>\r\n\r\n</div>\r\n</div>\r\n9. Lastly, lets test ArrayFire\'s functionality. In the left hand pane open the main.cpp` file and insert the following code:\r\n<div class=\"image\"></div>\r\n<div class=\"fragment\">\r\n<div class=\"line\">\r\n<pre class=\"lang:default decode:true \"> // Include the ArrayFire header file\r\n#include &lt;arrayfire.h&gt;\r\n \r\nint main(int argc, const char * argv[]) {\r\n   // Gather some information about the ArrayFire device\r\n   af::info();\r\n   return 0;\r\n}</pre>\r\n&nbsp;\r\n\r\n</div>\r\n</div>\r\nFinally, click the build button and you should see some information about your graphics card in the lower-section of your screen:\r\n<div class=\"image\"><a href=\"http://sandbox.arrayfire.com/wp-content/uploads/2015/11/afinfo-result.png\"><img class=\"alignnone size-medium wp-image-8594\" src=\"http://sandbox.arrayfire.com/wp-content/uploads/2015/11/afinfo-result-300x85.png\" alt=\"afinfo-result\" width=\"300\" height=\"85\" /></a></div>\r\n<h2>CMake</h2>\r\nWe recommend that the CMake build system be used to create ArrayFire projects. If you are writing a new ArrayFire project in C/C++ from scratch, we suggest you grab a copy of our <a href=\"https://github.com/arrayfire/arrayfire-project-templates\">CMake Project Example</a>; however, it is useful to read the documentation below in case you need to add ArrayFire to an existing project.\r\n\r\nAs <a href=\"#big-picture\">discussed above</a>, ArrayFire ships with a series of CMake scripts to make finding and using our library easy. The scripts will automatically find all versions of the ArrayFire library and pick the most powerful of the installed backends (typically CUDA).\r\n\r\nFirst create a file called<span class=\"lang:default decode:true  crayon-inline \"> CMakeLists.txt</span>  in your project directory:\r\n<pre class=\"fragment\">cd your-project-directory\r\ntouch CMakeLists.txt\r\n</pre>\r\nand populate it with the following code:\r\n<pre class=\"fragment\">FIND_PACKAGE(ArrayFire)\r\nINCLUDE_DIRECTORIES(${ArrayFire_INCLUDE_DIRS})\r\n\r\n... [gather source files, etc.]\r\n\r\n# If you intend to use OpenCL, you need to find it\r\nFIND_PACKAGE(OpenCL)\r\nSET(EXTRA_LIBS ${CMAKE_THREAD_LIBS_INIT} ${OpenCL_LIBRARIES})\r\n\r\n# Or if you intend to use CUDA, you need it as well as NVVM:\r\nFIND_PACKAGE(CUDA)\r\nFIND_PACKAGE(NVVM) # this FIND script can be found in the ArrayFire CMake example repository\r\nSET(EXTRA_LIBS ${CMAKE_THREAD_LIBS_INIT} ${CUDA_LIBRARIES} ${NVVM_LIB})\r\n\r\nADD_EXECUTABLE(my_executable [list your source files here])\r\nTARGET_LINK_LIBRARIES(my_executable ${ArrayFire_LIBRARIES} ${EXTRA_LIBS})\r\n</pre>\r\nwhere <code>my_executable</code> is the name of the executable you wish to create. See the <a href=\"https://cmake.org/documentation/\">CMake documentation</a> for more information on how to use CMake. Clearly the above code snippet precludes the use of both CUDA and OpenCL, see the<a href=\"https://github.com/bkloppenborg/arrayfire-cmake-example\">ArrayFire CMake Example</a> for an example of how to build executables for both backends from the same CMake script.\r\n\r\nIn the above code listing, the <span class=\"lang:default decode:true  crayon-inline \">FIND_PACKAGE</span>  will find the ArrayFire include files, libraries, and define several variables including:\r\n<pre class=\"fragment\">ArrayFire_INCLUDE_DIRS    - Location of ArrayFire\'s include directory.\r\nArrayFire_LIBRARIES       - Location of ArrayFire\'s libraries.\r\n                            This will default to a GPU backend if one\r\n                            is found\r\nArrayFire_FOUND           - True if ArrayFire has been located\r\n</pre>\r\nIf you wish to use a specific backend, the find script also defines these variables:\r\n<pre class=\"fragment\">ArrayFire_CPU_FOUND         - True of the ArrayFire CPU library has been found.\r\nArrayFire_CPU_LIBRARIES     - Location of ArrayFire\'s CPU library, if found\r\nArrayFire_CUDA_FOUND        - True of the ArrayFire CUDA library has been found.\r\nArrayFire_CUDA_LIBRARIES    - Location of ArrayFire\'s CUDA library, if found\r\nArrayFire_OpenCL_FOUND      - True of the ArrayFire OpenCL library has been found.\r\nArrayFire_OpenCL_LIBRARIES  - Location of ArrayFire\'s OpenCL library, if found\r\nArrayFire_Unified_FOUND     - True of the ArrayFire Unified library has been found.\r\nArrayFire_Unified_LIBRARIES - Location of ArrayFire\'s Unified library, if found\r\n</pre>\r\nTherefore, if you wish to target a specific specific backend, simply replace <span class=\"lang:default decode:true  crayon-inline \">${ArrayFire_LIBRARIES}</span>  with<span class=\"lang:default decode:true  crayon-inline \">${ArrayFire_CPU}</span> , <span class=\"lang:default decode:true  crayon-inline \">${ArrayFire_OPENCL}</span> , <span class=\"lang:default decode:true  crayon-inline \">${ArrayFire_CUDA}</span> , or <code>${ArrayFire_Unified}</code> in the<span class=\"lang:default decode:true  crayon-inline \">TARGET_LINK_LIBRARIES</span>  command above. If you intend on building your software to link with all of these backends, please see the <a href=\"https://github.com/arrayfire/arrayfire-project-templates\">CMake Project Example</a> which makes use of some fairly fun CMake tricks to avoid re-compiling code whenever possible.\r\n\r\nNext we need to instruct CMake to create build instructions and then compile. We suggest using CMake\'s out-of-source build functionality to keep your build and source files cleanly separated. To do this:\r\n<pre class=\"fragment\">cd your-project-directory\r\nmkdir build\r\ncd build\r\ncmake ..\r\nmake\r\n</pre>\r\n<em>NOTE:</em> If you have installed ArrayFire to a non-standard location, CMake can still help you out. When you execute CMake specify the path to the <span class=\"lang:default decode:true  crayon-inline \">ArrayFireConfig*</span>  files that are found in the <span class=\"lang:default decode:true  crayon-inline \">share/ArrayFire/cmake</span>  subdirectory of the installation folder. For example, if ArrayFire were installed locally to <span class=\"lang:default decode:true  crayon-inline \">/opt/ArrayFire</span>  then you would modify the <span class=\"lang:default decode:true  crayon-inline \">cmake</span> command above to contain the following definition:\r\n<pre class=\"fragment\">cmake -DArrayFire_DIR=/opt/ArrayFire/share/ArrayFire/cmake ..\r\n</pre>\r\nYou can also specify this information in the ccmake command-line interface.\r\n<h2>MakeFiles</h2>\r\nBuilding ArrayFire projects with Makefiles is fairly similar to CMake except you must specify all paths and libraries manually. As with any make project, you need to specify the include path to the directory containing <code><a class=\"el\" href=\"arrayfire_8h.htm\">arrayfire.h</a></code> file. This should be <span class=\"lang:default decode:true  crayon-inline \">-I /usr/local/include</span>  if you followed our installation instructions. Similarly, you will need to specify the path to the ArrayFire library using the <span class=\"lang:default decode:true  crayon-inline \">-L</span>  option (e.g. <span class=\"lang:default decode:true  crayon-inline \">-L/usr/local/lib</span> ) followed by the specific ArrayFire library you wish to use using the <code>-l</code> option (for example <span class=\"lang:default decode:true  crayon-inline \">-lafcpu</span> , <span class=\"lang:default decode:true  crayon-inline \">-lafopencl</span> , <span class=\"lang:default decode:true  crayon-inline \">-lafcuda</span> , or <span class=\"lang:default decode:true  crayon-inline \">-laf</span>  for the CPU, OpenCL, CUDA, and unified backends respectively.\r\n\r\nHere is a minimial example MakeFile which uses ArrayFire\'s CPU backend:\r\n<pre class=\"fragment\">LIBS=-lafcpu\r\nLIB_PATHS=-L/usr/lib\r\nINCLUDES=-I/usr/include\r\nCC=g++ $(COMPILER_OPTIONS)\r\nCOMPILER_OPTIONS=-std=c++11 -g\r\n\r\nall: main.cpp Makefile\r\n    $(CC) main.cpp -o test $(INCLUDES) $(LIBS) $(LIB_PATHS)</pre>','Setting up an ArrayFire Project on OSX','','inherit','open','closed','','8592-revision-v1','','','2015-11-06 22:21:20','2015-11-06 22:21:20','',8592,'http://sandbox.arrayfire.com/8592-revision-v1/',0,'revision','',0),(8606,18528,'2015-11-06 22:22:06','2015-11-06 22:22:06','<div class=\"header\">\r\n<div class=\"headertitle\">\r\n<div class=\"title\">Continuing our blog series \"<a href=\"http://sandbox.arrayfire.com/tag/learning-arrayfire-from-scratch/\">Learning ArrayFire from scratch</a>\" today we will discuss how to set up an ArrayFire project on OSX using XCode, CMake, or Makefiles.</div>\r\n</div>\r\n</div>\r\n<!--more-->\r\n\r\nOnce you have <a class=\"el\" href=\"installing.htm\">installed</a> ArrayFire on your system, the next thing to do is set up your build system. On OSX, you may create ArrayFire project using almost any editor, compiler, or build system. The only requirement is that you can include the ArrayFire header directory, and link with the ArrayFire library you intend to use.\r\n<h3>The big picture</h3>\r\nBy default, the ArrayFire OSX installer will place several files in your computer\'s <span class=\"lang:default decode:true  crayon-inline \">/usr/local</span>  directory. The installer will populate this directory with files in the following sub-directories:\r\n<pre class=\"fragment\">include/arrayfire.h         - Primary ArrayFire include file\r\ninclude/af/*.h              - Additional include files\r\nlib/libaf*                  - CPU, CUDA, and OpenCL libraries (.a, .so)\r\nlib/libforge*               - Visualization library\r\nshare/ArrayFire/cmake/*     - CMake config (find) scripts\r\nshare/ArrayFire/examples/*  - All ArrayFire examples\r\n</pre>\r\nBecause ArrayFire follows standard installation practices, you can use basically any build system to create and compile projects that use ArrayFire. Among the many possible build systems on Linux we suggest using ArrayFire with either CMake or Makefiles with CMake being our preferred build system.\r\n<h3>XCode</h3>\r\nAlthough we recommend using CMake to build ArrayFire projects on OSX, you can use XCode if this is your preferred development platform. To set up a basic C/C++ project in XCode do the following:\r\n<ol type=\"1\">\r\n	<li>Start up XCode. Choose OSX -&gt; Application, Command Line Tool for the project:\r\n<div class=\"image\"><a href=\"http://sandbox.arrayfire.com/wp-content/uploads/2015/11/xcode-startup.png\"><img class=\"alignnone wp-image-8596\" src=\"http://sandbox.arrayfire.com/wp-content/uploads/2015/11/xcode-startup.png\" alt=\"xcode-startup\" width=\"650\" height=\"387\" /></a></div></li>\r\n	<li>Fill in the details for your project and choose either C or C++ for the project:\r\n<div class=\"image\"><a href=\"http://sandbox.arrayfire.com/wp-content/uploads/2015/11/project-options.png\"><img class=\"alignnone wp-image-8597\" src=\"http://sandbox.arrayfire.com/wp-content/uploads/2015/11/project-options.png\" alt=\"project-options\" width=\"650\" height=\"393\" /></a></div></li>\r\n	<li>Next we need to configure the build settings. In the left-hand pane, click on the project. In the center pane, click on \"Build Settings\" followed by the \"All\" button:\r\n<div class=\"image\"><a href=\"http://sandbox.arrayfire.com/wp-content/uploads/2015/11/build-settings1.png\"><img class=\"alignnone wp-image-8600\" src=\"http://sandbox.arrayfire.com/wp-content/uploads/2015/11/build-settings1.png\" alt=\"build-settings\" width=\"900\" height=\"602\" /></a></div></li>\r\n	<li>Now search for \"Header Search Paths\" and add <span class=\"lang:default decode:true  crayon-inline \">/usr/local/include</span>  to the list:\r\n<div class=\"image\"><a href=\"http://sandbox.arrayfire.com/wp-content/uploads/2015/11/header-search-paths.png\"><img class=\"alignnone wp-image-8601\" src=\"http://sandbox.arrayfire.com/wp-content/uploads/2015/11/header-search-paths.png\" alt=\"header-search-paths\" width=\"650\" height=\"279\" /></a></div></li>\r\n	<li>Then search for \"Library Search Paths\" and add <span class=\"lang:default decode:true  crayon-inline \">/usr/local/lib</span>  to the list:\r\n<div class=\"image\"><a href=\"http://sandbox.arrayfire.com/wp-content/uploads/2015/11/library-search-paths.png\"><img class=\"alignnone wp-image-8602\" src=\"http://sandbox.arrayfire.com/wp-content/uploads/2015/11/library-search-paths.png\" alt=\"library-search-paths\" width=\"650\" height=\"285\" /></a></div></li>\r\n	<li>Next, we need to make sure the executable is linked with an ArrayFire library: To do this, click the \"Build Phases\" tab and expand the \"Link with Binary Library\" menu:\r\n<div class=\"image\"><a href=\"http://sandbox.arrayfire.com/wp-content/uploads/2015/11/build-phases.png\"><img class=\"alignnone wp-image-8603\" src=\"http://sandbox.arrayfire.com/wp-content/uploads/2015/11/build-phases.png\" alt=\"build-phases\" width=\"900\" height=\"269\" /></a></div></li>\r\n	<li>In the search dialog that pops up, choose the \"Add Other\" button from the lower right. Specify the<span class=\"lang:default decode:true  crayon-inline \">/usr/local/lib</span>  folder:\r\n<div class=\"image\"><a href=\"http://sandbox.arrayfire.com/wp-content/uploads/2015/11/library-folder-path.png\"><img class=\"alignnone wp-image-8599\" src=\"http://sandbox.arrayfire.com/wp-content/uploads/2015/11/library-folder-path.png\" alt=\"library-folder-path\" width=\"650\" height=\"567\" /></a></div></li>\r\n	<li>Next, select the ArrayFire library with which you wish to link your program. Your options will be:</li>\r\n</ol>\r\n<div class=\"fragment\">\r\n<div class=\"line\">\r\n<pre class=\"lang:default decode:true \">libafcuda.*.dylib   - CUDA backend\r\nlibafopencl.*.dylib - OpenCL backend\r\nlibafcpu.*.dylib    - CPU backend\r\nlibaf.*.dylib       - Unified backend</pre>\r\nIn the picture below, we have elected to link with the OpenCL backend:\r\n\r\n<a href=\"http://sandbox.arrayfire.com/wp-content/uploads/2015/11/pick-arrayfire-library.png\"><img class=\"alignnone wp-image-8598\" src=\"http://sandbox.arrayfire.com/wp-content/uploads/2015/11/pick-arrayfire-library.png\" alt=\"pick-arrayfire-library\" width=\"650\" height=\"566\" /></a>\r\n\r\n</div>\r\n</div>\r\n9. Lastly, lets test ArrayFire\'s functionality. In the left hand pane open the main.cpp` file and insert the following code:\r\n<div class=\"image\"></div>\r\n<div class=\"fragment\">\r\n<div class=\"line\">\r\n<pre class=\"lang:default decode:true \"> // Include the ArrayFire header file\r\n#include &lt;arrayfire.h&gt;\r\n \r\nint main(int argc, const char * argv[]) {\r\n   // Gather some information about the ArrayFire device\r\n   af::info();\r\n   return 0;\r\n}</pre>\r\n&nbsp;\r\n\r\n</div>\r\n</div>\r\nFinally, click the build button and you should see some information about your graphics card in the lower-section of your screen:\r\n<div class=\"image\"><a href=\"http://sandbox.arrayfire.com/wp-content/uploads/2015/11/afinfo-result.png\"><img class=\"alignnone size-medium wp-image-8594\" src=\"http://sandbox.arrayfire.com/wp-content/uploads/2015/11/afinfo-result-300x85.png\" alt=\"afinfo-result\" width=\"300\" height=\"85\" /></a></div>\r\n<h3>CMake</h3>\r\nWe recommend that the CMake build system be used to create ArrayFire projects. If you are writing a new ArrayFire project in C/C++ from scratch, we suggest you grab a copy of our <a href=\"https://github.com/arrayfire/arrayfire-project-templates\">CMake Project Example</a>; however, it is useful to read the documentation below in case you need to add ArrayFire to an existing project.\r\n\r\nAs <a href=\"#big-picture\">discussed above</a>, ArrayFire ships with a series of CMake scripts to make finding and using our library easy. The scripts will automatically find all versions of the ArrayFire library and pick the most powerful of the installed backends (typically CUDA).\r\n\r\nFirst create a file called<span class=\"lang:default decode:true  crayon-inline \"> CMakeLists.txt</span>  in your project directory:\r\n<pre class=\"fragment\">cd your-project-directory\r\ntouch CMakeLists.txt\r\n</pre>\r\nand populate it with the following code:\r\n<pre class=\"fragment\">FIND_PACKAGE(ArrayFire)\r\nINCLUDE_DIRECTORIES(${ArrayFire_INCLUDE_DIRS})\r\n\r\n... [gather source files, etc.]\r\n\r\n# If you intend to use OpenCL, you need to find it\r\nFIND_PACKAGE(OpenCL)\r\nSET(EXTRA_LIBS ${CMAKE_THREAD_LIBS_INIT} ${OpenCL_LIBRARIES})\r\n\r\n# Or if you intend to use CUDA, you need it as well as NVVM:\r\nFIND_PACKAGE(CUDA)\r\nFIND_PACKAGE(NVVM) # this FIND script can be found in the ArrayFire CMake example repository\r\nSET(EXTRA_LIBS ${CMAKE_THREAD_LIBS_INIT} ${CUDA_LIBRARIES} ${NVVM_LIB})\r\n\r\nADD_EXECUTABLE(my_executable [list your source files here])\r\nTARGET_LINK_LIBRARIES(my_executable ${ArrayFire_LIBRARIES} ${EXTRA_LIBS})\r\n</pre>\r\nwhere <span class=\"lang:default decode:true  crayon-inline \">my_executable</span>  is the name of the executable you wish to create. See the <a href=\"https://cmake.org/documentation/\">CMake documentation</a> for more information on how to use CMake. Clearly the above code snippet precludes the use of both CUDA and OpenCL, see the<a href=\"https://github.com/bkloppenborg/arrayfire-cmake-example\">ArrayFire CMake Example</a> for an example of how to build executables for both backends from the same CMake script.\r\n\r\nIn the above code listing, the <span class=\"lang:default decode:true  crayon-inline \">FIND_PACKAGE</span>  will find the ArrayFire include files, libraries, and define several variables including:\r\n<pre class=\"fragment\">ArrayFire_INCLUDE_DIRS    - Location of ArrayFire\'s include directory.\r\nArrayFire_LIBRARIES       - Location of ArrayFire\'s libraries.\r\n                            This will default to a GPU backend if one\r\n                            is found\r\nArrayFire_FOUND           - True if ArrayFire has been located\r\n</pre>\r\nIf you wish to use a specific backend, the find script also defines these variables:\r\n<pre class=\"fragment\">ArrayFire_CPU_FOUND         - True of the ArrayFire CPU library has been found.\r\nArrayFire_CPU_LIBRARIES     - Location of ArrayFire\'s CPU library, if found\r\nArrayFire_CUDA_FOUND        - True of the ArrayFire CUDA library has been found.\r\nArrayFire_CUDA_LIBRARIES    - Location of ArrayFire\'s CUDA library, if found\r\nArrayFire_OpenCL_FOUND      - True of the ArrayFire OpenCL library has been found.\r\nArrayFire_OpenCL_LIBRARIES  - Location of ArrayFire\'s OpenCL library, if found\r\nArrayFire_Unified_FOUND     - True of the ArrayFire Unified library has been found.\r\nArrayFire_Unified_LIBRARIES - Location of ArrayFire\'s Unified library, if found\r\n</pre>\r\nTherefore, if you wish to target a specific specific backend, simply replace <span class=\"lang:default decode:true  crayon-inline \">${ArrayFire_LIBRARIES}</span>  with<span class=\"lang:default decode:true  crayon-inline \">${ArrayFire_CPU}</span> , <span class=\"lang:default decode:true  crayon-inline \">${ArrayFire_OPENCL}</span> , <span class=\"lang:default decode:true  crayon-inline \">${ArrayFire_CUDA}</span> , or <code>${ArrayFire_Unified}</code> in the<span class=\"lang:default decode:true  crayon-inline \">TARGET_LINK_LIBRARIES</span>  command above. If you intend on building your software to link with all of these backends, please see the <a href=\"https://github.com/arrayfire/arrayfire-project-templates\">CMake Project Example</a> which makes use of some fairly fun CMake tricks to avoid re-compiling code whenever possible.\r\n\r\nNext we need to instruct CMake to create build instructions and then compile. We suggest using CMake\'s out-of-source build functionality to keep your build and source files cleanly separated. To do this:\r\n<pre class=\"fragment\">cd your-project-directory\r\nmkdir build\r\ncd build\r\ncmake ..\r\nmake\r\n</pre>\r\n<em>NOTE:</em> If you have installed ArrayFire to a non-standard location, CMake can still help you out. When you execute CMake specify the path to the <span class=\"lang:default decode:true  crayon-inline \">ArrayFireConfig*</span>  files that are found in the <span class=\"lang:default decode:true  crayon-inline \">share/ArrayFire/cmake</span>  subdirectory of the installation folder. For example, if ArrayFire were installed locally to <span class=\"lang:default decode:true  crayon-inline \">/opt/ArrayFire</span>  then you would modify the <span class=\"lang:default decode:true  crayon-inline \">cmake</span> command above to contain the following definition:\r\n<pre class=\"fragment\">cmake -DArrayFire_DIR=/opt/ArrayFire/share/ArrayFire/cmake ..\r\n</pre>\r\nYou can also specify this information in the ccmake command-line interface.\r\n<h3>MakeFiles</h3>\r\nBuilding ArrayFire projects with Makefiles is fairly similar to CMake except you must specify all paths and libraries manually. As with any make project, you need to specify the include path to the directory containing <code><a class=\"el\" href=\"arrayfire_8h.htm\">arrayfire.h</a></code> file. This should be <span class=\"lang:default decode:true  crayon-inline \">-I /usr/local/include</span>  if you followed our installation instructions. Similarly, you will need to specify the path to the ArrayFire library using the <span class=\"lang:default decode:true  crayon-inline \">-L</span>  option (e.g. <span class=\"lang:default decode:true  crayon-inline \">-L/usr/local/lib</span> ) followed by the specific ArrayFire library you wish to use using the <code>-l</code> option (for example <span class=\"lang:default decode:true  crayon-inline \">-lafcpu</span> , <span class=\"lang:default decode:true  crayon-inline \">-lafopencl</span> , <span class=\"lang:default decode:true  crayon-inline \">-lafcuda</span> , or <span class=\"lang:default decode:true  crayon-inline \">-laf</span>  for the CPU, OpenCL, CUDA, and unified backends respectively.\r\n\r\nHere is a minimial example MakeFile which uses ArrayFire\'s CPU backend:\r\n<pre class=\"fragment\">LIBS=-lafcpu\r\nLIB_PATHS=-L/usr/lib\r\nINCLUDES=-I/usr/include\r\nCC=g++ $(COMPILER_OPTIONS)\r\nCOMPILER_OPTIONS=-std=c++11 -g\r\n\r\nall: main.cpp Makefile\r\n    $(CC) main.cpp -o test $(INCLUDES) $(LIBS) $(LIB_PATHS)</pre>','Setting up an ArrayFire Project on OSX','','inherit','open','closed','','8592-revision-v1','','','2015-11-06 22:22:06','2015-11-06 22:22:06','',8592,'http://sandbox.arrayfire.com/8592-revision-v1/',0,'revision','',0),(8607,18528,'2015-11-06 22:23:00','2015-11-06 22:23:00','<div class=\"header\">\r\n<div class=\"headertitle\">\r\n<div class=\"title\">Continuing our blog series \"<a href=\"http://sandbox.arrayfire.com/tag/learning-arrayfire-from-scratch/\">Learning ArrayFire from scratch</a>\" today we will discuss how to set up an ArrayFire project on OSX using XCode, CMake, or Makefiles.</div>\r\n</div>\r\n</div>\r\n<!--more-->\r\n\r\nOnce you have <a class=\"el\" href=\"installing.htm\">installed</a> ArrayFire on your system, the next thing to do is set up your build system. On OSX, you may create ArrayFire project using almost any editor, compiler, or build system. The only requirement is that you can include the ArrayFire header directory, and link with the ArrayFire library you intend to use.\r\n<h3>The big picture</h3>\r\nBy default, the ArrayFire OSX installer will place several files in your computer\'s <span class=\"lang:default decode:true  crayon-inline \">/usr/local</span>  directory. The installer will populate this directory with files in the following sub-directories:\r\n<pre class=\"fragment\">include/arrayfire.h         - Primary ArrayFire include file\r\ninclude/af/*.h              - Additional include files\r\nlib/libaf*                  - CPU, CUDA, and OpenCL libraries (.a, .so)\r\nlib/libforge*               - Visualization library\r\nshare/ArrayFire/cmake/*     - CMake config (find) scripts\r\nshare/ArrayFire/examples/*  - All ArrayFire examples\r\n</pre>\r\nBecause ArrayFire follows standard installation practices, you can use basically any build system to create and compile projects that use ArrayFire. Among the many possible build systems on Linux we suggest using ArrayFire with either CMake or Makefiles with CMake being our preferred build system.\r\n<h3>XCode</h3>\r\nAlthough we recommend using CMake to build ArrayFire projects on OSX, you can use XCode if this is your preferred development platform. To set up a basic C/C++ project in XCode do the following:\r\n<ol type=\"1\">\r\n	<li>Start up XCode. Choose OSX -&gt; Application, Command Line Tool for the project:\r\n<div class=\"image\"><a href=\"http://sandbox.arrayfire.com/wp-content/uploads/2015/11/xcode-startup.png\"><img class=\"alignnone wp-image-8596\" src=\"http://sandbox.arrayfire.com/wp-content/uploads/2015/11/xcode-startup.png\" alt=\"xcode-startup\" width=\"650\" height=\"387\" /></a></div></li>\r\n	<li>Fill in the details for your project and choose either C or C++ for the project:\r\n<div class=\"image\"><a href=\"http://sandbox.arrayfire.com/wp-content/uploads/2015/11/project-options.png\"><img class=\"alignnone wp-image-8597\" src=\"http://sandbox.arrayfire.com/wp-content/uploads/2015/11/project-options.png\" alt=\"project-options\" width=\"650\" height=\"393\" /></a></div></li>\r\n	<li>Next we need to configure the build settings. In the left-hand pane, click on the project. In the center pane, click on \"Build Settings\" followed by the \"All\" button:\r\n<div class=\"image\"><a href=\"http://sandbox.arrayfire.com/wp-content/uploads/2015/11/build-settings1.png\"><img class=\"alignnone wp-image-8600\" src=\"http://sandbox.arrayfire.com/wp-content/uploads/2015/11/build-settings1.png\" alt=\"build-settings\" width=\"900\" height=\"602\" /></a></div></li>\r\n	<li>Now search for \"Header Search Paths\" and add <span class=\"lang:default decode:true  crayon-inline \">/usr/local/include</span>  to the list:\r\n<div class=\"image\"><a href=\"http://sandbox.arrayfire.com/wp-content/uploads/2015/11/header-search-paths.png\"><img class=\"alignnone wp-image-8601\" src=\"http://sandbox.arrayfire.com/wp-content/uploads/2015/11/header-search-paths.png\" alt=\"header-search-paths\" width=\"650\" height=\"279\" /></a></div></li>\r\n	<li>Then search for \"Library Search Paths\" and add <span class=\"lang:default decode:true  crayon-inline \">/usr/local/lib</span>  to the list:\r\n<div class=\"image\"><a href=\"http://sandbox.arrayfire.com/wp-content/uploads/2015/11/library-search-paths.png\"><img class=\"alignnone wp-image-8602\" src=\"http://sandbox.arrayfire.com/wp-content/uploads/2015/11/library-search-paths.png\" alt=\"library-search-paths\" width=\"650\" height=\"285\" /></a></div></li>\r\n	<li>Next, we need to make sure the executable is linked with an ArrayFire library: To do this, click the \"Build Phases\" tab and expand the \"Link with Binary Library\" menu:\r\n<div class=\"image\"><a href=\"http://sandbox.arrayfire.com/wp-content/uploads/2015/11/build-phases.png\"><img class=\"alignnone wp-image-8603\" src=\"http://sandbox.arrayfire.com/wp-content/uploads/2015/11/build-phases.png\" alt=\"build-phases\" width=\"900\" height=\"269\" /></a></div></li>\r\n	<li>In the search dialog that pops up, choose the \"Add Other\" button from the lower right. Specify the<span class=\"lang:default decode:true  crayon-inline \">/usr/local/lib</span>  folder:\r\n<div class=\"image\"><a href=\"http://sandbox.arrayfire.com/wp-content/uploads/2015/11/library-folder-path.png\"><img class=\"alignnone wp-image-8599\" src=\"http://sandbox.arrayfire.com/wp-content/uploads/2015/11/library-folder-path.png\" alt=\"library-folder-path\" width=\"650\" height=\"567\" /></a></div></li>\r\n	<li>Next, select the ArrayFire library with which you wish to link your program. Your options will be:</li>\r\n</ol>\r\n<div class=\"fragment\">\r\n<div class=\"line\">\r\n<pre class=\"lang:default decode:true \">libafcuda.*.dylib   - CUDA backend\r\nlibafopencl.*.dylib - OpenCL backend\r\nlibafcpu.*.dylib    - CPU backend\r\nlibaf.*.dylib       - Unified backend</pre>\r\nIn the picture below, we have elected to link with the OpenCL backend:\r\n\r\n<a href=\"http://sandbox.arrayfire.com/wp-content/uploads/2015/11/pick-arrayfire-library.png\"><img class=\"alignnone wp-image-8598\" src=\"http://sandbox.arrayfire.com/wp-content/uploads/2015/11/pick-arrayfire-library.png\" alt=\"pick-arrayfire-library\" width=\"650\" height=\"566\" /></a>\r\n\r\n</div>\r\n</div>\r\n9. Lastly, lets test ArrayFire\'s functionality. In the left hand pane open the main.cpp` file and insert the following code:\r\n<div class=\"image\"></div>\r\n<div class=\"fragment\">\r\n<div class=\"line\">\r\n<pre class=\"lang:default decode:true \"> // Include the ArrayFire header file\r\n#include &lt;arrayfire.h&gt;\r\n \r\nint main(int argc, const char * argv[]) {\r\n   // Gather some information about the ArrayFire device\r\n   af::info();\r\n   return 0;\r\n}</pre>\r\n&nbsp;\r\n\r\n</div>\r\n</div>\r\nFinally, click the build button and you should see some information about your graphics card in the lower-section of your screen:\r\n<div class=\"image\"><a href=\"http://sandbox.arrayfire.com/wp-content/uploads/2015/11/afinfo-result.png\"><img class=\"alignnone wp-image-8594 size-full\" src=\"http://sandbox.arrayfire.com/wp-content/uploads/2015/11/afinfo-result.png\" alt=\"afinfo-result\" width=\"477\" height=\"135\" /></a></div>\r\n<h3>CMake</h3>\r\nWe recommend that the CMake build system be used to create ArrayFire projects. If you are writing a new ArrayFire project in C/C++ from scratch, we suggest you grab a copy of our <a href=\"https://github.com/arrayfire/arrayfire-project-templates\">CMake Project Example</a>; however, it is useful to read the documentation below in case you need to add ArrayFire to an existing project.\r\n\r\nAs <a href=\"#big-picture\">discussed above</a>, ArrayFire ships with a series of CMake scripts to make finding and using our library easy. The scripts will automatically find all versions of the ArrayFire library and pick the most powerful of the installed backends (typically CUDA).\r\n\r\nFirst create a file called<span class=\"lang:default decode:true  crayon-inline \"> CMakeLists.txt</span>  in your project directory:\r\n<pre class=\"fragment\">cd your-project-directory\r\ntouch CMakeLists.txt\r\n</pre>\r\nand populate it with the following code:\r\n<pre class=\"fragment\">FIND_PACKAGE(ArrayFire)\r\nINCLUDE_DIRECTORIES(${ArrayFire_INCLUDE_DIRS})\r\n\r\n... [gather source files, etc.]\r\n\r\n# If you intend to use OpenCL, you need to find it\r\nFIND_PACKAGE(OpenCL)\r\nSET(EXTRA_LIBS ${CMAKE_THREAD_LIBS_INIT} ${OpenCL_LIBRARIES})\r\n\r\n# Or if you intend to use CUDA, you need it as well as NVVM:\r\nFIND_PACKAGE(CUDA)\r\nFIND_PACKAGE(NVVM) # this FIND script can be found in the ArrayFire CMake example repository\r\nSET(EXTRA_LIBS ${CMAKE_THREAD_LIBS_INIT} ${CUDA_LIBRARIES} ${NVVM_LIB})\r\n\r\nADD_EXECUTABLE(my_executable [list your source files here])\r\nTARGET_LINK_LIBRARIES(my_executable ${ArrayFire_LIBRARIES} ${EXTRA_LIBS})\r\n</pre>\r\nwhere <span class=\"lang:default decode:true  crayon-inline \">my_executable</span>  is the name of the executable you wish to create. See the <a href=\"https://cmake.org/documentation/\">CMake documentation</a> for more information on how to use CMake. Clearly the above code snippet precludes the use of both CUDA and OpenCL, see the<a href=\"https://github.com/bkloppenborg/arrayfire-cmake-example\">ArrayFire CMake Example</a> for an example of how to build executables for both backends from the same CMake script.\r\n\r\nIn the above code listing, the <span class=\"lang:default decode:true  crayon-inline \">FIND_PACKAGE</span>  will find the ArrayFire include files, libraries, and define several variables including:\r\n<pre class=\"fragment\">ArrayFire_INCLUDE_DIRS    - Location of ArrayFire\'s include directory.\r\nArrayFire_LIBRARIES       - Location of ArrayFire\'s libraries.\r\n                            This will default to a GPU backend if one\r\n                            is found\r\nArrayFire_FOUND           - True if ArrayFire has been located\r\n</pre>\r\nIf you wish to use a specific backend, the find script also defines these variables:\r\n<pre class=\"fragment\">ArrayFire_CPU_FOUND         - True of the ArrayFire CPU library has been found.\r\nArrayFire_CPU_LIBRARIES     - Location of ArrayFire\'s CPU library, if found\r\nArrayFire_CUDA_FOUND        - True of the ArrayFire CUDA library has been found.\r\nArrayFire_CUDA_LIBRARIES    - Location of ArrayFire\'s CUDA library, if found\r\nArrayFire_OpenCL_FOUND      - True of the ArrayFire OpenCL library has been found.\r\nArrayFire_OpenCL_LIBRARIES  - Location of ArrayFire\'s OpenCL library, if found\r\nArrayFire_Unified_FOUND     - True of the ArrayFire Unified library has been found.\r\nArrayFire_Unified_LIBRARIES - Location of ArrayFire\'s Unified library, if found\r\n</pre>\r\nTherefore, if you wish to target a specific specific backend, simply replace <span class=\"lang:default decode:true  crayon-inline \">${ArrayFire_LIBRARIES}</span>  with<span class=\"lang:default decode:true  crayon-inline \">${ArrayFire_CPU}</span> , <span class=\"lang:default decode:true  crayon-inline \">${ArrayFire_OPENCL}</span> , <span class=\"lang:default decode:true  crayon-inline \">${ArrayFire_CUDA}</span> , or <code>${ArrayFire_Unified}</code> in the<span class=\"lang:default decode:true  crayon-inline \">TARGET_LINK_LIBRARIES</span>  command above. If you intend on building your software to link with all of these backends, please see the <a href=\"https://github.com/arrayfire/arrayfire-project-templates\">CMake Project Example</a> which makes use of some fairly fun CMake tricks to avoid re-compiling code whenever possible.\r\n\r\nNext we need to instruct CMake to create build instructions and then compile. We suggest using CMake\'s out-of-source build functionality to keep your build and source files cleanly separated. To do this:\r\n<pre class=\"fragment\">cd your-project-directory\r\nmkdir build\r\ncd build\r\ncmake ..\r\nmake\r\n</pre>\r\n<em>NOTE:</em> If you have installed ArrayFire to a non-standard location, CMake can still help you out. When you execute CMake specify the path to the <span class=\"lang:default decode:true  crayon-inline \">ArrayFireConfig*</span>  files that are found in the <span class=\"lang:default decode:true  crayon-inline \">share/ArrayFire/cmake</span>  subdirectory of the installation folder. For example, if ArrayFire were installed locally to <span class=\"lang:default decode:true  crayon-inline \">/opt/ArrayFire</span>  then you would modify the <span class=\"lang:default decode:true  crayon-inline \">cmake</span> command above to contain the following definition:\r\n<pre class=\"fragment\">cmake -DArrayFire_DIR=/opt/ArrayFire/share/ArrayFire/cmake ..\r\n</pre>\r\nYou can also specify this information in the ccmake command-line interface.\r\n<h3>MakeFiles</h3>\r\nBuilding ArrayFire projects with Makefiles is fairly similar to CMake except you must specify all paths and libraries manually. As with any make project, you need to specify the include path to the directory containing <code><a class=\"el\" href=\"arrayfire_8h.htm\">arrayfire.h</a></code> file. This should be <span class=\"lang:default decode:true  crayon-inline \">-I /usr/local/include</span>  if you followed our installation instructions. Similarly, you will need to specify the path to the ArrayFire library using the <span class=\"lang:default decode:true  crayon-inline \">-L</span>  option (e.g. <span class=\"lang:default decode:true  crayon-inline \">-L/usr/local/lib</span> ) followed by the specific ArrayFire library you wish to use using the <code>-l</code> option (for example <span class=\"lang:default decode:true  crayon-inline \">-lafcpu</span> , <span class=\"lang:default decode:true  crayon-inline \">-lafopencl</span> , <span class=\"lang:default decode:true  crayon-inline \">-lafcuda</span> , or <span class=\"lang:default decode:true  crayon-inline \">-laf</span>  for the CPU, OpenCL, CUDA, and unified backends respectively.\r\n\r\nHere is a minimial example MakeFile which uses ArrayFire\'s CPU backend:\r\n<pre class=\"fragment\">LIBS=-lafcpu\r\nLIB_PATHS=-L/usr/lib\r\nINCLUDES=-I/usr/include\r\nCC=g++ $(COMPILER_OPTIONS)\r\nCOMPILER_OPTIONS=-std=c++11 -g\r\n\r\nall: main.cpp Makefile\r\n    $(CC) main.cpp -o test $(INCLUDES) $(LIBS) $(LIB_PATHS)</pre>','Setting up an ArrayFire Project on OSX','','inherit','open','closed','','8592-revision-v1','','','2015-11-06 22:23:00','2015-11-06 22:23:00','',8592,'http://sandbox.arrayfire.com/8592-revision-v1/',0,'revision','',0),(8608,18528,'2015-11-06 22:25:27','2015-11-06 22:25:27','<div class=\"header\">\r\n<div class=\"headertitle\">\r\n<div class=\"title\">Continuing our blog series \"<a href=\"http://sandbox.arrayfire.com/tag/learning-arrayfire-from-scratch/\">Learning ArrayFire from scratch</a>\" today we will discuss how to set up an ArrayFire project on OSX using XCode, CMake, or Makefiles.</div>\r\n</div>\r\n</div>\r\n<!--more-->\r\n\r\nOnce you have <a class=\"el\" href=\"installing.htm\">installed</a> ArrayFire on your system, the next thing to do is set up your build system. On OSX, you may create ArrayFire project using almost any editor, compiler, or build system. The only requirement is that you can include the ArrayFire header directory, and link with the ArrayFire library you intend to use.\r\n<h3>The big picture</h3>\r\nBy default, the ArrayFire OSX installer will place several files in your computer\'s <span class=\"lang:default decode:true  crayon-inline \">/usr/local</span>  directory. The installer will populate this directory with files in the following sub-directories:\r\n<pre class=\"lang:default highlight:0 decode:true fragment\">include/arrayfire.h         - Primary ArrayFire include file\r\ninclude/af/*.h              - Additional include files\r\nlib/libaf*                  - CPU, CUDA, and OpenCL libraries (.a, .so)\r\nlib/libforge*               - Visualization library\r\nshare/ArrayFire/cmake/*     - CMake config (find) scripts\r\nshare/ArrayFire/examples/*  - All ArrayFire examples\r\n</pre>\r\nBecause ArrayFire follows standard installation practices, you can use basically any build system to create and compile projects that use ArrayFire. Among the many possible build systems on Linux we suggest using ArrayFire with either CMake or Makefiles with CMake being our preferred build system.\r\n<h3>XCode</h3>\r\nAlthough we recommend using CMake to build ArrayFire projects on OSX, you can use XCode if this is your preferred development platform. To set up a basic C/C++ project in XCode do the following:\r\n<ol type=\"1\">\r\n	<li>Start up XCode. Choose OSX -&gt; Application, Command Line Tool for the project:\r\n<div class=\"image\"><a href=\"http://sandbox.arrayfire.com/wp-content/uploads/2015/11/xcode-startup.png\"><img class=\"alignnone wp-image-8596\" src=\"http://sandbox.arrayfire.com/wp-content/uploads/2015/11/xcode-startup.png\" alt=\"xcode-startup\" width=\"650\" height=\"387\" /></a></div></li>\r\n	<li>Fill in the details for your project and choose either C or C++ for the project:\r\n<div class=\"image\"><a href=\"http://sandbox.arrayfire.com/wp-content/uploads/2015/11/project-options.png\"><img class=\"alignnone wp-image-8597\" src=\"http://sandbox.arrayfire.com/wp-content/uploads/2015/11/project-options.png\" alt=\"project-options\" width=\"650\" height=\"393\" /></a></div></li>\r\n	<li>Next we need to configure the build settings. In the left-hand pane, click on the project. In the center pane, click on \"Build Settings\" followed by the \"All\" button:\r\n<div class=\"image\"><a href=\"http://sandbox.arrayfire.com/wp-content/uploads/2015/11/build-settings1.png\"><img class=\"alignnone wp-image-8600\" src=\"http://sandbox.arrayfire.com/wp-content/uploads/2015/11/build-settings1.png\" alt=\"build-settings\" width=\"900\" height=\"602\" /></a></div></li>\r\n	<li>Now search for \"Header Search Paths\" and add <span class=\"lang:default decode:true  crayon-inline \">/usr/local/include</span>  to the list:\r\n<div class=\"image\"><a href=\"http://sandbox.arrayfire.com/wp-content/uploads/2015/11/header-search-paths.png\"><img class=\"alignnone wp-image-8601\" src=\"http://sandbox.arrayfire.com/wp-content/uploads/2015/11/header-search-paths.png\" alt=\"header-search-paths\" width=\"650\" height=\"279\" /></a></div></li>\r\n	<li>Then search for \"Library Search Paths\" and add <span class=\"lang:default decode:true  crayon-inline \">/usr/local/lib</span>  to the list:\r\n<div class=\"image\"><a href=\"http://sandbox.arrayfire.com/wp-content/uploads/2015/11/library-search-paths.png\"><img class=\"alignnone wp-image-8602\" src=\"http://sandbox.arrayfire.com/wp-content/uploads/2015/11/library-search-paths.png\" alt=\"library-search-paths\" width=\"650\" height=\"285\" /></a></div></li>\r\n	<li>Next, we need to make sure the executable is linked with an ArrayFire library: To do this, click the \"Build Phases\" tab and expand the \"Link with Binary Library\" menu:\r\n<div class=\"image\"><a href=\"http://sandbox.arrayfire.com/wp-content/uploads/2015/11/build-phases.png\"><img class=\"alignnone wp-image-8603\" src=\"http://sandbox.arrayfire.com/wp-content/uploads/2015/11/build-phases.png\" alt=\"build-phases\" width=\"900\" height=\"269\" /></a></div></li>\r\n	<li>In the search dialog that pops up, choose the \"Add Other\" button from the lower right. Specify the<span class=\"lang:default decode:true  crayon-inline \">/usr/local/lib</span>  folder:\r\n<div class=\"image\"><a href=\"http://sandbox.arrayfire.com/wp-content/uploads/2015/11/library-folder-path.png\"><img class=\"alignnone wp-image-8599\" src=\"http://sandbox.arrayfire.com/wp-content/uploads/2015/11/library-folder-path.png\" alt=\"library-folder-path\" width=\"650\" height=\"567\" /></a></div></li>\r\n	<li>Next, select the ArrayFire library with which you wish to link your program. Your options will be:</li>\r\n</ol>\r\n<div class=\"fragment\">\r\n<div class=\"line\">\r\n<pre class=\"lang:default highlight:0 decode:true\">libafcuda.*.dylib   - CUDA backend\r\nlibafopencl.*.dylib - OpenCL backend\r\nlibafcpu.*.dylib    - CPU backend\r\nlibaf.*.dylib       - Unified backend</pre>\r\nIn the picture below, we have elected to link with the OpenCL backend:\r\n\r\n<a href=\"http://sandbox.arrayfire.com/wp-content/uploads/2015/11/pick-arrayfire-library.png\"><img class=\"alignnone wp-image-8598\" src=\"http://sandbox.arrayfire.com/wp-content/uploads/2015/11/pick-arrayfire-library.png\" alt=\"pick-arrayfire-library\" width=\"650\" height=\"566\" /></a>\r\n\r\n</div>\r\n</div>\r\n9. Lastly, lets test ArrayFire\'s functionality. In the left hand pane open the main.cpp` file and insert the following code:\r\n<div class=\"image\"></div>\r\n<div class=\"fragment\">\r\n<div class=\"line\">\r\n<pre class=\"lang:default decode:true\"> // Include the ArrayFire header file\r\n#include &lt;arrayfire.h&gt;\r\n \r\nint main(int argc, const char * argv[]) {\r\n   // Gather some information about the ArrayFire device\r\n   af::info();\r\n   return 0;\r\n}</pre>\r\n&nbsp;\r\n\r\n</div>\r\n</div>\r\nFinally, click the build button and you should see some information about your graphics card in the lower-section of your screen:\r\n<div class=\"image\"><a href=\"http://sandbox.arrayfire.com/wp-content/uploads/2015/11/afinfo-result.png\"><img class=\"alignnone wp-image-8594 size-full\" src=\"http://sandbox.arrayfire.com/wp-content/uploads/2015/11/afinfo-result.png\" alt=\"afinfo-result\" width=\"477\" height=\"135\" /></a></div>\r\n<h3>CMake</h3>\r\nWe recommend that the CMake build system be used to create ArrayFire projects. If you are writing a new ArrayFire project in C/C++ from scratch, we suggest you grab a copy of our <a href=\"https://github.com/arrayfire/arrayfire-project-templates\">CMake Project Example</a>; however, it is useful to read the documentation below in case you need to add ArrayFire to an existing project.\r\n\r\nAs <a href=\"#big-picture\">discussed above</a>, ArrayFire ships with a series of CMake scripts to make finding and using our library easy. The scripts will automatically find all versions of the ArrayFire library and pick the most powerful of the installed backends (typically CUDA).\r\n\r\nFirst create a file called<span class=\"lang:default decode:true  crayon-inline \"> CMakeLists.txt</span>  in your project directory:\r\n<pre class=\"lang:default decode:true fragment\">cd your-project-directory\r\ntouch CMakeLists.txt\r\n</pre>\r\nand populate it with the following code:\r\n<pre class=\"fragment\">FIND_PACKAGE(ArrayFire)\r\nINCLUDE_DIRECTORIES(${ArrayFire_INCLUDE_DIRS})\r\n\r\n... [gather source files, etc.]\r\n\r\n# If you intend to use OpenCL, you need to find it\r\nFIND_PACKAGE(OpenCL)\r\nSET(EXTRA_LIBS ${CMAKE_THREAD_LIBS_INIT} ${OpenCL_LIBRARIES})\r\n\r\n# Or if you intend to use CUDA, you need it as well as NVVM:\r\nFIND_PACKAGE(CUDA)\r\nFIND_PACKAGE(NVVM) # this FIND script can be found in the ArrayFire CMake example repository\r\nSET(EXTRA_LIBS ${CMAKE_THREAD_LIBS_INIT} ${CUDA_LIBRARIES} ${NVVM_LIB})\r\n\r\nADD_EXECUTABLE(my_executable [list your source files here])\r\nTARGET_LINK_LIBRARIES(my_executable ${ArrayFire_LIBRARIES} ${EXTRA_LIBS})\r\n</pre>\r\nwhere <span class=\"lang:default decode:true  crayon-inline \">my_executable</span>  is the name of the executable you wish to create. See the <a href=\"https://cmake.org/documentation/\">CMake documentation</a> for more information on how to use CMake. Clearly the above code snippet precludes the use of both CUDA and OpenCL, see the<a href=\"https://github.com/bkloppenborg/arrayfire-cmake-example\">ArrayFire CMake Example</a> for an example of how to build executables for both backends from the same CMake script.\r\n\r\nIn the above code listing, the <span class=\"lang:default decode:true  crayon-inline \">FIND_PACKAGE</span>  will find the ArrayFire include files, libraries, and define several variables including:\r\n<pre class=\"lang:default highlight:0 decode:true fragment\">ArrayFire_INCLUDE_DIRS    - Location of ArrayFire\'s include directory.\r\nArrayFire_LIBRARIES       - Location of ArrayFire\'s libraries.\r\n                            This will default to a GPU backend if one\r\n                            is found\r\nArrayFire_FOUND           - True if ArrayFire has been located\r\n</pre>\r\nIf you wish to use a specific backend, the find script also defines these variables:\r\n<pre class=\"lang:default highlight:0 decode:true fragment \">ArrayFire_CPU_FOUND         - True of the ArrayFire CPU library has been found.\r\nArrayFire_CPU_LIBRARIES     - Location of ArrayFire\'s CPU library, if found\r\nArrayFire_CUDA_FOUND        - True of the ArrayFire CUDA library has been found.\r\nArrayFire_CUDA_LIBRARIES    - Location of ArrayFire\'s CUDA library, if found\r\nArrayFire_OpenCL_FOUND      - True of the ArrayFire OpenCL library has been found.\r\nArrayFire_OpenCL_LIBRARIES  - Location of ArrayFire\'s OpenCL library, if found\r\nArrayFire_Unified_FOUND     - True of the ArrayFire Unified library has been found.\r\nArrayFire_Unified_LIBRARIES - Location of ArrayFire\'s Unified library, if found\r\n</pre>\r\nTherefore, if you wish to target a specific specific backend, simply replace <span class=\"lang:default decode:true  crayon-inline \">${ArrayFire_LIBRARIES}</span>  with<span class=\"lang:default decode:true  crayon-inline \">${ArrayFire_CPU}</span> , <span class=\"lang:default decode:true  crayon-inline \">${ArrayFire_OPENCL}</span> , <span class=\"lang:default decode:true  crayon-inline \">${ArrayFire_CUDA}</span> , or <code>${ArrayFire_Unified}</code> in the<span class=\"lang:default decode:true  crayon-inline \">TARGET_LINK_LIBRARIES</span>  command above. If you intend on building your software to link with all of these backends, please see the <a href=\"https://github.com/arrayfire/arrayfire-project-templates\">CMake Project Example</a> which makes use of some fairly fun CMake tricks to avoid re-compiling code whenever possible.\r\n\r\nNext we need to instruct CMake to create build instructions and then compile. We suggest using CMake\'s out-of-source build functionality to keep your build and source files cleanly separated. To do this:\r\n<pre class=\"fragment\">cd your-project-directory\r\nmkdir build\r\ncd build\r\ncmake ..\r\nmake\r\n</pre>\r\n<em>NOTE:</em> If you have installed ArrayFire to a non-standard location, CMake can still help you out. When you execute CMake specify the path to the <span class=\"lang:default decode:true  crayon-inline \">ArrayFireConfig*</span>  files that are found in the <span class=\"lang:default decode:true  crayon-inline \">share/ArrayFire/cmake</span>  subdirectory of the installation folder. For example, if ArrayFire were installed locally to <span class=\"lang:default decode:true  crayon-inline \">/opt/ArrayFire</span>  then you would modify the <span class=\"lang:default decode:true  crayon-inline \">cmake</span> command above to contain the following definition:\r\n<pre class=\"fragment\">cmake -DArrayFire_DIR=/opt/ArrayFire/share/ArrayFire/cmake ..\r\n</pre>\r\nYou can also specify this information in the ccmake command-line interface.\r\n<h3>MakeFiles</h3>\r\nBuilding ArrayFire projects with Makefiles is fairly similar to CMake except you must specify all paths and libraries manually. As with any make project, you need to specify the include path to the directory containing <code><a class=\"el\" href=\"arrayfire_8h.htm\">arrayfire.h</a></code> file. This should be <span class=\"lang:default decode:true  crayon-inline \">-I /usr/local/include</span>  if you followed our installation instructions. Similarly, you will need to specify the path to the ArrayFire library using the <span class=\"lang:default decode:true  crayon-inline \">-L</span>  option (e.g. <span class=\"lang:default decode:true  crayon-inline \">-L/usr/local/lib</span> ) followed by the specific ArrayFire library you wish to use using the <code>-l</code> option (for example <span class=\"lang:default decode:true  crayon-inline \">-lafcpu</span> , <span class=\"lang:default decode:true  crayon-inline \">-lafopencl</span> , <span class=\"lang:default decode:true  crayon-inline \">-lafcuda</span> , or <span class=\"lang:default decode:true  crayon-inline \">-laf</span>  for the CPU, OpenCL, CUDA, and unified backends respectively.\r\n\r\nHere is a minimial example MakeFile which uses ArrayFire\'s CPU backend:\r\n<pre class=\"fragment\">LIBS=-lafcpu\r\nLIB_PATHS=-L/usr/lib\r\nINCLUDES=-I/usr/include\r\nCC=g++ $(COMPILER_OPTIONS)\r\nCOMPILER_OPTIONS=-std=c++11 -g\r\n\r\nall: main.cpp Makefile\r\n    $(CC) main.cpp -o test $(INCLUDES) $(LIBS) $(LIB_PATHS)</pre>','Setting up an ArrayFire Project on OSX','','inherit','open','closed','','8592-revision-v1','','','2015-11-06 22:25:27','2015-11-06 22:25:27','',8592,'http://sandbox.arrayfire.com/8592-revision-v1/',0,'revision','',0),(8609,18528,'2015-11-06 22:37:42','2015-11-06 22:37:42','<div class=\"header\">\r\n<div class=\"headertitle\">\r\n<div class=\"title\">Continuing our blog series \"<a href=\"http://sandbox.arrayfire.com/tag/learning-arrayfire-from-scratch/\">Learning ArrayFire from scratch</a>\" today we will discuss how to set up an ArrayFire project on OSX using XCode, CMake, or Makefiles.</div>\r\n</div>\r\n</div>\r\n<!--more-->\r\n\r\nOnce you have <a class=\"el\" href=\"installing.htm\">installed</a> ArrayFire on your system, the next thing to do is set up your build system. On OSX, you may create ArrayFire project using almost any editor, compiler, or build system. The only requirement is that you can include the ArrayFire header directory, and link with the ArrayFire library you intend to use.\r\n<h3>The big picture</h3>\r\nBy default, the ArrayFire OSX installer will place several files in your computer\'s <span class=\"lang:default decode:true  crayon-inline \">/usr/local</span>  directory. The installer will populate this directory with files in the following sub-directories:\r\n<pre class=\"lang:default highlight:0 decode:true fragment\">include/arrayfire.h         - Primary ArrayFire include file\r\ninclude/af/*.h              - Additional include files\r\nlib/libaf*                  - CPU, CUDA, and OpenCL libraries (.a, .so)\r\nlib/libforge*               - Visualization library\r\nshare/ArrayFire/cmake/*     - CMake config (find) scripts\r\nshare/ArrayFire/examples/*  - All ArrayFire examples\r\n</pre>\r\nBecause ArrayFire follows standard installation practices, you can use basically any build system to create and compile projects that use ArrayFire. Among the many possible build systems on Linux we suggest using ArrayFire with either CMake or Makefiles with CMake being our preferred build system.\r\n<h3>XCode</h3>\r\nAlthough we recommend using CMake to build ArrayFire projects on OSX (because you can save on re-compiling some files for multiple-backend deployments), you can use XCode if this is your preferred development platform. To save some time, we have created an sample XCode project in our <a href=\"https://github.com/arrayfire/arrayfire-project-templates\">ArrayFire Project Templates repository</a>.\r\n\r\nTo set up a basic C/C++ project in XCode do the following:\r\n<ol type=\"1\">\r\n	<li>Start up XCode. Choose OSX -&gt; Application, Command Line Tool for the project:\r\n<div class=\"image\"><a href=\"http://sandbox.arrayfire.com/wp-content/uploads/2015/11/xcode-startup.png\"><img class=\"alignnone wp-image-8596\" src=\"http://sandbox.arrayfire.com/wp-content/uploads/2015/11/xcode-startup.png\" alt=\"xcode-startup\" width=\"650\" height=\"387\" /></a></div></li>\r\n	<li>Fill in the details for your project and choose either C or C++ for the project:\r\n<div class=\"image\"><a href=\"http://sandbox.arrayfire.com/wp-content/uploads/2015/11/project-options.png\"><img class=\"alignnone wp-image-8597\" src=\"http://sandbox.arrayfire.com/wp-content/uploads/2015/11/project-options.png\" alt=\"project-options\" width=\"650\" height=\"393\" /></a></div></li>\r\n	<li>Next we need to configure the build settings. In the left-hand pane, click on the project. In the center pane, click on \"Build Settings\" followed by the \"All\" button:\r\n<div class=\"image\"><a href=\"http://sandbox.arrayfire.com/wp-content/uploads/2015/11/build-settings1.png\"><img class=\"alignnone wp-image-8600\" src=\"http://sandbox.arrayfire.com/wp-content/uploads/2015/11/build-settings1.png\" alt=\"build-settings\" width=\"900\" height=\"602\" /></a></div></li>\r\n	<li>Now search for \"Header Search Paths\" and add <span class=\"lang:default decode:true  crayon-inline \">/usr/local/include</span>  to the list:\r\n<div class=\"image\"><a href=\"http://sandbox.arrayfire.com/wp-content/uploads/2015/11/header-search-paths.png\"><img class=\"alignnone wp-image-8601\" src=\"http://sandbox.arrayfire.com/wp-content/uploads/2015/11/header-search-paths.png\" alt=\"header-search-paths\" width=\"650\" height=\"279\" /></a></div></li>\r\n	<li>Then search for \"Library Search Paths\" and add <span class=\"lang:default decode:true  crayon-inline \">/usr/local/lib</span>  to the list:\r\n<div class=\"image\"><a href=\"http://sandbox.arrayfire.com/wp-content/uploads/2015/11/library-search-paths.png\"><img class=\"alignnone wp-image-8602\" src=\"http://sandbox.arrayfire.com/wp-content/uploads/2015/11/library-search-paths.png\" alt=\"library-search-paths\" width=\"650\" height=\"285\" /></a></div></li>\r\n	<li>Next, we need to make sure the executable is linked with an ArrayFire library: To do this, click the \"Build Phases\" tab and expand the \"Link with Binary Library\" menu:\r\n<div class=\"image\"><a href=\"http://sandbox.arrayfire.com/wp-content/uploads/2015/11/build-phases.png\"><img class=\"alignnone wp-image-8603\" src=\"http://sandbox.arrayfire.com/wp-content/uploads/2015/11/build-phases.png\" alt=\"build-phases\" width=\"900\" height=\"269\" /></a></div></li>\r\n	<li>In the search dialog that pops up, choose the \"Add Other\" button from the lower right. Specify the<span class=\"lang:default decode:true  crayon-inline \">/usr/local/lib</span>  folder:\r\n<div class=\"image\"><a href=\"http://sandbox.arrayfire.com/wp-content/uploads/2015/11/library-folder-path.png\"><img class=\"alignnone wp-image-8599\" src=\"http://sandbox.arrayfire.com/wp-content/uploads/2015/11/library-folder-path.png\" alt=\"library-folder-path\" width=\"650\" height=\"567\" /></a></div></li>\r\n	<li>Next, select the ArrayFire library with which you wish to link your program. Your options will be:</li>\r\n</ol>\r\n<div class=\"fragment\">\r\n<div class=\"line\">\r\n<pre class=\"lang:default highlight:0 decode:true\">libafcuda.*.dylib   - CUDA backend\r\nlibafopencl.*.dylib - OpenCL backend\r\nlibafcpu.*.dylib    - CPU backend\r\nlibaf.*.dylib       - Unified backend</pre>\r\nIn the picture below, we have elected to link with the OpenCL backend:\r\n\r\n<a href=\"http://sandbox.arrayfire.com/wp-content/uploads/2015/11/pick-arrayfire-library.png\"><img class=\"alignnone wp-image-8598\" src=\"http://sandbox.arrayfire.com/wp-content/uploads/2015/11/pick-arrayfire-library.png\" alt=\"pick-arrayfire-library\" width=\"650\" height=\"566\" /></a>\r\n\r\n</div>\r\n</div>\r\n9. Lastly, lets test ArrayFire\'s functionality. In the left hand pane open the main.cpp` file and insert the following code:\r\n<div class=\"image\"></div>\r\n<div class=\"fragment\">\r\n<div class=\"line\">\r\n<pre class=\"lang:default decode:true\"> // Include the ArrayFire header file\r\n#include &lt;arrayfire.h&gt;\r\n \r\nint main(int argc, const char * argv[]) {\r\n   // Gather some information about the ArrayFire device\r\n   af::info();\r\n   return 0;\r\n}</pre>\r\n&nbsp;\r\n\r\n</div>\r\n</div>\r\nFinally, click the build button and you should see some information about your graphics card in the lower-section of your screen:\r\n<div class=\"image\"><a href=\"http://sandbox.arrayfire.com/wp-content/uploads/2015/11/afinfo-result.png\"><img class=\"alignnone wp-image-8594 size-full\" src=\"http://sandbox.arrayfire.com/wp-content/uploads/2015/11/afinfo-result.png\" alt=\"afinfo-result\" width=\"477\" height=\"135\" /></a></div>\r\n<h3>CMake</h3>\r\nWe recommend that the CMake build system be used to create ArrayFire projects. If you are writing a new ArrayFire project in C/C++ from scratch, we suggest you grab a copy of our <a href=\"https://github.com/arrayfire/arrayfire-project-templates\">CMake Project Example</a>; however, it is useful to read the documentation below in case you need to add ArrayFire to an existing project.\r\n\r\nAs <a href=\"#big-picture\">discussed above</a>, ArrayFire ships with a series of CMake scripts to make finding and using our library easy. The scripts will automatically find all versions of the ArrayFire library and pick the most powerful of the installed backends (typically CUDA).\r\n\r\nFirst create a file called<span class=\"lang:default decode:true  crayon-inline \"> CMakeLists.txt</span>  in your project directory:\r\n<pre class=\"lang:default decode:true fragment\">cd your-project-directory\r\ntouch CMakeLists.txt\r\n</pre>\r\nand populate it with the following code:\r\n<pre class=\"fragment\">FIND_PACKAGE(ArrayFire)\r\nINCLUDE_DIRECTORIES(${ArrayFire_INCLUDE_DIRS})\r\n\r\n... [gather source files, etc.]\r\n\r\n# If you intend to use OpenCL, you need to find it\r\nFIND_PACKAGE(OpenCL)\r\nSET(EXTRA_LIBS ${CMAKE_THREAD_LIBS_INIT} ${OpenCL_LIBRARIES})\r\n\r\n# Or if you intend to use CUDA, you need it as well as NVVM:\r\nFIND_PACKAGE(CUDA)\r\nFIND_PACKAGE(NVVM) # this FIND script can be found in the ArrayFire CMake example repository\r\nSET(EXTRA_LIBS ${CMAKE_THREAD_LIBS_INIT} ${CUDA_LIBRARIES} ${NVVM_LIB})\r\n\r\nADD_EXECUTABLE(my_executable [list your source files here])\r\nTARGET_LINK_LIBRARIES(my_executable ${ArrayFire_LIBRARIES} ${EXTRA_LIBS})\r\n</pre>\r\nwhere <span class=\"lang:default decode:true  crayon-inline \">my_executable</span>  is the name of the executable you wish to create. See the <a href=\"https://cmake.org/documentation/\">CMake documentation</a> for more information on how to use CMake. Clearly the above code snippet precludes the use of both CUDA and OpenCL, see the<a href=\"https://github.com/bkloppenborg/arrayfire-cmake-example\">ArrayFire CMake Example</a> for an example of how to build executables for both backends from the same CMake script.\r\n\r\nIn the above code listing, the <span class=\"lang:default decode:true  crayon-inline \">FIND_PACKAGE</span>  will find the ArrayFire include files, libraries, and define several variables including:\r\n<pre class=\"lang:default highlight:0 decode:true fragment\">ArrayFire_INCLUDE_DIRS    - Location of ArrayFire\'s include directory.\r\nArrayFire_LIBRARIES       - Location of ArrayFire\'s libraries.\r\n                            This will default to a GPU backend if one\r\n                            is found\r\nArrayFire_FOUND           - True if ArrayFire has been located\r\n</pre>\r\nIf you wish to use a specific backend, the find script also defines these variables:\r\n<pre class=\"lang:default highlight:0 decode:true fragment \">ArrayFire_CPU_FOUND         - True of the ArrayFire CPU library has been found.\r\nArrayFire_CPU_LIBRARIES     - Location of ArrayFire\'s CPU library, if found\r\nArrayFire_CUDA_FOUND        - True of the ArrayFire CUDA library has been found.\r\nArrayFire_CUDA_LIBRARIES    - Location of ArrayFire\'s CUDA library, if found\r\nArrayFire_OpenCL_FOUND      - True of the ArrayFire OpenCL library has been found.\r\nArrayFire_OpenCL_LIBRARIES  - Location of ArrayFire\'s OpenCL library, if found\r\nArrayFire_Unified_FOUND     - True of the ArrayFire Unified library has been found.\r\nArrayFire_Unified_LIBRARIES - Location of ArrayFire\'s Unified library, if found\r\n</pre>\r\nTherefore, if you wish to target a specific specific backend, simply replace <span class=\"lang:default decode:true  crayon-inline \">${ArrayFire_LIBRARIES}</span>  with<span class=\"lang:default decode:true  crayon-inline \">${ArrayFire_CPU}</span> , <span class=\"lang:default decode:true  crayon-inline \">${ArrayFire_OPENCL}</span> , <span class=\"lang:default decode:true  crayon-inline \">${ArrayFire_CUDA}</span> , or <code>${ArrayFire_Unified}</code> in the<span class=\"lang:default decode:true  crayon-inline \">TARGET_LINK_LIBRARIES</span>  command above. If you intend on building your software to link with all of these backends, please see the <a href=\"https://github.com/arrayfire/arrayfire-project-templates\">CMake Project Example</a> which makes use of some fairly fun CMake tricks to avoid re-compiling code whenever possible.\r\n\r\nNext we need to instruct CMake to create build instructions and then compile. We suggest using CMake\'s out-of-source build functionality to keep your build and source files cleanly separated. To do this:\r\n<pre class=\"fragment\">cd your-project-directory\r\nmkdir build\r\ncd build\r\ncmake ..\r\nmake\r\n</pre>\r\n<em>NOTE:</em> If you have installed ArrayFire to a non-standard location, CMake can still help you out. When you execute CMake specify the path to the <span class=\"lang:default decode:true  crayon-inline \">ArrayFireConfig*</span>  files that are found in the <span class=\"lang:default decode:true  crayon-inline \">share/ArrayFire/cmake</span>  subdirectory of the installation folder. For example, if ArrayFire were installed locally to <span class=\"lang:default decode:true  crayon-inline \">/opt/ArrayFire</span>  then you would modify the <span class=\"lang:default decode:true  crayon-inline \">cmake</span> command above to contain the following definition:\r\n<pre class=\"fragment\">cmake -DArrayFire_DIR=/opt/ArrayFire/share/ArrayFire/cmake ..\r\n</pre>\r\nYou can also specify this information in the ccmake command-line interface.\r\n<h3>MakeFiles</h3>\r\nBuilding ArrayFire projects with Makefiles is fairly similar to CMake except you must specify all paths and libraries manually. As with any make project, you need to specify the include path to the directory containing <code><a class=\"el\" href=\"arrayfire_8h.htm\">arrayfire.h</a></code> file. This should be <span class=\"lang:default decode:true  crayon-inline \">-I /usr/local/include</span>  if you followed our installation instructions. Similarly, you will need to specify the path to the ArrayFire library using the <span class=\"lang:default decode:true  crayon-inline \">-L</span>  option (e.g. <span class=\"lang:default decode:true  crayon-inline \">-L/usr/local/lib</span> ) followed by the specific ArrayFire library you wish to use using the <code>-l</code> option (for example <span class=\"lang:default decode:true  crayon-inline \">-lafcpu</span> , <span class=\"lang:default decode:true  crayon-inline \">-lafopencl</span> , <span class=\"lang:default decode:true  crayon-inline \">-lafcuda</span> , or <span class=\"lang:default decode:true  crayon-inline \">-laf</span>  for the CPU, OpenCL, CUDA, and unified backends respectively.\r\n\r\nHere is a minimial example MakeFile which uses ArrayFire\'s CPU backend:\r\n<pre class=\"fragment\">LIBS=-lafcpu\r\nLIB_PATHS=-L/usr/lib\r\nINCLUDES=-I/usr/include\r\nCC=g++ $(COMPILER_OPTIONS)\r\nCOMPILER_OPTIONS=-std=c++11 -g\r\n\r\nall: main.cpp Makefile\r\n    $(CC) main.cpp -o test $(INCLUDES) $(LIBS) $(LIB_PATHS)</pre>','Setting up an ArrayFire Project on OSX','','inherit','open','closed','','8592-revision-v1','','','2015-11-06 22:37:42','2015-11-06 22:37:42','',8592,'http://sandbox.arrayfire.com/8592-revision-v1/',0,'revision','',0),(8610,18528,'2015-11-06 22:40:37','2015-11-06 22:40:37','<div class=\"header\">\r\n<div class=\"headertitle\">\r\n<div class=\"title\">Continuing our blog series \"<a href=\"http://sandbox.arrayfire.com/tag/learning-arrayfire-from-scratch/\">Learning ArrayFire from scratch</a>\" today we will discuss how to set up an ArrayFire project on OSX using XCode, CMake, or Makefiles.</div>\r\n</div>\r\n</div>\r\n<!--more-->\r\n\r\nOnce you have <a class=\"el\" href=\"installing.htm\">installed</a> ArrayFire on your system, the next thing to do is set up your build system. On OSX, you may create ArrayFire project using almost any editor, compiler, or build system. The only requirement is that you can include the ArrayFire header directory, and link with the ArrayFire library you intend to use.\r\n<h3>The big picture</h3>\r\nBy default, the ArrayFire OSX installer will place several files in your computer\'s <span class=\"lang:default decode:true  crayon-inline \">/usr/local</span>  directory. The installer will populate this directory with files in the following sub-directories:\r\n<pre class=\"lang:default highlight:0 decode:true fragment\">include/arrayfire.h         - Primary ArrayFire include file\r\ninclude/af/*.h              - Additional include files\r\nlib/libaf*                  - CPU, CUDA, and OpenCL libraries (.a, .so)\r\nlib/libforge*               - Visualization library\r\nshare/ArrayFire/cmake/*     - CMake config (find) scripts\r\nshare/ArrayFire/examples/*  - All ArrayFire examples\r\n</pre>\r\nBecause ArrayFire follows standard installation practices, you can use basically any build system to create and compile projects that use ArrayFire. Among the many possible build systems on Linux we suggest using ArrayFire with either CMake or Makefiles with CMake being our preferred build system.\r\n<h3>XCode</h3>\r\nAlthough we recommend using CMake to build ArrayFire projects on OSX (because you can save on re-compiling some files for multiple-backend deployments), you can use XCode if this is your preferred development platform. To save some time, we have created an sample XCode project in our <a href=\"https://github.com/arrayfire/arrayfire-project-templates\">ArrayFire Project Templates repository</a> which is configured to build code for the CPU, OpenCL, CUDA, and Unified backends.\r\n\r\nTo set up a basic C/C++ project in XCode do the following:\r\n<ol type=\"1\">\r\n	<li>Start up XCode. Choose OSX -&gt; Application, Command Line Tool for the project:\r\n<div class=\"image\"><a href=\"http://sandbox.arrayfire.com/wp-content/uploads/2015/11/xcode-startup.png\"><img class=\"alignnone wp-image-8596\" src=\"http://sandbox.arrayfire.com/wp-content/uploads/2015/11/xcode-startup.png\" alt=\"xcode-startup\" width=\"650\" height=\"387\" /></a></div></li>\r\n	<li>Fill in the details for your project and choose either C or C++ for the project:\r\n<div class=\"image\"><a href=\"http://sandbox.arrayfire.com/wp-content/uploads/2015/11/project-options.png\"><img class=\"alignnone wp-image-8597\" src=\"http://sandbox.arrayfire.com/wp-content/uploads/2015/11/project-options.png\" alt=\"project-options\" width=\"650\" height=\"393\" /></a></div></li>\r\n	<li>Next we need to configure the build settings. In the left-hand pane, click on the project. In the center pane, click on \"Build Settings\" followed by the \"All\" button:\r\n<div class=\"image\"><a href=\"http://sandbox.arrayfire.com/wp-content/uploads/2015/11/build-settings1.png\"><img class=\"alignnone wp-image-8600\" src=\"http://sandbox.arrayfire.com/wp-content/uploads/2015/11/build-settings1.png\" alt=\"build-settings\" width=\"900\" height=\"602\" /></a></div></li>\r\n	<li>Now search for \"Header Search Paths\" and add <span class=\"lang:default decode:true  crayon-inline \">/usr/local/include</span>  to the list:\r\n<div class=\"image\"><a href=\"http://sandbox.arrayfire.com/wp-content/uploads/2015/11/header-search-paths.png\"><img class=\"alignnone wp-image-8601\" src=\"http://sandbox.arrayfire.com/wp-content/uploads/2015/11/header-search-paths.png\" alt=\"header-search-paths\" width=\"650\" height=\"279\" /></a></div></li>\r\n	<li>Then search for \"Library Search Paths\" and add <span class=\"lang:default decode:true  crayon-inline \">/usr/local/lib</span>  to the list:\r\n<div class=\"image\"><a href=\"http://sandbox.arrayfire.com/wp-content/uploads/2015/11/library-search-paths.png\"><img class=\"alignnone wp-image-8602\" src=\"http://sandbox.arrayfire.com/wp-content/uploads/2015/11/library-search-paths.png\" alt=\"library-search-paths\" width=\"650\" height=\"285\" /></a></div></li>\r\n	<li>Next, we need to make sure the executable is linked with an ArrayFire library: To do this, click the \"Build Phases\" tab and expand the \"Link with Binary Library\" menu:\r\n<div class=\"image\"><a href=\"http://sandbox.arrayfire.com/wp-content/uploads/2015/11/build-phases.png\"><img class=\"alignnone wp-image-8603\" src=\"http://sandbox.arrayfire.com/wp-content/uploads/2015/11/build-phases.png\" alt=\"build-phases\" width=\"900\" height=\"269\" /></a></div></li>\r\n	<li>In the search dialog that pops up, choose the \"Add Other\" button from the lower right. Specify the<span class=\"lang:default decode:true  crayon-inline \">/usr/local/lib</span>  folder:\r\n<div class=\"image\"><a href=\"http://sandbox.arrayfire.com/wp-content/uploads/2015/11/library-folder-path.png\"><img class=\"alignnone wp-image-8599\" src=\"http://sandbox.arrayfire.com/wp-content/uploads/2015/11/library-folder-path.png\" alt=\"library-folder-path\" width=\"650\" height=\"567\" /></a></div></li>\r\n	<li>Next, select the ArrayFire library with which you wish to link your program. Your options will be:</li>\r\n</ol>\r\n<div class=\"fragment\">\r\n<div class=\"line\">\r\n<pre class=\"lang:default highlight:0 decode:true\">libafcuda.*.dylib   - CUDA backend\r\nlibafopencl.*.dylib - OpenCL backend\r\nlibafcpu.*.dylib    - CPU backend\r\nlibaf.*.dylib       - Unified backend</pre>\r\nIn the picture below, we have elected to link with the OpenCL backend:\r\n\r\n<a href=\"http://sandbox.arrayfire.com/wp-content/uploads/2015/11/pick-arrayfire-library.png\"><img class=\"alignnone wp-image-8598\" src=\"http://sandbox.arrayfire.com/wp-content/uploads/2015/11/pick-arrayfire-library.png\" alt=\"pick-arrayfire-library\" width=\"650\" height=\"566\" /></a>\r\n\r\n</div>\r\n</div>\r\n9. Lastly, lets test ArrayFire\'s functionality. In the left hand pane open the main.cpp` file and insert the following code:\r\n<div class=\"image\"></div>\r\n<div class=\"fragment\">\r\n<div class=\"line\">\r\n<pre class=\"lang:default decode:true\"> // Include the ArrayFire header file\r\n#include &lt;arrayfire.h&gt;\r\n \r\nint main(int argc, const char * argv[]) {\r\n   // Gather some information about the ArrayFire device\r\n   af::info();\r\n   return 0;\r\n}</pre>\r\n&nbsp;\r\n\r\n</div>\r\n</div>\r\nFinally, click the build button and you should see some information about your graphics card in the lower-section of your screen:\r\n<div class=\"image\"><a href=\"http://sandbox.arrayfire.com/wp-content/uploads/2015/11/afinfo-result.png\"><img class=\"alignnone wp-image-8594 size-full\" src=\"http://sandbox.arrayfire.com/wp-content/uploads/2015/11/afinfo-result.png\" alt=\"afinfo-result\" width=\"477\" height=\"135\" /></a></div>\r\n<h3>CMake</h3>\r\nWe recommend that the CMake build system be used to create ArrayFire projects. If you are writing a new ArrayFire project in C/C++ from scratch, we suggest you grab a copy of our <a href=\"https://github.com/arrayfire/arrayfire-project-templates\">CMake Project Example</a>; however, it is useful to read the documentation below in case you need to add ArrayFire to an existing project.\r\n\r\nAs <a href=\"#big-picture\">discussed above</a>, ArrayFire ships with a series of CMake scripts to make finding and using our library easy. The scripts will automatically find all versions of the ArrayFire library and pick the most powerful of the installed backends (typically CUDA).\r\n\r\nFirst create a file called<span class=\"lang:default decode:true  crayon-inline \"> CMakeLists.txt</span>  in your project directory:\r\n<pre class=\"lang:default decode:true fragment\">cd your-project-directory\r\ntouch CMakeLists.txt\r\n</pre>\r\nand populate it with the following code:\r\n<pre class=\"fragment\">FIND_PACKAGE(ArrayFire)\r\nINCLUDE_DIRECTORIES(${ArrayFire_INCLUDE_DIRS})\r\n\r\n... [gather source files, etc.]\r\n\r\n# If you intend to use OpenCL, you need to find it\r\nFIND_PACKAGE(OpenCL)\r\nSET(EXTRA_LIBS ${CMAKE_THREAD_LIBS_INIT} ${OpenCL_LIBRARIES})\r\n\r\n# Or if you intend to use CUDA, you need it as well as NVVM:\r\nFIND_PACKAGE(CUDA)\r\nFIND_PACKAGE(NVVM) # this FIND script can be found in the ArrayFire CMake example repository\r\nSET(EXTRA_LIBS ${CMAKE_THREAD_LIBS_INIT} ${CUDA_LIBRARIES} ${NVVM_LIB})\r\n\r\nADD_EXECUTABLE(my_executable [list your source files here])\r\nTARGET_LINK_LIBRARIES(my_executable ${ArrayFire_LIBRARIES} ${EXTRA_LIBS})\r\n</pre>\r\nwhere <span class=\"lang:default decode:true  crayon-inline \">my_executable</span>  is the name of the executable you wish to create. See the <a href=\"https://cmake.org/documentation/\">CMake documentation</a> for more information on how to use CMake. Clearly the above code snippet precludes the use of both CUDA and OpenCL, see the<a href=\"https://github.com/bkloppenborg/arrayfire-cmake-example\">ArrayFire CMake Example</a> for an example of how to build executables for both backends from the same CMake script.\r\n\r\nIn the above code listing, the <span class=\"lang:default decode:true  crayon-inline \">FIND_PACKAGE</span>  will find the ArrayFire include files, libraries, and define several variables including:\r\n<pre class=\"lang:default highlight:0 decode:true fragment\">ArrayFire_INCLUDE_DIRS    - Location of ArrayFire\'s include directory.\r\nArrayFire_LIBRARIES       - Location of ArrayFire\'s libraries.\r\n                            This will default to a GPU backend if one\r\n                            is found\r\nArrayFire_FOUND           - True if ArrayFire has been located\r\n</pre>\r\nIf you wish to use a specific backend, the find script also defines these variables:\r\n<pre class=\"lang:default highlight:0 decode:true fragment \">ArrayFire_CPU_FOUND         - True of the ArrayFire CPU library has been found.\r\nArrayFire_CPU_LIBRARIES     - Location of ArrayFire\'s CPU library, if found\r\nArrayFire_CUDA_FOUND        - True of the ArrayFire CUDA library has been found.\r\nArrayFire_CUDA_LIBRARIES    - Location of ArrayFire\'s CUDA library, if found\r\nArrayFire_OpenCL_FOUND      - True of the ArrayFire OpenCL library has been found.\r\nArrayFire_OpenCL_LIBRARIES  - Location of ArrayFire\'s OpenCL library, if found\r\nArrayFire_Unified_FOUND     - True of the ArrayFire Unified library has been found.\r\nArrayFire_Unified_LIBRARIES - Location of ArrayFire\'s Unified library, if found\r\n</pre>\r\nTherefore, if you wish to target a specific specific backend, simply replace <span class=\"lang:default decode:true  crayon-inline \">${ArrayFire_LIBRARIES}</span>  with<span class=\"lang:default decode:true  crayon-inline \">${ArrayFire_CPU}</span> , <span class=\"lang:default decode:true  crayon-inline \">${ArrayFire_OPENCL}</span> , <span class=\"lang:default decode:true  crayon-inline \">${ArrayFire_CUDA}</span> , or <code>${ArrayFire_Unified}</code> in the<span class=\"lang:default decode:true  crayon-inline \">TARGET_LINK_LIBRARIES</span>  command above. If you intend on building your software to link with all of these backends, please see the <a href=\"https://github.com/arrayfire/arrayfire-project-templates\">CMake Project Example</a> which makes use of some fairly fun CMake tricks to avoid re-compiling code whenever possible.\r\n\r\nNext we need to instruct CMake to create build instructions and then compile. We suggest using CMake\'s out-of-source build functionality to keep your build and source files cleanly separated. To do this:\r\n<pre class=\"fragment\">cd your-project-directory\r\nmkdir build\r\ncd build\r\ncmake ..\r\nmake\r\n</pre>\r\n<em>NOTE:</em> If you have installed ArrayFire to a non-standard location, CMake can still help you out. When you execute CMake specify the path to the <span class=\"lang:default decode:true  crayon-inline \">ArrayFireConfig*</span>  files that are found in the <span class=\"lang:default decode:true  crayon-inline \">share/ArrayFire/cmake</span>  subdirectory of the installation folder. For example, if ArrayFire were installed locally to <span class=\"lang:default decode:true  crayon-inline \">/opt/ArrayFire</span>  then you would modify the <span class=\"lang:default decode:true  crayon-inline \">cmake</span> command above to contain the following definition:\r\n<pre class=\"fragment\">cmake -DArrayFire_DIR=/opt/ArrayFire/share/ArrayFire/cmake ..\r\n</pre>\r\nYou can also specify this information in the ccmake command-line interface.\r\n<h3>MakeFiles</h3>\r\nBuilding ArrayFire projects with Makefiles is fairly similar to CMake except you must specify all paths and libraries manually. As with any make project, you need to specify the include path to the directory containing <code><a class=\"el\" href=\"arrayfire_8h.htm\">arrayfire.h</a></code> file. This should be <span class=\"lang:default decode:true  crayon-inline \">-I /usr/local/include</span>  if you followed our installation instructions. Similarly, you will need to specify the path to the ArrayFire library using the <span class=\"lang:default decode:true  crayon-inline \">-L</span>  option (e.g. <span class=\"lang:default decode:true  crayon-inline \">-L/usr/local/lib</span> ) followed by the specific ArrayFire library you wish to use using the <code>-l</code> option (for example <span class=\"lang:default decode:true  crayon-inline \">-lafcpu</span> , <span class=\"lang:default decode:true  crayon-inline \">-lafopencl</span> , <span class=\"lang:default decode:true  crayon-inline \">-lafcuda</span> , or <span class=\"lang:default decode:true  crayon-inline \">-laf</span>  for the CPU, OpenCL, CUDA, and unified backends respectively.\r\n\r\nHere is a minimial example MakeFile which uses ArrayFire\'s CPU backend:\r\n<pre class=\"fragment\">LIBS=-lafcpu\r\nLIB_PATHS=-L/usr/lib\r\nINCLUDES=-I/usr/include\r\nCC=g++ $(COMPILER_OPTIONS)\r\nCOMPILER_OPTIONS=-std=c++11 -g\r\n\r\nall: main.cpp Makefile\r\n    $(CC) main.cpp -o test $(INCLUDES) $(LIBS) $(LIB_PATHS)</pre>','Setting up an ArrayFire Project on OSX','','inherit','open','closed','','8592-revision-v1','','','2015-11-06 22:40:37','2015-11-06 22:40:37','',8592,'http://sandbox.arrayfire.com/8592-revision-v1/',0,'revision','',0),(8611,18528,'2015-11-09 16:04:35','2015-11-09 16:04:35','Recently one of our interns completed his project ahead of schedule and asked if he could spend some time writing a particle filtering demo in ArrayFire for use at our upcoming trade shows. While learning the ins and outs of ArrayFire he posed several excellent questions which prompted us to start a series of blog posts entitled \"<a href=\"http://sandbox.arrayfire.com/tag/learning-arrayfire-from-scratch/\">Learning ArrayFire from scratch</a>\" that are geared to first-time users of our library.\r\n\r\nIn today\'s post I will cover the installation process on Windows, Mac, and Linux. Our next post will discuss the basics of setting up your first ArrayFire project.\r\n\r\n<!--more-->\r\n\r\nInstalling ArrayFire couldn\'t be easier. We ship installers for Windows, OSX, and Linux. Although you could <a href=\"https://github.com/arrayfire/arrayfire\">build ArrayFire from source</a>, we suggest using our pre-compiled binaries as they include the Intel Math Kernel Library to accelerate linear algebra functions.\r\n\r\nPlease note that although our download page requires a valid login, registration is free and downloading ArrayFire is also free. We request your contact information so that we may notify you of software updates and occasionally collect user feedback about our library.\r\n\r\nIn general, the installation process for ArrayFire looks like this:\r\n<ol type=\"1\">\r\n	<li>Install prerequisites</li>\r\n	<li><a href=\"http://sandbox.arrayfire.com/download/\">Download</a> the ArrayFire installer for your operating system</li>\r\n	<li>Install ArrayFire</li>\r\n	<li>Test the installation</li>\r\n	<li><a href=\"#GettingHelp\">Where to go for help?</a></li>\r\n</ol>\r\nBelow you will find instructions for\r\n<ul>\r\n	<li><a href=\"#Windows\">Windows</a></li>\r\n	<li>Linux including\r\n<ul>\r\n	<li><a href=\"#Debian\">Debian 8</a></li>\r\n	<li><a href=\"#Ubuntu\">Ubuntu 14.10 and later</a></li>\r\n	<li><a href=\"#Fedora\">Fedora 21</a></li>\r\n</ul>\r\n</li>\r\n	<li><a href=\"#OSX\">Mac OSX (.sh and brew)</a></li>\r\n</ul>\r\n<h3><a id=\"Windows\" class=\"anchor\"></a>Windows</h3>\r\nIf you wish to use CUDA or OpenCL please ensure that you have also installed\r\nsupport for these technologies from your video card vendor\'s website.\r\n\r\nNext <a href=\"http://sandbox.arrayfire.com/download/\">download</a> and run the ArrayFire installer.\r\nAfter it has completed, you need to add ArrayFire to the path for all users.\r\n<ol>\r\n	<li>Open Advanced System Settings:\r\n* Windows 8: Move the Mouse pointer to the bottom right corner of the screen, Right click, choose System. Then click \"Advanced System Settings\"\r\n* Windows 7: Open the Start Menu and Right Click on \"Computer\". Then choose Properties and click \"Advanced System Settings\"</li>\r\n	<li>In Advanced System Settings window, click on Advanced tab</li>\r\n	<li>Click on Environment Variables, then under System Variables, find PATH, and click on it.</li>\r\n	<li>In edit mode, append <span class=\"lang:default decode:true  crayon-inline \">%AF_PATH%/lib</span> . NOTE: Ensure that there is a semi-colon separating <span class=\"lang:default decode:true  crayon-inline \">%AF_PATH%/lib</span>  from any existing content (e.g. <span class=\"lang:default decode:true  crayon-inline \">EXISTING_PATHS;%AF_PATH%/lib;</span> ) otherwise other software may not function correctly.</li>\r\n</ol>\r\nFinally, verify that the path addition worked correctly. You can do this by running any of the HelloWorld examples located in <span class=\"lang:default decode:true  crayon-inline \">AF_PATH/examples/helloworld/</span>\r\n<h3>Linux</h3>\r\n<h4><a id=\"Debian\" class=\"anchor\"></a>Debian 8</h4>\r\nFirst install the prerequisite packages:\r\n<pre class=\"fragment\"># Prerequisite packages:\r\napt-get install libfreeimage-dev libatlas3gf-base libfftw3-dev libglew-dev libglewmx-dev libglfw3-dev cmake\r\n\r\n# Enable GPU support (OpenCL):\r\napt-get install ocl-icd-libopencl1\r\n</pre>\r\nIf you wish to use CUDA, please <a href=\"https://developer.nvidia.com/cuda-zone\">download the latest version of CUDA</a> and install it on your system.\r\n\r\nNext <a href=\"http://sandbox.arrayfire.com/download/\">download</a> ArrayFire. After you have the file, run the installer.\r\n<pre class=\"fragment\">./arrayfire_*_Linux_x86_64.sh --exclude-subdir --prefix=/usr/local\r\n</pre>\r\n<h4><a id=\"Fedora\" class=\"anchor\"></a>Fedora 21</h4>\r\nFirst install the prerequisite packages:\r\n<pre class=\"fragment \"># Install prerequiste packages\r\nyum install freeimage atlas fftw libGLEW libGLEWmx glfw cmake\r\n</pre>\r\nIf you wish to use CUDA, please <a href=\"https://developer.nvidia.com/cuda-downloads\">download the latest version of CUDA</a> and install it on your system.\r\n\r\nNext <a href=\"http://sandbox.arrayfire.com/download/\">download</a> ArrayFire. After you have the file, run the installer.\r\n<pre class=\"fragment\">./arrayfire_*_Linux_x86_64.sh --exclude-subdir --prefix=/usr/local\r\n</pre>\r\n<h4><a id=\"Ubuntu\" class=\"anchor\"></a>Ubuntu 14.04 and later</h4>\r\nFirst install the prerequisite packages:\r\n<pre class=\"fragment\"># Prerequisite packages:\r\nsudo apt-get install libfreeimage-dev libatlas3gf-base libfftw3-dev libglew-dev libglewmx-dev libglfw3-dev cmake\r\n</pre>\r\nUbuntu 14.04 will not have the libglfw3-dev package in its repositories. You can either build the library from source (following the <a href=\"https://github.com/arrayfire/arrayfire/wiki/Build-Instructions-for-Linux#general-dependencies\">instructions listed</a>) or install the library from a PPA as follows:\r\n<pre class=\"lang:default decode:true\">sudo apt-add repository ppa:keithw/glfw3\r\nsudo apt-get update\r\nsudo apt-get install glfw3</pre>\r\nAfter this point, the installation should proceed identically to Ubuntu 14.10 or newer.\r\n\r\nIf you are using ArrayFire on the Tegra-K1 also install these packages:\r\n<pre class=\"fragment\">sudo apt-get install libatlas3gf-base libatlas-dev libfftw3-dev liblapacke-dev\r\n</pre>\r\nIf your system has a CUDA GPU, we suggest downloading the latest drivers from NVIDIA in the form of a Debian package and installing using the package manager. At present, CUDA downloads can be found on the <a href=\"https://developer.nvidia.com/cuda-downloads\">NVIDIA CUDA download page</a> Follow NVIDIA\'s instructions for getting CUDA set up.\r\n\r\nIf you wish to use OpenCL, simply install the OpenCL ICD loader along with any drivers required for your hardware.\r\n<pre class=\"fragment\"># Enable GPU support (OpenCL):\r\napt-get install ocl-icd-libopencl1\r\n</pre>\r\nFinally, <a href=\"http://sandbox.arrayfire.com/download/\">download</a> ArrayFire. After you have the file, run the installer using:\r\n<pre class=\"fragment\">./arrayfire_*_Linux_x86_64.sh --exclude-subdir --prefix=/usr/local\r\n</pre>\r\n<h3><a id=\"OSX\" class=\"anchor\"></a>Mac OSX</h3>\r\nOn OSX there are several dependencies that are not integrated into the operating system. The ArrayFire installer automatically satisfies these dependencies using <a href=\"http://brew.sh/\">Homebrew</a>. If you don\'t have Homebrew installed on your system, the ArrayFire installer will ask you do to so.\r\n\r\nSimply <a href=\"http://sandbox.arrayfire.com/download\">download</a> the ArrayFire installer and double-click it to carry out the installation.\r\n\r\nArrayFire can also be installed through Homebrew directly using <span class=\"lang:default decode:true  crayon-inline \">brew install arrayfire</span> ; however, it will not include MKL acceleration of linear algebra functions.\r\n<h3><a id=\"Testing\" class=\"anchor\"></a>Testing the installation</h3>\r\nAfter ArrayFire is installed, you can build the example programs as follows:\r\n<pre class=\"fragment\">cp -r /usr/local/share/doc/arrayfire/examples .\r\ncd examples\r\nmkdir build\r\ncd build\r\ncmake ..\r\nmake\r\n</pre>\r\n<h3><a id=\"GettingHelp\" class=\"anchor\"></a>Getting help</h3>\r\n<ul>\r\n	<li>Google Groups: <a href=\"https://groups.google.com/forum/#!forum/arrayfire-users\">https://groups.google.com/forum/#!forum/arrayfire-users</a></li>\r\n	<li>ArrayFire Services: <a href=\"http://sandbox.arrayfire.com/consulting/\">Consulting</a> | <a href=\"http://sandbox.arrayfire.com/support/\">Support</a> | <a href=\"http://sandbox.arrayfire.com/training/\">Training</a></li>\r\n	<li>ArrayFire Blogs: <a href=\"http://sandbox.arrayfire.com/blog/\">http://sandbox.arrayfire.com/blog/</a></li>\r\n	<li>Email: <a href=\"#\">technical@arrayfire.com</a></li>\r\n</ul>\r\n&nbsp;','Learning ArrayFire from scratch: Installation','','inherit','open','closed','','8542-revision-v1','','','2015-11-09 16:04:35','2015-11-09 16:04:35','',8542,'http://sandbox.arrayfire.com/8542-revision-v1/',0,'revision','',0),(8613,6,'2015-11-10 18:45:22','2015-11-10 18:45:22','<img src=\"http://sc15.supercomputing.org/sites/all/themes/sc14/files/sc15-logo.png\" alt=\"SC15\" />\r\n\r\nSC15 is almost here! We\'re getting excited to head down to Austin, Texas, to be a part of this <a href=\"http://sc15.supercomputing.org/\">excellent conference</a>. It\'s a great place for soaking up HPC knowledge, getting inspired, and connecting with the brightest minds in the industry. Here\'s a quick run-down of where we\'ll be.\r\n\r\n<img class=\"alignright size-medium wp-image-6977\" src=\"http://sandbox.arrayfire.com/wp-content/uploads/2014/10/IMG_0737-300x225.jpg\" alt=\"IMG_0737\" width=\"300\" height=\"225\" />\r\n\r\n<strong>Visit our booth.</strong> We\'re booth #2229. We\'ll be showing off our latest demos and our engineers will be available for questions. Ask your questions, meet the team, or just bounce some ideas.\r\n\r\n<strong>Try our in-booth tutorials.</strong> Want to learn how to use <a href=\"http://sandbox.arrayfire.com/\">ArrayFire</a> to accelerate your code? Stop by and receive an in-booth tutorial from one of our ArrayFire experts. We’ll show you how the open source ArrayFire software library makes programming GPUs and other accelerators fast and easy.\r\n\r\n<b>Join us for a user meeting. </b>ArrayFire is more than a software library—it\'s an active community. Come to one of our user group meetings to get practical tips for working with ArrayFire and to network with other ArrayFire users. Visit our booth for more details.\r\n\r\n<strong>Set up individual meetings.</strong> Whether you live across the state or across the world, SC15 is a great time to connect one-on-one with us. Set up an appointment to discuss your work with an ArrayFire engineer at SC using our <a href=\"http://meetme.so/arrayfire\">meeting scheduler</a>.\r\n\r\nSee you in Austin!','ArrayFire at SC15','','publish','open','closed','','arrayfire-at-sc15','','','2015-11-10 18:53:01','2015-11-10 18:53:01','',0,'http://sandbox.arrayfire.com/?p=8613',0,'post','',0),(8619,18528,'2015-11-10 17:56:29','2015-11-10 17:56:29','<div class=\"header\">\r\n<div class=\"headertitle\">\r\n<div class=\"title\">Continuing our blog series \"<a href=\"http://sandbox.arrayfire.com/tag/learning-arrayfire-from-scratch/\">Learning ArrayFire from scratch</a>\" today we will discuss how to set up an ArrayFire project on OSX using XCode, CMake, or Makefiles.</div>\r\n</div>\r\n</div>\r\n<!--more-->\r\n\r\nOnce you have <a class=\"el\" href=\"installing.htm\">installed</a> ArrayFire on your system, the next thing to do is set up your build system. On OSX, you may create ArrayFire project using almost any editor, compiler, or build system. The only requirement is that you can include the ArrayFire header directory, and link with the ArrayFire library you intend to use.\r\n<h3>The big picture</h3>\r\nBy default, the ArrayFire OSX installer will place several files in your computer\'s <span class=\"lang:default decode:true  crayon-inline \">/usr/local</span>  directory. The installer will populate this directory with files in the following sub-directories:\r\n<pre class=\"lang:default highlight:0 decode:true fragment \">include/arrayfire.h         - Primary ArrayFire include file\r\ninclude/af/*.h              - Additional include files\r\nlib/libaf*                  - CPU, CUDA, and OpenCL libraries (.a, .so)\r\nlib/libforge*               - Visualization library\r\nshare/ArrayFire/cmake/*     - CMake config (find) scripts\r\nshare/ArrayFire/examples/*  - All ArrayFire examples\r\n</pre>\r\nBecause ArrayFire follows standard installation practices, you can use basically any build system to create and compile projects that use ArrayFire. Among the many possible build systems on Linux we suggest using ArrayFire with either CMake or Makefiles with CMake being our preferred build system.\r\n<h3>XCode</h3>\r\nAlthough we recommend using CMake to build ArrayFire projects on OSX (because you can save on re-compiling some files for multiple-backend deployments), you can use XCode if this is your preferred development platform. To save some time, we have created an sample XCode project in our <a href=\"https://github.com/arrayfire/arrayfire-project-templates\">ArrayFire Project Templates repository</a> which is configured to build code for the CPU, OpenCL, CUDA, and Unified backends.\r\n\r\nTo set up a basic C/C++ project in XCode do the following:\r\n<ol type=\"1\">\r\n	<li>Start up XCode. Choose OSX -&gt; Application, Command Line Tool for the project:\r\n<div class=\"image\"><a href=\"http://sandbox.arrayfire.com/wp-content/uploads/2015/11/xcode-startup.png\"><img class=\"alignnone wp-image-8596\" src=\"http://sandbox.arrayfire.com/wp-content/uploads/2015/11/xcode-startup.png\" alt=\"xcode-startup\" width=\"650\" height=\"387\" /></a></div></li>\r\n	<li>Fill in the details for your project and choose either C or C++ for the project:\r\n<div class=\"image\"><a href=\"http://sandbox.arrayfire.com/wp-content/uploads/2015/11/project-options.png\"><img class=\"alignnone wp-image-8597\" src=\"http://sandbox.arrayfire.com/wp-content/uploads/2015/11/project-options.png\" alt=\"project-options\" width=\"650\" height=\"393\" /></a></div></li>\r\n	<li>Next we need to configure the build settings. In the left-hand pane, click on the project. In the center pane, click on \"Build Settings\" followed by the \"All\" button:\r\n<div class=\"image\"><a href=\"http://sandbox.arrayfire.com/wp-content/uploads/2015/11/build-settings1.png\"><img class=\"alignnone wp-image-8600\" src=\"http://sandbox.arrayfire.com/wp-content/uploads/2015/11/build-settings1.png\" alt=\"build-settings\" width=\"900\" height=\"602\" /></a></div></li>\r\n	<li>Now search for \"Header Search Paths\" and add <span class=\"lang:default decode:true  crayon-inline \">/usr/local/include</span>  to the list:\r\n<div class=\"image\"><a href=\"http://sandbox.arrayfire.com/wp-content/uploads/2015/11/header-search-paths.png\"><img class=\"alignnone wp-image-8601\" src=\"http://sandbox.arrayfire.com/wp-content/uploads/2015/11/header-search-paths.png\" alt=\"header-search-paths\" width=\"650\" height=\"279\" /></a></div></li>\r\n	<li>Then search for \"Library Search Paths\" and add <span class=\"lang:default decode:true  crayon-inline \">/usr/local/lib</span>  to the list:\r\n<div class=\"image\"><a href=\"http://sandbox.arrayfire.com/wp-content/uploads/2015/11/library-search-paths.png\"><img class=\"alignnone wp-image-8602\" src=\"http://sandbox.arrayfire.com/wp-content/uploads/2015/11/library-search-paths.png\" alt=\"library-search-paths\" width=\"650\" height=\"285\" /></a></div></li>\r\n	<li>Next, we need to make sure the executable is linked with an ArrayFire library: To do this, click the \"Build Phases\" tab and expand the \"Link with Binary Library\" menu:\r\n<div class=\"image\"><a href=\"http://sandbox.arrayfire.com/wp-content/uploads/2015/11/build-phases.png\"><img class=\"alignnone wp-image-8603\" src=\"http://sandbox.arrayfire.com/wp-content/uploads/2015/11/build-phases.png\" alt=\"build-phases\" width=\"900\" height=\"269\" /></a></div></li>\r\n	<li>In the search dialog that pops up, choose the \"Add Other\" button from the lower right. Specify the<span class=\"lang:default decode:true  crayon-inline \">/usr/local/lib</span>  folder:\r\n<div class=\"image\"><a href=\"http://sandbox.arrayfire.com/wp-content/uploads/2015/11/library-folder-path.png\"><img class=\"alignnone wp-image-8599\" src=\"http://sandbox.arrayfire.com/wp-content/uploads/2015/11/library-folder-path.png\" alt=\"library-folder-path\" width=\"650\" height=\"567\" /></a></div></li>\r\n	<li>Next, select the ArrayFire library with which you wish to link your program. Your options will be:</li>\r\n</ol>\r\n<div class=\"fragment\">\r\n<div class=\"line\">\r\n<pre class=\"lang:default highlight:0 decode:true\">libafcuda.*.dylib   - CUDA backend\r\nlibafopencl.*.dylib - OpenCL backend\r\nlibafcpu.*.dylib    - CPU backend\r\nlibaf.*.dylib       - Unified backend</pre>\r\nIn the picture below, we have elected to link with the OpenCL backend:\r\n\r\n<a href=\"http://sandbox.arrayfire.com/wp-content/uploads/2015/11/pick-arrayfire-library.png\"><img class=\"alignnone wp-image-8598\" src=\"http://sandbox.arrayfire.com/wp-content/uploads/2015/11/pick-arrayfire-library.png\" alt=\"pick-arrayfire-library\" width=\"650\" height=\"566\" /></a>\r\n\r\n</div>\r\n</div>\r\n9. Lastly, lets test ArrayFire\'s functionality. In the left hand pane open the main.cpp` file and insert the following code:\r\n<div class=\"image\"></div>\r\n<div class=\"fragment\">\r\n<div class=\"line\">\r\n<pre class=\"lang:default decode:true\"> // Include the ArrayFire header file\r\n#include &lt;arrayfire.h&gt;\r\n \r\nint main(int argc, const char * argv[]) {\r\n   // Gather some information about the ArrayFire device\r\n   af::info();\r\n   return 0;\r\n}</pre>\r\n&nbsp;\r\n\r\n</div>\r\n</div>\r\nFinally, click the build button and you should see some information about your graphics card in the lower-section of your screen:\r\n<div class=\"image\"><a href=\"http://sandbox.arrayfire.com/wp-content/uploads/2015/11/afinfo-result.png\"><img class=\"alignnone wp-image-8594 size-full\" src=\"http://sandbox.arrayfire.com/wp-content/uploads/2015/11/afinfo-result.png\" alt=\"afinfo-result\" width=\"477\" height=\"135\" /></a></div>\r\n<h3>CMake</h3>\r\nWe recommend that the CMake build system be used to create ArrayFire projects. If you are writing a new ArrayFire project in C/C++ from scratch, we suggest you grab a copy of our <a href=\"https://github.com/arrayfire/arrayfire-project-templates\">CMake Project Example</a>; however, it is useful to read the documentation below in case you need to add ArrayFire to an existing project.\r\n\r\nAs <a href=\"#big-picture\">discussed above</a>, ArrayFire ships with a series of CMake scripts to make finding and using our library easy. The scripts will automatically find all versions of the ArrayFire library and pick the most powerful of the installed backends (typically CUDA).\r\n\r\nFirst create a file called<span class=\"lang:default decode:true  crayon-inline \"> CMakeLists.txt</span>  in your project directory:\r\n<pre class=\"lang:default decode:true fragment\">cd your-project-directory\r\ntouch CMakeLists.txt\r\n</pre>\r\nand populate it with the following code:\r\n<pre class=\"fragment\">FIND_PACKAGE(ArrayFire)\r\nINCLUDE_DIRECTORIES(${ArrayFire_INCLUDE_DIRS})\r\n\r\n... [gather source files, etc.]\r\n\r\n# If you intend to use OpenCL, you need to find it\r\nFIND_PACKAGE(OpenCL)\r\nSET(EXTRA_LIBS ${CMAKE_THREAD_LIBS_INIT} ${OpenCL_LIBRARIES})\r\n\r\n# Or if you intend to use CUDA, you need it as well as NVVM:\r\nFIND_PACKAGE(CUDA)\r\nFIND_PACKAGE(NVVM) # this FIND script can be found in the ArrayFire CMake example repository\r\nSET(EXTRA_LIBS ${CMAKE_THREAD_LIBS_INIT} ${CUDA_LIBRARIES} ${NVVM_LIB})\r\n\r\nADD_EXECUTABLE(my_executable [list your source files here])\r\nTARGET_LINK_LIBRARIES(my_executable ${ArrayFire_LIBRARIES} ${EXTRA_LIBS})\r\n</pre>\r\nwhere <span class=\"lang:default decode:true  crayon-inline \">my_executable</span>  is the name of the executable you wish to create. See the <a href=\"https://cmake.org/documentation/\">CMake documentation</a> for more information on how to use CMake. Clearly the above code snippet precludes the use of both CUDA and OpenCL, see the<a href=\"https://github.com/bkloppenborg/arrayfire-cmake-example\">ArrayFire CMake Example</a> for an example of how to build executables for both backends from the same CMake script.\r\n\r\nIn the above code listing, the <span class=\"lang:default decode:true  crayon-inline \">FIND_PACKAGE</span>  will find the ArrayFire include files, libraries, and define several variables including:\r\n<pre class=\"lang:default highlight:0 decode:true fragment\">ArrayFire_INCLUDE_DIRS    - Location of ArrayFire\'s include directory.\r\nArrayFire_LIBRARIES       - Location of ArrayFire\'s libraries.\r\n                            This will default to a GPU backend if one\r\n                            is found\r\nArrayFire_FOUND           - True if ArrayFire has been located\r\n</pre>\r\nIf you wish to use a specific backend, the find script also defines these variables:\r\n<pre class=\"lang:default highlight:0 decode:true fragment \">ArrayFire_CPU_FOUND         - True of the ArrayFire CPU library has been found.\r\nArrayFire_CPU_LIBRARIES     - Location of ArrayFire\'s CPU library, if found\r\nArrayFire_CUDA_FOUND        - True of the ArrayFire CUDA library has been found.\r\nArrayFire_CUDA_LIBRARIES    - Location of ArrayFire\'s CUDA library, if found\r\nArrayFire_OpenCL_FOUND      - True of the ArrayFire OpenCL library has been found.\r\nArrayFire_OpenCL_LIBRARIES  - Location of ArrayFire\'s OpenCL library, if found\r\nArrayFire_Unified_FOUND     - True of the ArrayFire Unified library has been found.\r\nArrayFire_Unified_LIBRARIES - Location of ArrayFire\'s Unified library, if found\r\n</pre>\r\nTherefore, if you wish to target a specific specific backend, simply replace <span class=\"lang:default decode:true  crayon-inline \">${ArrayFire_LIBRARIES}</span>  with<span class=\"lang:default decode:true  crayon-inline \">${ArrayFire_CPU}</span> , <span class=\"lang:default decode:true  crayon-inline \">${ArrayFire_OPENCL}</span> , <span class=\"lang:default decode:true  crayon-inline \">${ArrayFire_CUDA}</span> , or <code>${ArrayFire_Unified}</code> in the<span class=\"lang:default decode:true  crayon-inline \">TARGET_LINK_LIBRARIES</span>  command above. If you intend on building your software to link with all of these backends, please see the <a href=\"https://github.com/arrayfire/arrayfire-project-templates\">CMake Project Example</a> which makes use of some fairly fun CMake tricks to avoid re-compiling code whenever possible.\r\n\r\nNext we need to instruct CMake to create build instructions and then compile. We suggest using CMake\'s out-of-source build functionality to keep your build and source files cleanly separated. To do this:\r\n<pre class=\"fragment\">cd your-project-directory\r\nmkdir build\r\ncd build\r\ncmake ..\r\nmake\r\n</pre>\r\n<em>NOTE:</em> If you have installed ArrayFire to a non-standard location, CMake can still help you out. When you execute CMake specify the path to the <span class=\"lang:default decode:true  crayon-inline \">ArrayFireConfig*</span>  files that are found in the <span class=\"lang:default decode:true  crayon-inline \">share/ArrayFire/cmake</span>  subdirectory of the installation folder. For example, if ArrayFire were installed locally to <span class=\"lang:default decode:true  crayon-inline \">/opt/ArrayFire</span>  then you would modify the <span class=\"lang:default decode:true  crayon-inline \">cmake</span> command above to contain the following definition:\r\n<pre class=\"fragment\">cmake -DArrayFire_DIR=/opt/ArrayFire/share/ArrayFire/cmake ..\r\n</pre>\r\nYou can also specify this information in the ccmake command-line interface.\r\n<h3>MakeFiles</h3>\r\nBuilding ArrayFire projects with Makefiles is fairly similar to CMake except you must specify all paths and libraries manually. As with any make project, you need to specify the include path to the directory containing <code><a class=\"el\" href=\"arrayfire_8h.htm\">arrayfire.h</a></code> file. This should be <span class=\"lang:default decode:true  crayon-inline \">-I /usr/local/include</span>  if you followed our installation instructions. Similarly, you will need to specify the path to the ArrayFire library using the <span class=\"lang:default decode:true  crayon-inline \">-L</span>  option (e.g. <span class=\"lang:default decode:true  crayon-inline \">-L/usr/local/lib</span> ) followed by the specific ArrayFire library you wish to use using the <code>-l</code> option (for example <span class=\"lang:default decode:true  crayon-inline \">-lafcpu</span> , <span class=\"lang:default decode:true  crayon-inline \">-lafopencl</span> , <span class=\"lang:default decode:true  crayon-inline \">-lafcuda</span> , or <span class=\"lang:default decode:true  crayon-inline \">-laf</span>  for the CPU, OpenCL, CUDA, and unified backends respectively.\r\n\r\nHere is a minimial example MakeFile which uses ArrayFire\'s CPU backend:\r\n<pre class=\"fragment\">LIBS=-lafcpu\r\nLIB_PATHS=-L/usr/lib\r\nINCLUDES=-I/usr/include\r\nCC=g++ $(COMPILER_OPTIONS)\r\nCOMPILER_OPTIONS=-std=c++11 -g\r\n\r\nall: main.cpp Makefile\r\n    $(CC) main.cpp -o test $(INCLUDES) $(LIBS) $(LIB_PATHS)</pre>','Setting up an ArrayFire Project on OSX','','inherit','open','closed','','8592-revision-v1','','','2015-11-10 17:56:29','2015-11-10 17:56:29','',8592,'http://sandbox.arrayfire.com/8592-revision-v1/',0,'revision','',0),(8625,6,'2015-11-10 18:42:31','2015-11-10 18:42:31','<img src=\"http://sc15.supercomputing.org/sites/all/themes/sc14/files/sc15-logo.png\" alt=\"SC15\" />\r\n\r\nSC15 is almost here! We\'re getting excited to head down to Austin, Texas, to be a part of this <a href=\"http://sc15.supercomputing.org/\">excellent conference</a>. It\'s a great place for soaking up HPC knowledge, getting inspired, and connecting with the brightest minds in the industry. Here\'s a quick run-down of where we\'ll be.\r\n\r\n<img class=\"alignright size-medium wp-image-6977\" src=\"http://sandbox.arrayfire.com/wp-content/uploads/2014/10/IMG_0737-300x225.jpg\" alt=\"IMG_0737\" width=\"300\" height=\"225\" />\r\n\r\n<strong>Visit our booth.</strong> We\'re booth <a href=\"http://iebms.heiexpo.com/iebms/oep/oep_p2_details.aspx?sessionid=fb5ei7fe6eikfbkfepej5&amp;OrderNbr=7508\">#2229</a>. We\'ll be showing off our latest demos and our engineers will be available for questions. Ask your questions, meet the team, or just bounce some ideas.\r\n\r\n<strong>Try our in-booth tutorials.</strong> Want to learn how to use <a href=\"http://sandbox.arrayfire.com/\">ArrayFire</a> to accelerate your code? Stop by and receive a free in-booth tutorial from one of our ArrayFire experts. We’ll show you how the ArrayFire software library makes programming GPUs and other accelerators fast and easy.\r\n\r\n&nbsp;\r\n\r\n<b>Join us for a user meeting. </b>ArrayFire is more than a software library—it\'s a community. Come to our user meeting to get practical tips for working with ArrayFire and to network with other ArrayFire users! Visit our booth for more details.\r\n\r\n<strong>Set up individual meetings.</strong> Whether you live across the state or across the world, SC is a great time to connect one-on-one with us. Set up an appointment to discuss your work with an ArrayFire engineer at SC using our <a href=\"http://meetme.so/arrayfire\">meeting scheduler</a>.\r\n\r\nSee you in Austin!','ArrayFire at SC14','','inherit','open','closed','','8613-revision-v1','','','2015-11-10 18:42:31','2015-11-10 18:42:31','',8613,'http://sandbox.arrayfire.com/8613-revision-v1/',0,'revision','',0),(8626,6,'2015-11-10 18:45:22','2015-11-10 18:45:22','<img src=\"http://sc15.supercomputing.org/sites/all/themes/sc14/files/sc15-logo.png\" alt=\"SC15\" />\r\n\r\nSC15 is almost here! We\'re getting excited to head down to Austin, Texas, to be a part of this <a href=\"http://sc15.supercomputing.org/\">excellent conference</a>. It\'s a great place for soaking up HPC knowledge, getting inspired, and connecting with the brightest minds in the industry. Here\'s a quick run-down of where we\'ll be.\r\n\r\n<img class=\"alignright size-medium wp-image-6977\" src=\"http://sandbox.arrayfire.com/wp-content/uploads/2014/10/IMG_0737-300x225.jpg\" alt=\"IMG_0737\" width=\"300\" height=\"225\" />\r\n\r\n<strong>Visit our booth.</strong> We\'re booth <a href=\"http://iebms.heiexpo.com/iebms/oep/oep_p2_details.aspx?sessionid=fb5ei7fe6eikfbkfepej5&amp;OrderNbr=7508\">#2229</a>. We\'ll be showing off our latest demos and our engineers will be available for questions. Ask your questions, meet the team, or just bounce some ideas.\r\n\r\n<strong>Try our in-booth tutorials.</strong> Want to learn how to use <a href=\"http://sandbox.arrayfire.com/\">ArrayFire</a> to accelerate your code? Stop by and receive an in-booth tutorial from one of our ArrayFire experts. We’ll show you how the open source ArrayFire software library makes programming GPUs and other accelerators fast and easy.\r\n\r\n<b>Join us for a user meeting. </b>ArrayFire is more than a software library—it\'s a community. Come to one of our user group meetings to get practical tips for working with ArrayFire and to network with other ArrayFire users. Visit our booth for more details.\r\n\r\n<strong>Set up individual meetings.</strong> Whether you live across the state or across the world, SC15 is a great time to connect one-on-one with us. Set up an appointment to discuss your work with an ArrayFire engineer at SC using our <a href=\"http://meetme.so/arrayfire\">meeting scheduler</a>.\r\n\r\nSee you in Austin!','ArrayFire at SC15','','inherit','open','closed','','8613-revision-v1','','','2015-11-10 18:45:22','2015-11-10 18:45:22','',8613,'http://sandbox.arrayfire.com/8613-revision-v1/',0,'revision','',0),(8627,6,'2015-11-10 18:49:49','2015-11-10 18:49:49','<img src=\"http://sc15.supercomputing.org/sites/all/themes/sc14/files/sc15-logo.png\" alt=\"SC15\" />\n\nSC15 is almost here! We\'re getting excited to head down to Austin, Texas, to be a part of this <a href=\"http://sc15.supercomputing.org/\">excellent conference</a>. It\'s a great place for soaking up HPC knowledge, getting inspired, and connecting with the brightest minds in the industry. Here\'s a quick run-down of where we\'ll be.\n\n<img class=\"alignright size-medium wp-image-6977\" src=\"http://sandbox.arrayfire.com/wp-content/uploads/2014/10/IMG_0737-300x225.jpg\" alt=\"IMG_0737\" width=\"300\" height=\"225\" />\n\n<strong>Visit our booth.</strong> We\'re booth #2229. We\'ll be showing off our latest demos and our engineers will be available for questions. Ask your questions, meet the team, or just bounce some ideas.\n\n<strong>Try our in-booth tutorials.</strong> Want to learn how to use <a href=\"http://sandbox.arrayfire.com/\">ArrayFire</a> to accelerate your code? Stop by and receive an in-booth tutorial from one of our ArrayFire experts. We’ll show you how the open source ArrayFire software library makes programming GPUs and other accelerators fast and easy.\n\n<b>Join us for a user meeting. </b>ArrayFire is more than a software library—it\'s an active community. Come to one of our user group meetings to get practical tips for working with ArrayFire and to network with other ArrayFire users. Visit our booth for more details.\n\n<strong>Set up individual meetings.</strong> Whether you live across the state or across the world, SC15 is a great time to connect one-on-one with us. Set up an appointment to discuss your work with an ArrayFire engineer at SC using our <a href=\"http://meetme.so/arrayfire\">meeting scheduler</a>.\n\nSee you in Austin!','ArrayFire at SC15','','inherit','open','closed','','8613-autosave-v1','','','2015-11-10 18:49:49','2015-11-10 18:49:49','',8613,'http://sandbox.arrayfire.com/8613-autosave-v1/',0,'revision','',0),(8630,6,'2015-11-10 18:47:16','2015-11-10 18:47:16','<img src=\"http://sc15.supercomputing.org/sites/all/themes/sc14/files/sc15-logo.png\" alt=\"SC15\" />\r\n\r\nSC15 is almost here! We\'re getting excited to head down to Austin, Texas, to be a part of this <a href=\"http://sc15.supercomputing.org/\">excellent conference</a>. It\'s a great place for soaking up HPC knowledge, getting inspired, and connecting with the brightest minds in the industry. Here\'s a quick run-down of where we\'ll be.\r\n\r\n<img class=\"alignright size-medium wp-image-6977\" src=\"http://sandbox.arrayfire.com/wp-content/uploads/2014/10/IMG_0737-300x225.jpg\" alt=\"IMG_0737\" width=\"300\" height=\"225\" />\r\n\r\n<strong>Visit our booth.</strong> We\'re booth #2229. We\'ll be showing off our latest demos and our engineers will be available for questions. Ask your questions, meet the team, or just bounce some ideas.\r\n\r\n<strong>Try our in-booth tutorials.</strong> Want to learn how to use <a href=\"http://sandbox.arrayfire.com/\">ArrayFire</a> to accelerate your code? Stop by and receive an in-booth tutorial from one of our ArrayFire experts. We’ll show you how the open source ArrayFire software library makes programming GPUs and other accelerators fast and easy.\r\n\r\n<b>Join us for a user meeting. </b>ArrayFire is more than a software library—it\'s a community. Come to one of our user group meetings to get practical tips for working with ArrayFire and to network with other ArrayFire users. Visit our booth for more details.\r\n\r\n<strong>Set up individual meetings.</strong> Whether you live across the state or across the world, SC15 is a great time to connect one-on-one with us. Set up an appointment to discuss your work with an ArrayFire engineer at SC using our <a href=\"http://meetme.so/arrayfire\">meeting scheduler</a>.\r\n\r\nSee you in Austin!','ArrayFire at SC15','','inherit','open','closed','','8613-revision-v1','','','2015-11-10 18:47:16','2015-11-10 18:47:16','',8613,'http://sandbox.arrayfire.com/8613-revision-v1/',0,'revision','',0),(8631,6,'2015-11-10 18:49:51','2015-11-10 18:49:51','<img src=\"http://sc15.supercomputing.org/sites/all/themes/sc14/files/sc15-logo.png\" alt=\"SC15\" />\r\n\r\nSC15 is almost here! We\'re getting excited to head down to Austin, Texas, to be a part of this <a href=\"http://sc15.supercomputing.org/\">excellent conference</a>. It\'s a great place for soaking up HPC knowledge, getting inspired, and connecting with the brightest minds in the industry. Here\'s a quick run-down of where we\'ll be.\r\n\r\n<img class=\"alignright size-medium wp-image-6977\" src=\"http://sandbox.arrayfire.com/wp-content/uploads/2014/10/IMG_0737-300x225.jpg\" alt=\"IMG_0737\" width=\"300\" height=\"225\" />\r\n\r\n<strong>Visit our booth.</strong> We\'re booth #2229. We\'ll be showing off our latest demos and our engineers will be available for questions. Ask your questions, meet the team, or just bounce some ideas.\r\n\r\n<strong>Try our in-booth tutorials.</strong> Want to learn how to use <a href=\"http://sandbox.arrayfire.com/\">ArrayFire</a> to accelerate your code? Stop by and receive an in-booth tutorial from one of our ArrayFire experts. We’ll show you how the open source ArrayFire software library makes programming GPUs and other accelerators fast and easy.\r\n\r\n<b>Join us for a user meeting. </b>ArrayFire is more than a software library—it\'s an active community. Come to one of our user group meetings to get practical tips for working with ArrayFire and to network with other ArrayFire users. Visit our booth for more details.\r\n\r\n<strong>Set up individual meetings.</strong> Whether you live across the state or across the world, SC15 is a great time to connect one-on-one with us. Set up an appointment to discuss your work with an ArrayFire engineer at SC using our <a href=\"http://meetme.so/arrayfire\">meeting scheduler</a>.\r\n\r\nSee you in Austin!','ArrayFire at SC15','','inherit','open','closed','','8613-revision-v1','','','2015-11-10 18:49:51','2015-11-10 18:49:51','',8613,'http://sandbox.arrayfire.com/8613-revision-v1/',0,'revision','',0),(8633,18673,'2016-05-24 10:00:08','2016-05-24 14:00:08','One of the most common questions we see on the <a href=\"https://groups.google.com/forum/#!forum/arrayfire-users\">ArrayFire Google Group</a> pertains to methods to manipulate the dimensions of ArrayFire array objects. Thus we will continue the \"<a href=\"http://sandbox.arrayfire.com/tag/learning-arrayfire-from-scratch/\">Learning ArrayFire from scratch</a>\" blog series by providing a detailed discussion of the numerous functions that permit you to change the dimentionality, flatten, flip, join, shift, transpose, and tile arrays.\r\n\r\n<!--more-->\r\n\r\nArrayFire provides several different methods for manipulating arrays and matrices. The functionality includes:\r\n<ul>\r\n 	<li><a href=\"#moddims\">moddims()</a> - change the dimensions of an array without changing the data</li>\r\n 	<li><a href=\"#array\">array()</a> - create a (shallow) copy of an array with different dimensions.</li>\r\n 	<li><a href=\"#flat\">flat()</a> - flatten an array to one dimension</li>\r\n 	<li><a href=\"#flip\">flip()</a> - flip an array along a dimension</li>\r\n 	<li><a href=\"#join\">join()</a> - join up to 4 arrays</li>\r\n 	<li><a href=\"#reorder\">reorder()</a> - changes the dimension order within the array</li>\r\n 	<li><a href=\"#shift\">shift()</a> - shifts data along a dimension</li>\r\n 	<li><a href=\"#tile\">tile()</a> - repeats an array along a dimension</li>\r\n 	<li><a href=\"#transpose\">transpose()</a> - performs a matrix transpose</li>\r\n 	<li><a href=\"#transpose\">T()</a> - transpose a matrix or vector (shorthand notation)</li>\r\n 	<li><a href=\"#transpose\">H()</a> - Hermitian Transpose (conjugate-transpose) a matrix</li>\r\n</ul>\r\nBelow we provide several examples of these functions and their use. However, if you come to this page far in the future, we suggest you <a href=\"http://arrayfire.org/docs/matrixmanipulation.htm\">visit the documentation on this topic</a> to see the latest information on these topics.\r\n<a name=\"flat\"></a>\r\n<h4>flat()</h4>\r\nThe flat() function flattens an array to one dimension:\r\n<pre class=\"lang:default decode:true \">a [3 3 1 1]\r\n1.0000 4.0000 7.0000\r\n2.0000 5.0000 8.0000\r\n3.0000 6.0000 9.0000\r\n\r\nflat(a) [9 1 1 1]\r\n1.0000\r\n2.0000\r\n3.0000\r\n4.0000\r\n5.0000\r\n6.0000\r\n7.0000\r\n8.0000\r\n9.0000</pre>\r\nThe flat function can be called from C and C++ as follows:\r\n<pre class=\"lang:default decode:true\">af_err af_flat(af_array* out, const af_array in) \r\n– C interface for flat() function\r\n\r\narray af::flat(const array&amp; in)\r\n– C++ interface for flat() function</pre>\r\n<a name=\"flip\"></a>\r\n<h4>flip()</h4>\r\nThe flip() function flips the contents of an array along a chosen dimension. In the example below, we show the 5x2 array flipped along the zeroth (i.e. within a column) and first (e.g. across rows) axes:\r\n<pre class=\"lang:default decode:true \">a [5 2 1 1]\r\n1.0000 6.0000\r\n2.0000 7.0000\r\n3.0000 8.0000\r\n4.0000 9.0000\r\n5.0000 10.0000\r\n\r\nflip(a, 0) [5 2 1 1]\r\n5.0000 10.0000\r\n4.0000 9.0000\r\n3.0000 8.0000\r\n2.0000 7.0000\r\n1.0000 6.0000\r\n\r\nflip(a, 1) [5 2 1 1]\r\n6.0000 1.0000\r\n7.0000 2.0000\r\n8.0000 3.0000\r\n9.0000 4.0000\r\n10.0000 5.0000</pre>\r\nThe flip function can be called from C and C++ as follows:\r\n<pre class=\"lang:default decode:true\">af_err af_flip(af_array *out, const af_array in, const unsigned dim) \r\n– C interface for flip()\r\n\r\narray af::flip(const array &amp;in, const unsigned dim) \r\n– C++ interface for flip()</pre>\r\n<a name=\"join\"></a>\r\n<h4>join()</h4>\r\nThe join() function joins arrays along a specific dimension. The C++ interface can join up to four arrays whereas the C interface supports up to 10 arrays. Here is an example of how to use join an array to itself:\r\n<pre class=\"lang:default decode:true \">a [5 1 1 1]\r\n1.0000\r\n2.0000\r\n3.0000\r\n4.0000\r\n5.0000\r\n\r\njoin(0, a, a) [10 1 1 1]\r\n1.0000\r\n2.0000\r\n3.0000\r\n4.0000\r\n5.0000\r\n1.0000\r\n2.0000\r\n3.0000\r\n4.0000\r\n5.0000\r\n\r\njoin(1, a, a) [5 2 1 1]\r\n1.0000 1.0000\r\n2.0000 2.0000\r\n3.0000 3.0000\r\n4.0000 4.0000\r\n5.0000 5.0000</pre>\r\nThe join function has several candidate functions in C:\r\n<pre class=\"lang:default decode:true\">af_err af_join(af_array *out, const int dim, const af_array first, const af_array second) \r\n– C interface function to join 2 arrays along a dimension\r\n\r\naf_err af_join_many(af_array *out, const int dim, const unsigned n_arrays, const af_array *inputs) \r\n– C interface function to join up to 10 arrays along a dimension</pre>\r\nand in C++:\r\n<pre class=\"lang:default decode:true\">array af::join(const int dim, const array &amp;first, const array &amp;second) \r\n– Joins 2 arrays along a dimension\r\n\r\narray af::join(const int dim, const array &amp;first, const array &amp;second, const array &amp;third) \r\n– Joins 3 arrays along a dimension.\r\n\r\narray af::join(const int dim, const array &amp;first, const array &amp;second, const array &amp;third, const array &amp;fourth) \r\n– Joins 4 arrays along a dimension</pre>\r\n<a name=\"join\"></a>\r\n\r\n<a name=\"moddims\"></a>\r\n<h4>moddims()</h4>\r\nThe moddims() function changes the dimensions of an array without changing its data or order. Note that this function modifies only the metadata associated with the array. It does not modify the content of the array. Here is an example of moddims() converting an 8x1 array into a 2x4 and then back to a 8x1:\r\n<pre class=\"lang:default decode:true\">a [8 1 1 1]\r\n1.0000\r\n2.0000\r\n1.0000\r\n2.0000\r\n1.0000\r\n2.0000\r\n1.0000\r\n2.0000\r\n\r\naf::dim4 new_dims(2, 4);\r\nmoddims(a, new_dims) [2 4 1 1]\r\n1.0000 1.0000 1.0000 1.0000\r\n2.0000 2.0000 2.0000 2.0000\r\n\r\nmoddims(a, a.elements(), 1, 1, 1) [8 1 1 1]\r\n1.0000\r\n2.0000\r\n1.0000\r\n2.0000\r\n1.0000\r\n2.0000\r\n1.0000\r\n2.0000</pre>\r\nThe moddims function has a single form in the C API:\r\n<pre class=\"lang:default decode:true\">af_err af_moddims(af_array *out, const af_array in, const unsigned ndims, const dim_t *const dims) \r\n– C interface to mod dimensions of an array</pre>\r\nAnd several overloaded candidates in the C++ API:\r\n<pre class=\"lang:default decode:true\">array af::moddims(const array &amp;in, const unsigned ndims, const dim_t *const dims) \r\n– mods number of dimensions to match ndims as specidied in the array dims\r\n\r\narray af::moddims(const array &amp;in, const dim4 &amp;dims) \r\n– mods dimensions as specified by dims\r\n\r\narray af::moddims(const array &amp;in, const dim_t d0, const dim_t d1=1, const dim_t d2=1, const dim_t d3=1) \r\n– mods dimensions of an array</pre>\r\n<a name=\"moddims\"></a>\r\n\r\n<a name=\"reorder\"></a>\r\n<h4>reorder()</h4>\r\nThe reorder() function modifies the order of data within an array by exchanging data according to the change in dimensionality. The linear ordering of data within the array is preserved.\r\n<pre class=\"lang:default decode:true \">a [2 2 3 1]\r\n1.0000 3.0000\r\n2.0000 4.0000\r\n1.0000 3.0000\r\n2.0000 4.0000\r\n1.0000 3.0000\r\n2.0000 4.0000\r\n\r\nreorder(a, 1, 0, 2) [2 2 3 1] //equivalent to a transpose\r\n1.0000 2.0000\r\n3.0000 4.0000\r\n1.0000 2.0000\r\n3.0000 4.0000\r\n1.0000 2.0000\r\n3.0000 4.0000\r\n\r\nreorder(a, 2, 0, 1) [3 2 2 1]\r\n1.0000 2.0000\r\n1.0000 2.0000\r\n1.0000 2.0000\r\n3.0000 4.0000\r\n3.0000 4.0000\r\n3.0000 4.0000</pre>\r\nThe reorder function has several candidates functions in the C/C++ APIs:\r\n<pre class=\"lang:default decode:true\">af_err af_reorder(af_array *out, const af_array in, const unsigned x, const unsigned y, const unsigned z, const unsigned w) \r\n– C interface for reordering function\r\n\r\narray af::reorder(const array &amp;in, const unsigned x, const unsigned y=1, const unsigned z=2, const unsigned w=3) \r\n– Reorders dimensions of an array</pre>\r\n<a name=\"reorder\"></a>\r\n\r\n<a name=\"shift\"></a>\r\n<h4>shift()</h4>\r\nThe shift() function shifts data in a circular buffer fashion along a chosen dimension. Consider the following example:\r\n<pre class=\"lang:default decode:true \">a [3 5 1 1]\r\n0.0000 0.0000 0.0000 0.0000 0.0000\r\n3.0000 4.0000 5.0000 1.0000 2.0000\r\n3.0000 4.0000 5.0000 1.0000 2.0000\r\n\r\nshift(a, 0, 2 ) [3 5 1 1]\r\n0.0000 0.0000 0.0000 0.0000 0.0000\r\n1.0000 2.0000 3.0000 4.0000 5.0000\r\n1.0000 2.0000 3.0000 4.0000 5.0000\r\n\r\nshift(a, -1, 2 ) [3 5 1 1]\r\n1.0000 2.0000 3.0000 4.0000 5.0000\r\n1.0000 2.0000 3.0000 4.0000 5.0000\r\n0.0000 0.0000 0.0000 0.0000 0.0000</pre>\r\nThe shift function can be called from C and C++ as follows:\r\n<pre class=\"lang:default decode:true\">af_err af_shift(af_array *out, const af_array in, const int x, const int y, const int z, const int w) \r\n– C interface for shifting an array\r\n\r\narray af::shift(const array &amp;in, const int x, const int y=0, const int z=0, const int w=0) \r\n– Shifts array along specified dimensions</pre>\r\n<a name=\"shift\"></a>\r\n\r\n<a name=\"tile\"></a>\r\n<h4>tile()</h4>\r\nThe tile() function repeats an array along the specified dimension. For example below we show how to tile an array along the zeroth and first dimensions of an array:\r\n<pre class=\"lang:default decode:true\">a [3 1 1 1]\r\n1.0000\r\n2.0000\r\n3.0000\r\n\r\n// Repeat array a twice in the zeroth dimension\r\ntile(a, 2) [6 1 1 1]\r\n1.0000\r\n2.0000\r\n3.0000\r\n1.0000\r\n2.0000\r\n3.0000\r\n\r\n// Repeat array a twice along both the zeroth and first dimensions\r\ntile(a, 2, 2) [6 2 1 1]\r\n1.0000 1.0000\r\n2.0000 2.0000\r\n3.0000 3.0000\r\n1.0000 1.0000\r\n2.0000 2.0000\r\n3.0000 3.0000\r\n\r\n// Repeat array a twice along the first and three times along \r\n// the second dimension.\r\naf::dim4 tile_dims(1, 2, 3);\r\ntile(a, tile_dims) [3 2 3 1]\r\n1.0000 1.0000\r\n2.0000 2.0000\r\n3.0000 3.0000\r\n1.0000 1.0000\r\n2.0000 2.0000\r\n3.0000 3.0000\r\n1.0000 1.0000\r\n2.0000 2.0000\r\n3.0000 3.0000</pre>\r\nThe C interface for tile is as follows:\r\n<pre class=\"lang:default decode:true\">af_err af_tile(af_array *out, const af_array in, const unsigned x, const unsigned y, const unsigned z, const unsigned w) \r\n– C interface for tiling an array</pre>\r\nThe C++ interface has two overloads\r\n<pre class=\"lang:default decode:true\">array af::tile(const array &amp;in, const unsigned x, const unsigned y=1, const unsigned z=1, const unsigned w=1) \r\n– Tiles array along specified dimensions\r\n\r\narray af::tile(const array &amp;in, const dim4 &amp;dims) \r\n– Tile an array according to a dim4 object</pre>\r\n<a name=\"tile\"></a>\r\n\r\n<a name=\"transpose\"></a>\r\n<h4>transpose()</h4>\r\nThe transpose() function performs a standard matrix transpose. The input array must have the dimensions of a 2D-matrix.\r\n<pre class=\"lang:default decode:true\">a [3 3 1 1]\r\n1.0000 3.0000 3.0000\r\n2.0000 1.0000 3.0000\r\n2.0000 2.0000 1.0000\r\n\r\ntranspose(a) [3 3 1 1]\r\n1.0000 2.0000 2.0000\r\n3.0000 1.0000 2.0000\r\n3.0000 3.0000 1.0000</pre>\r\nThe C interfaces for transpose are as follows:\r\n<pre class=\"lang:default decode:true\">af_err af_transpose(af_array *out, af_array in, const bool conjugate) \r\n– C interface to transpose a matrix.\r\n\r\naf_err af_transpose_inplace(af_array in, const bool conjugate) \r\n– C interface to transpose a matrix in-place.</pre>\r\nThe C++ interface has two primary functions and two shorthand versions:\r\n<pre class=\"lang:default decode:true\">array af::transpose(const array &amp;in, const bool conjugate=false) \r\n– Transposes a matrix.\r\n\r\nvoid af::transposeInPlace(array &amp;in, const bool conjugate=false) \r\n– Transposes a matrix in-place.\r\n\r\n__array af::T() \r\n– Transpose a matrix\r\n\r\n__array af::H() \r\n– Conjugate Transpose (Hermitian transpose) of a matrix</pre>\r\nHere is an example of how the shorthand versions might be used:\r\n<pre class=\"lang:default decode:true \">array x = randu(2, 2, f32);\r\naf_print(x.T()); // transpose (real)\r\narray c = randu(2, 2, c32);\r\naf_print(c.T()); // transpose (complex)\r\naf_print(c.H()); // Hermitian (conjugate) transpose</pre>\r\n<a name=\"transpose\"></a>\r\n\r\n<a name=\"array\"></a>\r\n<h4>array()</h4>\r\narray() can be used to create a (shallow) copy of a matrix with different dimensions. The total number of elements must remain the same. This function is a wrapper over the moddims() function discussed earlier.\r\n\r\nCombining re-ordering functions to enumerate grid coordinates\r\n\r\nBy using a combination of the array restructuring functions, one can quickly code complex manipulation patterns with a few lines of code. For example, consider generating (x,y) coordinates for a grid where each axis goes from 1 to n. Instead of using several loops to populate our arrays we can just use a small combination of the above functions.\r\n<pre class=\"lang:default decode:true \">unsigned n=3;\r\naf::array xy = join(1,\r\n    tile(seq(1, n), n),\r\n    flat( transpose(tile(seq(1, n), 1, n)) )\r\n);\r\n\r\nxy [9 2 1 1]\r\n1.0000 1.0000\r\n2.0000 1.0000\r\n3.0000 1.0000\r\n1.0000 2.0000\r\n2.0000 2.0000\r\n3.0000 2.0000\r\n1.0000 3.0000\r\n2.0000 3.0000\r\n3.0000 3.0000</pre>\r\nWe hope you have found these instructions to be useful. As always, if you have questions about ArrayFire, feel free to drop us a line on the <a href=\"https://groups.google.com/forum/#!forum/arrayfire-users\">Google Group</a>.','Manipulating and restructuring arrays','','publish','open','closed','','manipulating-and-restructuring-arrays','','','2016-05-18 15:37:22','2016-05-18 19:37:22','',0,'http://sandbox.arrayfire.com/?p=8633',0,'post','',0),(8634,18673,'2015-11-10 19:01:19','2015-11-10 19:01:19','Now that we’ve learned how to create arrays and apply simple operations to them, lets explore how we can re-order and modify them. Arrayfire offers several functions that can easily reformat the structures of arrays.\r\n<h5><a id=\"These_functions_are_2\"></a>These functions are:</h5>\r\n<ul>\r\n	<li><strong>flat()</strong> - flatten an array to one dimension</li>\r\n	<li><strong>flip()</strong> - flip an array along a dimension</li>\r\n	<li><strong>join()</strong> - join up to 4 arrays</li>\r\n	<li><strong>moddims()</strong> - change the dimensions of an array without changing the data</li>\r\n	<li><strong>reorder()</strong> - changes the dimension order within the array</li>\r\n	<li><strong>shift()</strong> - shifts data along a dimension</li>\r\n	<li><strong>tile()</strong> - repeats an array along a dimension</li>\r\n	<li><strong>transpose()</strong> - performs a matrix transpose</li>\r\n</ul>\r\nBelow, are several examples showing the details of each function. We’ll start by defining an example matrix:\r\n<h2><a id=\"flat_15\"></a>flat()</h2>\r\nThe <strong>flat()</strong> function flattens an array to one dimension.\r\n<pre><code>a [3 3 1 1]\r\n    1.0000     4.0000     7.0000 \r\n    2.0000     5.0000     8.0000 \r\n    3.0000     6.0000     9.0000 \r\n\r\nflat(a) [9 1 1 1]\r\n    1.0000 \r\n    2.0000 \r\n    3.0000 \r\n    4.0000 \r\n    5.0000 \r\n    6.0000 \r\n    7.0000 \r\n    8.0000 \r\n    9.0000 \r\n</code></pre>\r\nThe flat function has the following overloads:\r\n<ul>\r\n	<li><strong>array af::flat(const array&amp; in)</strong> – flatten an array</li>\r\n	<li><strong>af_err af_flat(af_array* out, const af_array in)</strong> – C interface for flat() function</li>\r\n</ul>\r\n<h2><a id=\"flip_40\"></a>flip()</h2>\r\nThe <strong>flip()</strong> function flips the contents of an array along a chosen dimension.\r\n<pre><code>a [5 2 1 1]\r\n    1.0000     6.0000 \r\n    2.0000     7.0000 \r\n    3.0000     8.0000 \r\n    4.0000     9.0000 \r\n    5.0000    10.0000 \r\n\r\nflip(a, 0) [5 2 1 1]\r\n    5.0000    10.0000 \r\n    4.0000     9.0000 \r\n    3.0000     8.0000 \r\n    2.0000     7.0000 \r\n    1.0000     6.0000 \r\n\r\nflip(a, 1) [5 2 1 1]\r\n    6.0000     1.0000 \r\n    7.0000     2.0000 \r\n    8.0000     3.0000 \r\n    9.0000     4.0000 \r\n   10.0000     5.0000 </code></pre>\r\nThe flip function has the following overloads:\r\n<ul>\r\n	<li><strong>flip (const array &amp;in, const unsigned dim)</strong> – flips an array along a dimension</li>\r\n	<li><strong>af_flip (af_array *out, const af_array in, const unsigned dim)</strong> – C interface for flip()</li>\r\n</ul>\r\n<h2><a id=\"join_68\"></a>join()</h2>\r\nThe <strong>join()</strong> function can join up to 4 arrays together.\r\n<pre><code>a [5 1 1 1]\r\n    1.0000 \r\n    2.0000 \r\n    3.0000 \r\n    4.0000 \r\n    5.0000 \r\n\r\njoin(0, a, a) [10 1 1 1]\r\n    1.0000 \r\n    2.0000 \r\n    3.0000 \r\n    4.0000 \r\n    5.0000 \r\n    1.0000 \r\n    2.0000 \r\n    3.0000 \r\n    4.0000 \r\n    5.0000 \r\n\r\njoin(1, a, a) [5 2 1 1]\r\n    1.0000     1.0000 \r\n    2.0000     2.0000 \r\n    3.0000     3.0000 \r\n    4.0000     4.0000 \r\n    5.0000     5.0000 </code></pre>\r\nThe join function has several overloads:\r\n<ul>\r\n	<li><strong>array join (const int dim, const array &amp;first, const array &amp;second)</strong> – Joins 2 arrays along a dimension</li>\r\n	<li><strong>array join (const int dim, const array &amp;first, const array &amp;second, const array &amp;third)</strong> – Joins 3 arrays along a dimension.</li>\r\n	<li><strong>array join (const int dim, const array &amp;first, const array &amp;second, const array &amp;third, const array &amp;fourth)</strong> – Joins 4 arrays along a dimension</li>\r\n	<li><strong>array af_join (af_array *out, const int dim, const af_array first, const af_array second)</strong> – C interface function to join 2 arrays along a dimension.</li>\r\n	<li><strong>af_err af_join_many (af_array *out, const int dim, const unsigned n_arrays, const af_array *inputs)</strong> – C interface function to join up to 10 arrays along a dimension.</li>\r\n</ul>\r\n<h2><a id=\"moddims_108\"></a>moddims()</h2>\r\nThe <strong>moddims()</strong> function changes the dimensions of an array without changing its data or order. It is important to remember that the function only modifies the <em>metadata</em> associated with the array and does not actually modify the content of the array.\r\n<pre><code>a [8 1 1 1]\r\n    1.0000 \r\n    2.0000 \r\n    1.0000 \r\n    2.0000 \r\n    1.0000 \r\n    2.0000 \r\n    1.0000 \r\n    2.0000 \r\n\r\nmoddims(a, new_dims) [2 4 1 1]\r\n    1.0000     1.0000     1.0000     1.0000 \r\n    2.0000     2.0000     2.0000     2.0000 \r\n\r\nmoddims(a, a.elements(), 1, 1, 1) [8 1 1 1]\r\n    1.0000 \r\n    2.0000 \r\n    1.0000 \r\n    2.0000 \r\n    1.0000 \r\n    2.0000 \r\n    1.0000 \r\n    2.0000 \r\n</code></pre>\r\nThe moddims function has several overloads:\r\n<ul>\r\n	<li><strong>array moddims (const array &amp;in, const unsigned ndims, const dim_t *const dims)</strong> – mods number of dimensions to match <em>ndims</em> as specidied in the array <em>dims</em></li>\r\n	<li><strong>array moddims (const array &amp;in, const dim4 &amp;dims)</strong> – mods dimensions as specified by <em>dims</em></li>\r\n	<li><strong>array moddims (const array &amp;in, const dim_t d0, const dim_t d1=1, const dim_t d2=1, const dim_t d3=1)</strong> – mods dimensions of an array</li>\r\n	<li><strong>af_err af_moddims (af_array *out, const af_array in, const unsigned ndims, const dim_t *const dims)</strong> – C interface to mod dimensions of an array</li>\r\n</ul>\r\n<h2><a id=\"reorder_141\"></a>reorder()</h2>\r\nThe <strong>reorder()</strong> function changes the order of the dimensions within the array. This requires actually altering the underlying data of the array.\r\n<pre><code>a [2 2 3 1]\r\n    1.0000     3.0000 \r\n    2.0000     4.0000 \r\n\r\n    1.0000     3.0000 \r\n    2.0000     4.0000 \r\n\r\n    1.0000     3.0000 \r\n    2.0000     4.0000 \r\n\r\n\r\nreorder(a, 1, 0, 2) [2 2 3 1]  //equivalent to a transpose\r\n    1.0000     2.0000 \r\n    3.0000     4.0000 \r\n\r\n    1.0000     2.0000 \r\n    3.0000     4.0000 \r\n\r\n    1.0000     2.0000 \r\n    3.0000     4.0000 \r\n\r\n\r\nreorder(a, 2, 0, 1) [3 2 2 1]\r\n    1.0000     2.0000 \r\n    1.0000     2.0000 \r\n    1.0000     2.0000 \r\n\r\n    3.0000     4.0000 \r\n    3.0000     4.0000 \r\n    3.0000     4.0000 \r\n</code></pre>\r\nThe reorder function the following several overloads:\r\n<ul>\r\n	<li><strong>array reorder (const array &amp;in, const unsigned x, const unsigned y=1, const unsigned z=2, const unsigned w=3)</strong> – Reorders dimensions of an array</li>\r\n	<li><strong>af_reorder (af_array *out, const af_array in, const unsigned x, const unsigned y, const unsigned z, const unsigned w)</strong> – C interface for reordering function</li>\r\n</ul>\r\n<h2><a id=\"shift_180\"></a>shift()</h2>\r\nThe <strong>shift()</strong> function shifts data in a circular buffer fashion along a chosen dimension.\r\n<pre><code>a [3 5 1 1]\r\n    0.0000     0.0000     0.0000     0.0000     0.0000 \r\n    3.0000     4.0000     5.0000     1.0000     2.0000 \r\n    3.0000     4.0000     5.0000     1.0000     2.0000 \r\n\r\nshift(a, 0, 2 ) [3 5 1 1]\r\n    0.0000     0.0000     0.0000     0.0000     0.0000 \r\n    1.0000     2.0000     3.0000     4.0000     5.0000 \r\n    1.0000     2.0000     3.0000     4.0000     5.0000 \r\n\r\nshift(a, -1, 2 ) [3 5 1 1]\r\n    1.0000     2.0000     3.0000     4.0000     5.0000 \r\n    1.0000     2.0000     3.0000     4.0000     5.0000 \r\n    0.0000     0.0000     0.0000     0.0000     0.0000 \r\n</code></pre>\r\nThe shift function has the following overloads:\r\n<ul>\r\n	<li><strong>array shift (const array &amp;in, const int x, const int y=0, const int z=0, const int w=0)</strong> – Shifts array along specified dimensions</li>\r\n	<li><strong>af_err af_shift (af_array *out, const af_array in, const int x, const int y, const int z, const int w)</strong> – C interface for shifting an array</li>\r\n</ul>\r\n<h2><a id=\"tile_203\"></a>tile()</h2>\r\nThe <strong>tile()</strong> function repeats an array along a dimension\r\n<pre><code>a [3 1 1 1]\r\n    1.0000 \r\n    2.0000 \r\n    3.0000 \r\n\r\ntile(a, 2) [6 1 1 1]\r\n    1.0000 \r\n    2.0000 \r\n    3.0000 \r\n    1.0000 \r\n    2.0000 \r\n    3.0000 \r\n\r\ntile(a, 2, 2) [6 2 1 1]\r\n    1.0000     1.0000 \r\n    2.0000     2.0000 \r\n    3.0000     3.0000 \r\n    1.0000     1.0000 \r\n    2.0000     2.0000 \r\n    3.0000     3.0000 \r\n\r\naf::dim4 tile_dims(1, 2, 3);\r\ntile(a, tile_dims) [3 2 3 1]\r\n    1.0000     1.0000 \r\n    2.0000     2.0000 \r\n    3.0000     3.0000 \r\n\r\n    1.0000     1.0000 \r\n    2.0000     2.0000 \r\n    3.0000     3.0000 \r\n\r\n    1.0000     1.0000 \r\n    2.0000     2.0000 \r\n    3.0000     3.0000</code></pre>\r\nThe tile function has several overloads:\r\n<ul>\r\n	<li><strong>array tile (const array &amp;in, const unsigned x, const unsigned y=1, const unsigned z=1, const unsigned w=1)</strong> – Tiles array along specified dimensions</li>\r\n	<li><strong>array tile (const array &amp;in, const dim4 &amp;dims)</strong> – Tile an array according to a dim4 object</li>\r\n	<li><strong>af_err af_tile (af_array *out, const af_array in, const unsigned x, const unsigned y, const unsigned z, const unsigned w)</strong> – C interface for tiling an array</li>\r\n</ul>\r\n<h2><a id=\"transpose_247\"></a>transpose()</h2>\r\nThe <strong>transpose()</strong> function performs a standard matrix transpose. The input array must have the dimensions of a 2D-matrix.\r\n<pre><code>a [3 3 1 1]\r\n    1.0000     3.0000     3.0000 \r\n    2.0000     1.0000     3.0000 \r\n    2.0000     2.0000     1.0000 \r\n\r\ntranspose(a) [3 3 1 1]\r\n    1.0000     2.0000     2.0000 \r\n    3.0000     1.0000     2.0000 \r\n    3.0000     3.0000     1.0000 </code></pre>\r\nThe transpose function has several overloads:\r\n<ul>\r\n	<li><strong>array transpose (const array &amp;in, const bool conjugate=false)</strong> – Transposes a matrix.</li>\r\n	<li><strong>void transposeInPlace (array &amp;in, const bool conjugate=false)</strong> – Transposes a matrix in-place.</li>\r\n	<li><strong>af_err af_transpose (af_array *out, af_array in, const bool conjugate)</strong> – C interface to transpose a matrix.</li>\r\n	<li><strong>af_err af_transpose_inplace (af_array in, const bool conjugate)</strong> – C interface to transpose a matrix in-place.</li>\r\n</ul>\r\n<h1><a id=\"Combining_reordering_functions_to_enumerate_grid_coordinates_270\"></a>Combining re-ordering functions to enumerate grid coordinates</h1>\r\nBy using a combination of the array restructuring functions, we can quickly code complex manipulation patterns with a few lines of code. For example, consider generating <em>(x,y)</em> coordinates for a grid where each axis goes from <em>1 to n</em>. Instead of using several loops to populate our arrays we can just use a small combination of the above functions.\r\n<pre><code>unsigned n=3;\r\naf::array a = join(1, \r\n                tile(seq(1, n), n), \r\n                flat( transpose(tile(seq(1, n), 1, n)) )\r\n            );\r\na [9 2 1 1]\r\n    1.0000     1.0000 \r\n    2.0000     1.0000 \r\n    3.0000     1.0000 \r\n    1.0000     2.0000 \r\n    2.0000     2.0000 \r\n    3.0000     2.0000 \r\n    1.0000     3.0000 \r\n    2.0000     3.0000 \r\n    3.0000     3.0000 </code></pre>\r\n<h1><a id=\"Conclusion_289\"></a>Conclusion</h1>\r\nFunctions provided by arrayfire offer ease and flexibility for efficiently manipulating the structure of arrays. The provided functions can be used as building blocks to generate, shift, or prepare data to any form imaginable!\r\n\r\n&nbsp;','Manipulating and restructuring arrays','','inherit','open','closed','','8633-revision-v1','','','2015-11-10 19:01:19','2015-11-10 19:01:19','',8633,'http://sandbox.arrayfire.com/8633-revision-v1/',0,'revision','',0),