/********************************************************************** Copyright ©2012 Advanced Micro Devices, Inc. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: • Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. • Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ********************************************************************/ #ifndef HISTOGRAM_H_ #define HISTOGRAM_H_ #include #include #include #include #include #include #include #include #include #define NBINS 256 #define BITS_PER_PIX 8 /** * Histogram * Class implements 256 Histogram bin implementation * Derived from SDKSample base class */ class Histogram : public SDKSample { cl_uint inputNBytes; cl_uint outputNBytes; cl_uint nLoops; cl_uint nThreads; cl_uint nThreadsPerGroup; cl_uint nGroups; cl_uint n4Vectors; cl_uint n4VectorsPerThread; cl_uint nBins; cl_uint nBytesLDSPerGrp; cl_uint *input; cl_uint *output; cl_mem inputBuffer; cl_mem outputBuffer; cl_uint cpuhist[NBINS]; cl_context context; cl_device_id *devices; cl_command_queue commandQueue; cl_program program; cl_kernel histogram; cl_kernel reduce; cl_double setupTime; /**< time taken to setup OpenCL resources and building kernel */ cl_double kernelTimeGlobal; /**< time taken to run kernel and read result back */ cl_double kernelTimeLocal; /**< time taken to run kernel and read result back */ cl_ulong totalLocalMemory; /**< Max local memory allowed */ cl_ulong usedLocalMemory; /**< Used local memory by kernel */ int iterations; /**< Number of iterations for kernel execution */ cl_bool reqdExtSupport; size_t KernelCompileWorkGroupSize[3]; streamsdk::SDKDeviceInfo deviceInfo; /**< Structure to store device information*/ streamsdk::KernelWorkGroupInfo kernelInfoReduce,kernelInfoHistogram; /**< Structure to store kernel related info */ public: /** * Constructor * Initialize member variables * @param name name of sample (string) */ Histogram(std::string name) : SDKSample(name), setupTime(0), kernelTimeGlobal(0), kernelTimeLocal(0), input(NULL), output(NULL), devices(NULL), reqdExtSupport(true), iterations(1) { } /** * Constructor * Initialize member variables * @param name name of sample (const char*) */ Histogram(const char* name) : SDKSample(name), setupTime(0), kernelTimeGlobal(0), kernelTimeLocal(0), input(NULL), output(NULL), devices(NULL), reqdExtSupport(true), iterations(1) { } ~Histogram() { FREE(input); FREE(output); FREE(devices); } /** * Allocate and initialize required host memory with appropriate values * @return SDK_SUCCESS on success and SDK_FAILURE on failure */ int setupHistogram(); /** * Override from SDKSample, Generate binary image of given kernel * and exit application * @return SDK_SUCCESS on success and SDK_FAILURE on failure */ int genBinaryImage(); /** * OpenCL related initializations. * Set up Context, Device list, Command Queue, Memory buffers * Build CL kernel program executable * @return SDK_SUCCESS on success and SDK_FAILURE on failure */ int setupCL(); /** * Set values for kernels' arguments, enqueue calls to the kernels * on to the command queue, wait till end of kernel execution. * Get kernel start and end time if timing is enabled * @return SDK_SUCCESS on success and SDK_FAILURE on failure */ int runCLKernels(); /** * Override from SDKSample. Print sample stats. */ void printStats(); /** * Override from SDKSample. Initialize * command line parser, add custom options * @return SDK_SUCCESS on success and SDK_FAILURE on failure */ int initialize(); /** * Override from SDKSample, adjust width and height * of execution domain, perform all sample setup * @return SDK_SUCCESS on success and SDK_FAILURE on failure */ int setup(); /** * Override from SDKSample * Run OpenCL Black-Scholes * @return SDK_SUCCESS on success and SDK_FAILURE on failure */ int run(); /** * Override from SDKSample * Cleanup memory allocations * @return SDK_SUCCESS on success and SDK_FAILURE on failure */ int cleanup(); /** * Override from SDKSample * Verify against reference implementation * @return SDK_SUCCESS on success and SDK_FAILURE on failure */ int verifyResults(); private: /** * Calculate histogram bin on host */ void calculateHostBin(); }; #endif