/* * Copyright (c) Advanced Micro Devices, Inc., or its affiliates. * * SPDX-License-Identifier: MIT */ #ifndef VDI_COMMON_HPP_ #define VDI_COMMON_HPP_ #include "top.hpp" #include "platform/runtime.hpp" #include "platform/command.hpp" #include "platform/memory.hpp" #include "thread/thread.hpp" #include "platform/commandqueue.hpp" #include #include namespace device = amd::device; //! \cond ignore namespace amd { template class NotNullWrapper { private: T* const ptrOrNull_; protected: explicit NotNullWrapper(T* ptrOrNull) : ptrOrNull_(ptrOrNull) {} public: void operator=(T value) const { if (ptrOrNull_ != NULL) { *ptrOrNull_ = value; } } }; template class NotNullReference : protected NotNullWrapper { public: explicit NotNullReference(T* ptrOrNull) : NotNullWrapper(ptrOrNull) {} const NotNullWrapper& operator*() const { return *this; } }; } // namespace amd template inline amd::NotNullReference not_null(T* ptrOrNull) { return amd::NotNullReference(ptrOrNull); } #define RUNTIME_ENTRY_RET(ret, func, args) CL_API_ENTRY ret CL_API_CALL func args { #define RUNTIME_ENTRY_RET_NOERRCODE(ret, func, args) CL_API_ENTRY ret CL_API_CALL func args { #define RUNTIME_ENTRY(ret, func, args) CL_API_ENTRY ret CL_API_CALL func args { #define RUNTIME_ENTRY_VOID(ret, func, args) CL_API_ENTRY ret CL_API_CALL func args { #define RUNTIME_EXIT \ /* FIXME_lmoriche: we should check to thread->lastError here! */ \ } namespace amd { namespace detail { template struct ParamInfo { static inline std::pair get(const T& param) { return std::pair(¶m, sizeof(T)); } }; template <> struct ParamInfo { static inline std::pair get(const char* param) { return std::pair(param, strlen(param) + 1); } }; template struct ParamInfo { static inline std::pair get(const char* param) { return std::pair(param, strlen(param) + 1); } }; } // namespace detail struct PlatformIDS { const cl_icd_dispatch* dispatch_; }; class PlatformID { public: static inline PlatformIDS Platform = {amd::ICDDispatchedObject::icdVendorDispatch_}; }; #define AMD_PLATFORM (reinterpret_cast(&amd::PlatformID::Platform)) } // namespace amd #endif /* _VDI_COMMON_H */