1bf215546Sopenharmony_ci// 2bf215546Sopenharmony_ci// Copyright 2012 Francisco Jerez 3bf215546Sopenharmony_ci// 4bf215546Sopenharmony_ci// Permission is hereby granted, free of charge, to any person obtaining a 5bf215546Sopenharmony_ci// copy of this software and associated documentation files (the "Software"), 6bf215546Sopenharmony_ci// to deal in the Software without restriction, including without limitation 7bf215546Sopenharmony_ci// the rights to use, copy, modify, merge, publish, distribute, sublicense, 8bf215546Sopenharmony_ci// and/or sell copies of the Software, and to permit persons to whom the 9bf215546Sopenharmony_ci// Software is furnished to do so, subject to the following conditions: 10bf215546Sopenharmony_ci// 11bf215546Sopenharmony_ci// The above copyright notice and this permission notice shall be included in 12bf215546Sopenharmony_ci// all copies or substantial portions of the Software. 13bf215546Sopenharmony_ci// 14bf215546Sopenharmony_ci// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15bf215546Sopenharmony_ci// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16bf215546Sopenharmony_ci// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17bf215546Sopenharmony_ci// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 18bf215546Sopenharmony_ci// OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 19bf215546Sopenharmony_ci// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 20bf215546Sopenharmony_ci// OTHER DEALINGS IN THE SOFTWARE. 21bf215546Sopenharmony_ci// 22bf215546Sopenharmony_ci 23bf215546Sopenharmony_ci#ifndef CLOVER_API_UTIL_HPP 24bf215546Sopenharmony_ci#define CLOVER_API_UTIL_HPP 25bf215546Sopenharmony_ci 26bf215546Sopenharmony_ci#include <cassert> 27bf215546Sopenharmony_ci#include <iostream> 28bf215546Sopenharmony_ci 29bf215546Sopenharmony_ci#include "core/error.hpp" 30bf215546Sopenharmony_ci#include "core/property.hpp" 31bf215546Sopenharmony_ci#include "util/algorithm.hpp" 32bf215546Sopenharmony_ci#include "util/detect_os.h" 33bf215546Sopenharmony_ci 34bf215546Sopenharmony_ci#if DETECT_OS_WINDOWS 35bf215546Sopenharmony_ci#define CLOVER_API 36bf215546Sopenharmony_ci#define CLOVER_ICD_API 37bf215546Sopenharmony_ci#elif HAVE_CLOVER_ICD 38bf215546Sopenharmony_ci#define CLOVER_API 39bf215546Sopenharmony_ci#define CLOVER_ICD_API PUBLIC 40bf215546Sopenharmony_ci#else 41bf215546Sopenharmony_ci#define CLOVER_API PUBLIC 42bf215546Sopenharmony_ci#define CLOVER_ICD_API PUBLIC 43bf215546Sopenharmony_ci#endif 44bf215546Sopenharmony_ci 45bf215546Sopenharmony_ci#define CLOVER_NOT_SUPPORTED_UNTIL(version) \ 46bf215546Sopenharmony_ci do { \ 47bf215546Sopenharmony_ci std::cerr << "CL user error: " << __func__ \ 48bf215546Sopenharmony_ci << "() requires OpenCL version " << (version) \ 49bf215546Sopenharmony_ci << " or greater." << std::endl; \ 50bf215546Sopenharmony_ci } while (0) 51bf215546Sopenharmony_ci 52bf215546Sopenharmony_cinamespace clover { 53bf215546Sopenharmony_ci /// 54bf215546Sopenharmony_ci /// Return an error code in \a p if non-zero. 55bf215546Sopenharmony_ci /// 56bf215546Sopenharmony_ci inline void 57bf215546Sopenharmony_ci ret_error(cl_int *p, const clover::error &e) { 58bf215546Sopenharmony_ci if (p) 59bf215546Sopenharmony_ci *p = e.get(); 60bf215546Sopenharmony_ci } 61bf215546Sopenharmony_ci 62bf215546Sopenharmony_ci /// 63bf215546Sopenharmony_ci /// Return a clover object in \a p if non-zero incrementing the 64bf215546Sopenharmony_ci /// reference count of the object. 65bf215546Sopenharmony_ci /// 66bf215546Sopenharmony_ci template<typename T> 67bf215546Sopenharmony_ci void 68bf215546Sopenharmony_ci ret_object(typename T::descriptor_type **p, 69bf215546Sopenharmony_ci const intrusive_ref<T> &v) { 70bf215546Sopenharmony_ci if (p) { 71bf215546Sopenharmony_ci v().retain(); 72bf215546Sopenharmony_ci *p = desc(v()); 73bf215546Sopenharmony_ci } 74bf215546Sopenharmony_ci } 75bf215546Sopenharmony_ci 76bf215546Sopenharmony_ci /// 77bf215546Sopenharmony_ci /// Return an API object from an intrusive reference to a Clover object, 78bf215546Sopenharmony_ci /// incrementing the reference count of the object. 79bf215546Sopenharmony_ci /// 80bf215546Sopenharmony_ci template<typename T> 81bf215546Sopenharmony_ci typename T::descriptor_type * 82bf215546Sopenharmony_ci ret_object(const intrusive_ref<T> &v) { 83bf215546Sopenharmony_ci v().retain(); 84bf215546Sopenharmony_ci return desc(v()); 85bf215546Sopenharmony_ci } 86bf215546Sopenharmony_ci} 87bf215546Sopenharmony_ci 88bf215546Sopenharmony_ci#endif 89