util/pointer.hpp \
util/range.hpp \
util/tuple.hpp \
+ core/object.hpp \
+ core/error.hpp \
core/compiler.hpp \
core/geometry.hpp \
core/device.hpp \
#ifndef CLOVER_API_UTIL_HPP
#define CLOVER_API_UTIL_HPP
-#include <cstdint>
-#include <cstring>
-#include <algorithm>
-#include <map>
+#include <cassert>
-#include "core/base.hpp"
+#include "core/error.hpp"
#include "core/property.hpp"
#include "util/algorithm.hpp"
-#include "pipe/p_compiler.h"
namespace clover {
///
+++ /dev/null
-//
-// Copyright 2012 Francisco Jerez
-//
-// Permission is hereby granted, free of charge, to any person obtaining a
-// copy of this software and associated documentation files (the "Software"),
-// to deal in the Software without restriction, including without limitation
-// the rights to use, copy, modify, merge, publish, distribute, sublicense,
-// and/or sell copies of the Software, and to permit persons to whom the
-// Software is furnished to do so, subject to the following conditions:
-//
-// The above copyright notice and this permission notice shall be included in
-// all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
-// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
-// OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
-// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-// OTHER DEALINGS IN THE SOFTWARE.
-//
-
-#ifndef CLOVER_CORE_BASE_HPP
-#define CLOVER_CORE_BASE_HPP
-
-#include <stdexcept>
-#include <atomic>
-#include <cassert>
-#include <tuple>
-#include <vector>
-#include <functional>
-
-#include "CL/cl.h"
-#include "util/pointer.hpp"
-
-///
-/// Main namespace of the CL state tracker.
-///
-namespace clover {
- ///
- /// Class that represents an error that can be converted to an
- /// OpenCL status code.
- ///
- class error : public std::runtime_error {
- public:
- error(cl_int code, std::string what = "") :
- std::runtime_error(what), code(code) {
- }
-
- cl_int get() const {
- return code;
- }
-
- protected:
- cl_int code;
- };
-}
-
-#endif
#define CLOVER_CORE_COMPILER_HPP
#include "util/compat.hpp"
+#include "core/error.hpp"
#include "core/module.hpp"
#include "pipe/p_defines.h"
namespace clover {
- class build_error {
- public:
- build_error(const compat::string &log) : log(log) {
- }
-
- virtual ~build_error() {
- }
-
- compat::string what() {
- return log;
- }
-
- private:
- compat::vector<char> log;
- };
-
- class invalid_option_error {
- public:
- invalid_option_error() {
- }
-
- virtual ~invalid_option_error() {
- }
- };
-
module compile_program_llvm(const compat::string &source,
- enum pipe_shader_ir ir,
+ pipe_shader_ir ir,
const compat::string &target,
const compat::string &opts);
#ifndef CLOVER_CORE_CONTEXT_HPP
#define CLOVER_CORE_CONTEXT_HPP
-#include "core/base.hpp"
+#include "core/object.hpp"
#include "core/device.hpp"
namespace clover {
#include <set>
#include <vector>
-#include "core/base.hpp"
+#include "core/object.hpp"
#include "core/format.hpp"
#include "pipe-loader/pipe_loader.h"
--- /dev/null
+//
+// Copyright 2013 Francisco Jerez
+//
+// Permission is hereby granted, free of charge, to any person obtaining a
+// copy of this software and associated documentation files (the "Software"),
+// to deal in the Software without restriction, including without limitation
+// the rights to use, copy, modify, merge, publish, distribute, sublicense,
+// and/or sell copies of the Software, and to permit persons to whom the
+// Software is furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+// OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+// OTHER DEALINGS IN THE SOFTWARE.
+//
+
+#ifndef CLOVER_CORE_ERROR_HPP
+#define CLOVER_CORE_ERROR_HPP
+
+#include "CL/cl.h"
+
+#include "util/compat.hpp"
+
+namespace clover {
+ typedef struct _cl_command_queue command_queue;
+ typedef struct _cl_context context;
+ typedef struct _cl_device_id device;
+ typedef struct _cl_event event;
+ class hard_event;
+ class soft_event;
+ typedef struct _cl_kernel kernel;
+ typedef struct _cl_mem memory_obj;
+ class buffer;
+ class root_buffer;
+ class sub_buffer;
+ class image;
+ class image2d;
+ class image3d;
+ typedef struct _cl_platform_id platform;
+ typedef struct _cl_program program;
+ typedef struct _cl_sampler sampler;
+
+ ///
+ /// Class that represents an error that can be converted to an
+ /// OpenCL status code.
+ ///
+ class error : public compat::runtime_error {
+ public:
+ error(cl_int code, compat::string what = "") :
+ compat::runtime_error(what), code(code) {
+ }
+
+ cl_int get() const {
+ return code;
+ }
+
+ protected:
+ cl_int code;
+ };
+
+ class build_error : public error {
+ public:
+ build_error(const compat::string &log) :
+ error(CL_BUILD_PROGRAM_FAILURE, log) {
+ }
+ };
+
+ template<typename O>
+ class invalid_object_error;
+
+ template<>
+ class invalid_object_error<command_queue> : public error {
+ public:
+ invalid_object_error(std::string what = "") :
+ error(CL_INVALID_COMMAND_QUEUE, what) {}
+ };
+
+ template<>
+ class invalid_object_error<context> : public error {
+ public:
+ invalid_object_error(std::string what = "") :
+ error(CL_INVALID_CONTEXT, what) {}
+ };
+
+ template<>
+ class invalid_object_error<device> : public error {
+ public:
+ invalid_object_error(std::string what = "") :
+ error(CL_INVALID_DEVICE, what) {}
+ };
+
+ template<>
+ class invalid_object_error<event> : public error {
+ public:
+ invalid_object_error(std::string what = "") :
+ error(CL_INVALID_EVENT, what) {}
+ };
+
+ template<>
+ class invalid_object_error<soft_event> : public error {
+ public:
+ invalid_object_error(std::string what = "") :
+ error(CL_INVALID_EVENT, what) {}
+ };
+
+ template<>
+ class invalid_object_error<kernel> : public error {
+ public:
+ invalid_object_error(std::string what = "") :
+ error(CL_INVALID_KERNEL, what) {}
+ };
+
+ template<>
+ class invalid_object_error<memory_obj> : public error {
+ public:
+ invalid_object_error(std::string what = "") :
+ error(CL_INVALID_MEM_OBJECT, what) {}
+ };
+
+ template<>
+ class invalid_object_error<buffer> : public error {
+ public:
+ invalid_object_error(std::string what = "") :
+ error(CL_INVALID_MEM_OBJECT, what) {}
+ };
+
+ template<>
+ class invalid_object_error<root_buffer> : public error {
+ public:
+ invalid_object_error(std::string what = "") :
+ error(CL_INVALID_MEM_OBJECT, what) {}
+ };
+
+ template<>
+ class invalid_object_error<sub_buffer> : public error {
+ public:
+ invalid_object_error(std::string what = "") :
+ error(CL_INVALID_MEM_OBJECT, what) {}
+ };
+
+ template<>
+ class invalid_object_error<image> : public error {
+ public:
+ invalid_object_error(std::string what = "") :
+ error(CL_INVALID_MEM_OBJECT, what) {}
+ };
+
+ template<>
+ class invalid_object_error<image2d> : public error {
+ public:
+ invalid_object_error(std::string what = "") :
+ error(CL_INVALID_MEM_OBJECT, what) {}
+ };
+
+ template<>
+ class invalid_object_error<image3d> : public error {
+ public:
+ invalid_object_error(std::string what = "") :
+ error(CL_INVALID_MEM_OBJECT, what) {}
+ };
+
+ template<>
+ class invalid_object_error<platform> : public error {
+ public:
+ invalid_object_error(std::string what = "") :
+ error(CL_INVALID_PLATFORM, what) {}
+ };
+
+ template<>
+ class invalid_object_error<program> : public error {
+ public:
+ invalid_object_error(std::string what = "") :
+ error(CL_INVALID_PROGRAM, what) {}
+ };
+
+ template<>
+ class invalid_object_error<sampler> : public error {
+ public:
+ invalid_object_error(std::string what = "") :
+ error(CL_INVALID_SAMPLER, what) {}
+ };
+
+ class invalid_wait_list_error : public error {
+ public:
+ invalid_wait_list_error(std::string what = "") :
+ error(CL_INVALID_EVENT_WAIT_LIST, what) {}
+ };
+}
+
+#endif
#include <functional>
-#include "core/base.hpp"
+#include "core/object.hpp"
#include "core/queue.hpp"
#include "core/timestamp.hpp"
#include "util/lazy.hpp"
#include <set>
-#include "core/base.hpp"
+#include "core/object.hpp"
#include "pipe/p_defines.h"
#include "pipe/p_format.h"
#include <memory>
-#include "core/base.hpp"
+#include "core/object.hpp"
#include "core/program.hpp"
#include "core/memory.hpp"
#include "core/sampler.hpp"
#include <map>
#include <memory>
-#include "core/base.hpp"
+#include "core/object.hpp"
#include "core/queue.hpp"
namespace clover {
--- /dev/null
+//
+// Copyright 2013 Francisco Jerez
+//
+// Permission is hereby granted, free of charge, to any person obtaining a
+// copy of this software and associated documentation files (the "Software"),
+// to deal in the Software without restriction, including without limitation
+// the rights to use, copy, modify, merge, publish, distribute, sublicense,
+// and/or sell copies of the Software, and to permit persons to whom the
+// Software is furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+// OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+// OTHER DEALINGS IN THE SOFTWARE.
+//
+
+#ifndef CLOVER_CORE_OBJECT_HPP
+#define CLOVER_CORE_OBJECT_HPP
+
+#include <cassert>
+#include <functional>
+#include <vector>
+
+#include "CL/cl.h"
+
+#include "core/error.hpp"
+#include "core/property.hpp"
+
+///
+/// Main namespace of the CL state tracker.
+///
+namespace clover {
+ ///
+ /// Class that represents a CL API object.
+ ///
+ template<typename T, typename S>
+ struct descriptor {
+ typedef T object_type;
+ typedef S descriptor_type;
+ };
+
+ struct default_tag;
+ struct wait_list_tag;
+ struct property_list_tag;
+
+ namespace detail {
+ template<typename T, typename D>
+ struct descriptor_traits {
+ typedef T object_type;
+
+ static void
+ validate(D *d) {
+ auto o = static_cast<typename D::object_type *>(d);
+ if (!o || !dynamic_cast<object_type *>(o))
+ throw invalid_object_error<T>();
+ }
+
+ static void
+ validate_list(D * const *ds, size_t n) {
+ if (!ds || !n)
+ throw error(CL_INVALID_VALUE);
+ }
+ };
+
+ template<typename D>
+ struct descriptor_traits<default_tag, D> {
+ typedef typename D::object_type object_type;
+
+ static void
+ validate(D *d) {
+ if (!d)
+ throw invalid_object_error<object_type>();
+ }
+
+ static void
+ validate_list(D *const *ds, size_t n) {
+ if (!ds || !n)
+ throw error(CL_INVALID_VALUE);
+ }
+ };
+
+ template<typename D>
+ struct descriptor_traits<wait_list_tag, D> {
+ typedef typename D::object_type object_type;
+
+ static void
+ validate(D *d) {
+ if (!d)
+ throw invalid_wait_list_error();
+ }
+
+ static void
+ validate_list(D *const *ds, size_t n) {
+ if (bool(ds) != bool(n))
+ throw invalid_wait_list_error();
+ }
+ };
+ }
+
+ ///
+ /// Get a Clover object from an API object.
+ ///
+ /// \a T can either be the Clover object type to return or a \a tag
+ /// object to select some special validation behavior by means of a
+ /// specialization of the detail::descriptor_traits template. The
+ /// default behavior is to infer the most general Clover object
+ /// type for the given API object.
+ ///
+ template<typename T = default_tag, typename D>
+ typename detail::descriptor_traits<T, D>::object_type &
+ obj(D *d) {
+ detail::descriptor_traits<T, D>::validate(d);
+
+ return static_cast<
+ typename detail::descriptor_traits<T, D>::object_type &>(*d);
+ }
+
+ ///
+ /// Get a pointer to a Clover object from an API object. Returns
+ /// \c NULL if its argument is \c NULL.
+ ///
+ /// \sa obj
+ ///
+ template<typename T = default_tag, typename D>
+ typename detail::descriptor_traits<T, D>::object_type *
+ pobj(D *d) {
+ if (d)
+ detail::descriptor_traits<T, D>::validate(d);
+
+ return static_cast<
+ typename detail::descriptor_traits<T, D>::object_type *>(d);
+ }
+
+ ///
+ /// Get an API object from a Clover object.
+ ///
+ template<typename O>
+ typename O::descriptor_type *
+ desc(O &o) {
+ return static_cast<typename O::descriptor_type *>(&o);
+ }
+
+ ///
+ /// Get an API object from a pointer to a Clover object.
+ ///
+ template<typename O>
+ typename O::descriptor_type *
+ desc(O *o) {
+ return static_cast<typename O::descriptor_type *>(o);
+ }
+
+ ///
+ /// Get a range of Clover objects from a range of API objects.
+ ///
+ /// \sa obj
+ ///
+ template<typename T = default_tag, typename D>
+ ref_vector<typename detail::descriptor_traits<T, D>::object_type>
+ objs(D *const *ds, size_t n) {
+ detail::descriptor_traits<T, D>::validate_list(ds, n);
+ return map(obj<T, D>, range(ds, n));
+ }
+
+ ///
+ /// Get a range of API objects from a range of Clover objects.
+ ///
+ template<typename Os>
+ std::vector<typename Os::value_type::descriptor_type *>
+ descs(const Os &os) {
+ return map([](typename Os::value_type &o) {
+ return desc(o);
+ }, os);
+ }
+}
+
+#endif
#include <vector>
-#include "core/base.hpp"
+#include "core/object.hpp"
#include "core/device.hpp"
namespace clover {
} catch (build_error &e) {
_logs.insert({ dev, e.what() });
- throw error(CL_BUILD_PROGRAM_FAILURE);
- } catch (invalid_option_error &e) {
- throw error(CL_INVALID_BUILD_OPTIONS);
+ throw;
}
}
}
#include <map>
-#include "core/base.hpp"
+#include "core/object.hpp"
#include "core/context.hpp"
#include "core/module.hpp"
#ifndef CLOVER_CORE_QUEUE_HPP
#define CLOVER_CORE_QUEUE_HPP
-#include "core/base.hpp"
+#include "core/object.hpp"
#include "core/context.hpp"
#include "core/timestamp.hpp"
#include "pipe/p_context.h"
#include <list>
-#include "core/base.hpp"
+#include "core/object.hpp"
#include "core/memory.hpp"
#include "util/algebra.hpp"
#include "pipe/p_state.h"
#ifndef CLOVER_CORE_SAMPLER_HPP
#define CLOVER_CORE_SAMPLER_HPP
-#include "core/base.hpp"
+#include "core/object.hpp"
#include "core/queue.hpp"
namespace clover {
#ifndef CLOVER_CORE_TIMESTAMP_HPP
#define CLOVER_CORE_TIMESTAMP_HPP
-#include "core/base.hpp"
+#include "core/object.hpp"
struct pipe_query;
opts_carray.data() + opts_carray.size(),
Diags);
if (!Success) {
- throw invalid_option_error();
+ throw error(CL_INVALID_BUILD_OPTIONS);
}
c.getFrontendOpts().ProgramAction = clang::frontend::EmitLLVMOnly;
c.getHeaderSearchOpts().UseBuiltinIncludes = true;