Showing posts with label OpenCV. Show all posts
Showing posts with label OpenCV. Show all posts

Monday, November 18, 2013

AMD OpenCL installation

This was a "retake" as I had gone through the process before. But since both OpenCL and OpenCV have updates, and I had not taken such good notes the first time around, I am re-installing everything. For this toolset, that is not a task to be taken lightly.

The official name is the AMD Accelerated Parallel Processing (APP) SDK

What is AMD APP Technology? From the above URL:

"AMD APP technology is a set of advanced hardware and software technologies that enable AMD graphics processing cores (GPU), working in concert with the system’s x86 cores (CPU), to execute heterogeneously to accelerate many applications beyond just graphics. This enables better balanced platforms capable of running demanding computing tasks faster than ever, and sets software developers on the path to optimize for AMD Accelerated Processing Units (APUs)."

Without OpenCL installed, I am not going to be taking advantage of the GPU, and the whole reason I'm down this rabbit hole is to have OpenCV work well (measured in high frame rates).

As I had mentioned, I had already previously installed:

  1. The AMD FirePro Unified Driver (V5900 graphics driver)
  2. AMD APP
  3. OpenCV

I was very hesitant to fiddle with the installed and working graphics driver, so I choose to uninstalled AMD APP v2.8. I found no uninstaller in Windows Programs and Features but in Googling I found that the uninstall is managed by the "AMD Catalyst Install Manager" which is listed in Programs and Features. While uninstalling AMD APP, I also uninstalled a couple other AMD features I was not using.

The AMD APP V2.9 installer was downloaded and executed. I specified an alternate install path and no other options were presented. I installed to

e:\amd_app_2_9

The next step was to compile it. Rather than rehash here my frustrations with that, I refer the audience to the thread that I started at the AMD Developer Central forum. A synopsis is as follows.

  1. The AMD documentation is very helpful but there are some inaccuracies.
  2. I did end up having to install the latest AMD Unified Driver. I just installed over top of the existing and had no issues.
  3. After the driver update and compilation of OpenCL, I was able to successfully run the OpenCL samples.

The coolest OpenCL demo that I ran was the FluidSimulation2D. Mandelbrot was also rewarding. I can tell these demos are using the V5900 because I can hear the fan spin up. When time allows, I will experiment with more of the sample, peruse some source, and perhaps even learn a bit of OpenCL. But my main task is to learn OpenCV so the next installment in this series will pertain to getting that installed and operating.

An important note from Dr. Harris Gasparakis' blog at http://developer.amd.com/community/blog/2013/11/05/opencv-cl-computer-vision-with-even-more-opencl-acceleration/

With the view towards the future, and OpenCL 2.0 in particular, there is a significant and ground breaking development! About a year ago, we asked the question: Is it possible run the same code on both CPUs and GPUs, and have the OpenCV runtime libraries determine if OpenCL capable devices are present, and use hardware acceleration if they are? By that I do not mean running OpenCL on CPU vs. running OpenCL on GPU – that already works. What I mean is run a native C++ implementation on CPU vs. an OpenCL implementation on the GPU, if, at runtime, it is determined that the system supports OpenCL.

It is not clear to me if OpenCV 2.4.7 is already doing some of this. But I do know that the binding of OpenCV and OpenCL is different in 2.4.7. This is a question that I will be investigating during my installation and testing of OpenCV.

Sunday, November 17, 2013

Hardware preparation for OpenCV development

Why I added a graphics card

My computer was working just fine, thank you. The Intel i5-2500K contains Intel HD 3000 integrated graphics processor. It drives my dual HD monitors just fine. The The reason that I added a graphics card was to get a GPGPU (general purpose graphics processing unit). A GPU provides a great speed-boost to any math-intenstive processing because all those graphics cores can be brought to bear on any calculations which can be performed in parallel.

Some background

OpenCV supports two differnet GPU-based acceleration schemes. GPU match accelerators are usually proprietary and are developed and provided by the hardware manufacturer. I assume that the reason for their being closed is that the vendors have trade secrets related to the specialized GPU hardware and accompanying software. Even getting the vendor's GPU libraries often involves signing an NDA. The two schemes are OpenCL and CUDA.

OpenCL was initially developed by Apple who still owns the trademark but the technology was submitted to the Khronos Group who is now responsible for publishing the technical standards. The current standard is OpenCL 2.0 but most implementations are still at OpenCL 1.X.

CUDA is a parallel computing platform and programming model invented by NVIDIA who both owns the trademark and develops and distributes the libraries. CUDA works with all Nvidia GPUs from the G8x series onwards, as well as the Tegra system on a chip (SoC) series.

OpenCV supports both OpenCL and CUDA for GPU-based acceleration. I've chosen to go the OpenCV route as there is a much wider choice of supported hardware. This is not in any way a disparagement of CUDA, which is a very strong technology back by a very strong company. Anyone starting an OpenCV project should evaluate both OpenCL and CUDA at project initiation, and look at the available processors and boards. I had considered using an Nvidia Shield as an OpenCV development platform. It has a Tegra 4 chip and an available CUDA SDK. But I am trying to be risk-adverse and I could not find anyone else who has attempted to compile and run OpenCV on a Shield.

