GpuIntegralImage.cppGo to the documentation of this file.00001 /* 00002 Copyright (c) 2010, Paul Furgale and Chi Hay Tong 00003 All rights reserved. 00004 00005 Redistribution and use in source and binary forms, with or without 00006 modification, are permitted provided that the following conditions are 00007 met: 00008 00009 * Redistributions of source code must retain the above copyright notice, 00010 this list of conditions and the following disclaimer. 00011 * Redistributions in binary form must reproduce the above copyright 00012 notice, this list of conditions and the following disclaimer in the 00013 documentation and/or other materials provided with the distribution. 00014 * The names of its contributors may not be used to endorse or promote 00015 products derived from this software without specific prior written 00016 permission. 00017 00018 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 00019 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 00020 TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 00021 PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER 00022 OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 00023 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 00024 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 00025 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 00026 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 00027 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00028 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00029 */ 00030 00031 #include "GpuIntegralImage.hpp" 00032 #include <cuda.h> 00033 #include <builtin_types.h> 00034 #include <channel_descriptor.h> 00035 #include "assert_macros.hpp" 00036 00037 namespace asrl { 00038 00039 GpuIntegralImage::GpuIntegralImage(int width, int height) : m_width(width), m_height(height) 00040 { 00041 // allocate gpu cudaArray 00042 cudaChannelFormatDesc desc = cudaCreateChannelDesc<float>(); 00043 cudaArray * carr; 00044 cudaError_t err = cudaMallocArray(&carr, &desc, width, height); 00045 ASRL_ASSERT_EQ(err,cudaSuccess, "Unable to allocate CUDA array integral image. output: " << cudaGetErrorString(err)); 00046 m_cudaArray.reset(carr,&cudaFreeArray); 00047 } 00048 00049 GpuIntegralImage::~GpuIntegralImage() 00050 { 00051 // The smart pointer should clean up after itself. 00052 } 00053 00054 cudaArray * GpuIntegralImage::d_get() 00055 { 00056 return m_cudaArray.get(); 00057 } 00058 00059 int GpuIntegralImage::width() 00060 { 00061 return m_width; 00062 } 00063 00064 int GpuIntegralImage::height() 00065 { 00066 return m_height; 00067 } 00068 00069 float * GpuIntegralImage::h_get() 00070 { 00071 // Allocate the buffer if necessary. 00072 if(m_buffer.size() == 0) 00073 { 00074 m_buffer.init(width() * height()); 00075 } 00076 00077 // Download the integral image. 00078 cudaError_t err = cudaMemcpyFromArray (m_buffer.d_get(), m_cudaArray.get(), 0, 0, width()*height()*sizeof(float), cudaMemcpyDeviceToDevice); 00079 ASRL_ASSERT_EQ(err,cudaSuccess, "Unable to retrieve the integral image from the device. output: " << cudaGetErrorString(err)); 00080 m_buffer.pullFromDevice(); 00081 return m_buffer.h_get(); 00082 00083 } 00084 00085 } // namespace asrl Generated on Fri Apr 30 20:06:19 2010 for gpusurf by 1.6.2 |