The FirePro V5900

After evaluating my options, I settled on an AMD FirePro V5900. AMD provides an OpenCL compliant driver and SDK. While no stellar performer, the V5900 is reasonable priced. New the are less that $400. I picked up a used on eBay for less than $200. A good place to compare OpenCL performance is CompuBench. For example here are the results of their "Optical Flow" test. I had to "expand all" before getting the V5900 to show up on the results. And while you are there, check out how well the Intel HD 4000 performs.

My desire was to run the V5900 "headless" and to continue using the integrated graphics for my monitors and thus dedicate the GPU to OpenCL processing. But alas when I plugged in the card my motherboard's firmware automagically made the V5900 become the graphics device. Perhaps with more research and experiments I may have been able to achieve the desired configuration. But who know how much time investment that would have been. A side benefit of having the V5900 drive the display is that Google Earth runs much better and I can also run Outerra Anteworld (the V5900 just meets the minimal hardware requirements).

Installing a GPU is something that I hadn't done for many years. I was shocked by the size of the AMD Catalyst download size. There is a great deal of bloatware which gets installed. One can uninstall specific items and I probably could have avoided installing them in the first place. Generally I am hesitant to uninstall things if my computer is in working order and I haven't run low on disk space.

In my next entry I will describe installing the AMD Accelerated Parallel Processing (APP) SDK. As an aside, this was my first posting created with Emacs, Markdown, and Pandoc.

Beginning my Apprenticeship in Machine Vision

Back in 1987 while an undergrad at CMU, I had an interest in machine vision. I read (and still have) David Marr's book "Vision". That was a period when neural networks were fashionable, and machine vision was a common research topic for neural network researchers. Fast-forward 26 years and I find myself the parent of a FIRST robotics participant (CMU-based Girls of Steel (GoS) Robotics). I wish to be in a position to assist the team with the robot vision aspect of the project, and was told to get acquainted with OpenCV .

"Adopted all around the world, OpenCV has more than 47 thousand people of user community and estimated number of downloads exceeding 7 million. Usage ranges from interactive art, to mines inspection, stitching maps on the web or through advanced robotics."

The GoS robot needs to perform a task which is assigned at the begging of the season. The last few year's tasks have had sports themes. Last year was Frisbee golf. I expect that this year will also be sports-based. Perhaps hockey? Anyway, the robot needs to know where it is on the field. There are placed on the field several vision targets in the form of circles or rectangles made out of reflective tape. By tracking and triangulating these targets, the robot should be able to determine its position and orientation on the field.

My vision (excuse the pun) is that a small, low-power single-board computer would act as the "vision brain" for the robot, and would send world position data to the main computer (a National Instruments CompactRIO). Actually the cRIO would "pull" the information from a web server running on the vision board. The market for small, low-cost computer boards has exploded in the last few years. The dominant board right now is the Raspberry Pi which costs only $35. I use one of those as my Home Theater PC (HTPC). The Pi is underpowerered for machine vision work, and the proprietary nature of the on-board GPU really cripples the device. After speaking with the lead technical mentor (a robotics scientist at CMU) I decided to purchase an ODROID-XU. This board is about five times more powerful than a Pi, and has a GPU which can easily handle machine vision. The board is only $169 and has an Exynos5 CPU and a PowerVR SGX544MP3 GPU. They also sell a USB-CAM for $15.

The PowerVM is a product of Imagination Technologies, and they have committed to providing OpenCL drivers so that OpenCV can take advantage of this board. Unfortunately they have not yet released the Linux drivers. They were supposed to be out by mid-November but I and a lot of other early-adopters are anxiously waiting. I just checked again and see there is no news. The fact that there is only one guy working on it and that he is also busy with other projects does not give me a great deal of confidence in having something in time for the next FIRST season.

Rather than idly wait, I decided to get started with OpenCV programming on my desktop computer. This computer has a 2nd generation Intel Core 5-series. It is not really strong in terms of GPU. I don't think Intel's flavor of OpenCL even supports it. My solution was to purchase a used Firepro V5900 on ebay. The new card bumped my Windows Index score on to 7.3 from 5.x. The card has good support for AMD's OpenCL drivers. AMD has a very well-written guide to setting up OpenCV which I have followed successfully. After compiling and running some of the OpenCV GPU samples, I now have some confidence in the tools and techniques.

The next steps in this project will take place on my PC. They include:

  • Doing an update to OpenCV 2.4.7
  • Learning how to do camera calibration
  • Exploring different options for object location
  • (re)Learning the matrix math to perform world to camera transformations

Obviously my PC isn't going on the robot, so a "small computer" solution is needed. I still think the most promising is that the ODROID gets OpenCL. Another inexpensive option is a Samsung Chromebook. They use a Mali GPU which, if my forum interpretations are correct, already has OpenCL drivers. Yet another option is the new Intel NUC which is Haswell-based and has what is perhaps the best OpenCL drivers – from Intel I believe.

Look here for regular updates on this project. Some posts may be by Heather to her own blog but I will reference those here also.

As an aside, this post was made from Word using the blog publishing feature. Since I had to do a lot of post-publish cleanup, I have my doubts about using that approach in the future. Markdown authoring integration is still my plan.