29dd0eb7a2
SWDEV-219917 - [VDI Cleanup] Remove some direct OpenCL references, introduce a common functionality. ReviewBoardURL = http://ocltc.amd.com/reviews/r/18488/diff/ Affected files ... ... //depot/stg/opencl/drivers/opencl/api/hip/build/Makefile.hip#30 edit ... //depot/stg/opencl/drivers/opencl/api/hip/fixme.cpp#3 edit ... //depot/stg/opencl/drivers/opencl/api/hip/hip_internal.hpp#51 edit ... //depot/stg/opencl/drivers/opencl/api/hip/hiprtc_internal.hpp#3 edit ... //depot/stg/opencl/drivers/opencl/api/opencl/amdocl/build/Makefile.api#190 edit ... //depot/stg/opencl/drivers/opencl/api/opencl/amdocl/cl_common.hpp#25 edit ... //depot/stg/opencl/drivers/opencl/api/opencl/amdocl/cl_context.cpp#61 edit ... //depot/stg/opencl/drivers/opencl/api/opencl/amdocl/cl_device.cpp#75 edit ... //depot/stg/opencl/drivers/opencl/api/opencl/amdocl/cl_execute.cpp#31 edit ... //depot/stg/opencl/drivers/opencl/api/opencl/amdocl/cl_icd.cpp#36 edit ... //depot/stg/opencl/drivers/opencl/api/opencl/amdocl/cl_platform_amd.cpp#3 edit ... //depot/stg/opencl/drivers/opencl/api/opencl/amdocl/cl_program.cpp#54 edit ... //depot/stg/opencl/drivers/opencl/runtime/device/gpu/gpudevice.cpp#610 edit ... //depot/stg/opencl/drivers/opencl/runtime/device/pal/paldevice.cpp#180 edit ... //depot/stg/opencl/drivers/opencl/runtime/device/rocm/rocdevice.cpp#150 edit ... //depot/stg/opencl/drivers/opencl/runtime/include/vdi_agent_amd.h#1 add ... //depot/stg/opencl/drivers/opencl/runtime/include/vdi_common.hpp#1 add ... //depot/stg/opencl/drivers/opencl/runtime/os/os.hpp#32 edit ... //depot/stg/opencl/drivers/opencl/runtime/os/os_posix.cpp#49 edit ... //depot/stg/opencl/drivers/opencl/runtime/os/os_win32.cpp#50 edit ... //depot/stg/opencl/drivers/opencl/runtime/platform/agent.cpp#9 edit ... //depot/stg/opencl/drivers/opencl/runtime/platform/agent.hpp#7 edit ... //depot/stg/opencl/drivers/opencl/runtime/platform/context.cpp#54 edit ... //depot/stg/opencl/drivers/opencl/runtime/runtimedefs#54 edit
164 wiersze
5.6 KiB
C++
164 wiersze
5.6 KiB
C++
/*
|
|
Copyright (c) 2020 - present Advanced Micro Devices, Inc. All rights reserved.
|
|
|
|
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 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 <vector>
|
|
#include <utility>
|
|
|
|
//! \cond ignore
|
|
namespace amd {
|
|
|
|
template <typename T>
|
|
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 <typename T>
|
|
class NotNullReference : protected NotNullWrapper<T>
|
|
{
|
|
public:
|
|
explicit NotNullReference(T* ptrOrNull)
|
|
: NotNullWrapper<T>(ptrOrNull)
|
|
{ }
|
|
|
|
const NotNullWrapper<T>& operator * () const { return *this; }
|
|
};
|
|
|
|
} // namespace amd
|
|
|
|
template <typename T>
|
|
inline amd::NotNullReference<T>
|
|
not_null(T* ptrOrNull)
|
|
{
|
|
return amd::NotNullReference<T>(ptrOrNull);
|
|
}
|
|
|
|
#define VDI_CHECK_THREAD(thread) \
|
|
(thread != NULL || ((thread = new amd::HostThread()) != NULL \
|
|
&& thread == amd::Thread::current()))
|
|
|
|
#define RUNTIME_ENTRY_RET(ret, func, args) \
|
|
CL_API_ENTRY ret CL_API_CALL \
|
|
func args \
|
|
{ \
|
|
amd::Thread* thread = amd::Thread::current(); \
|
|
if (!VDI_CHECK_THREAD(thread)) { \
|
|
*not_null(errcode_ret) = CL_OUT_OF_HOST_MEMORY; \
|
|
return (ret) 0; \
|
|
}
|
|
|
|
#define RUNTIME_ENTRY_RET_NOERRCODE(ret, func, args) \
|
|
CL_API_ENTRY ret CL_API_CALL \
|
|
func args \
|
|
{ \
|
|
amd::Thread* thread = amd::Thread::current(); \
|
|
if (!VDI_CHECK_THREAD(thread)) { \
|
|
return (ret) 0; \
|
|
}
|
|
|
|
#define RUNTIME_ENTRY(ret, func, args) \
|
|
CL_API_ENTRY ret CL_API_CALL \
|
|
func args \
|
|
{ \
|
|
amd::Thread* thread = amd::Thread::current(); \
|
|
if (!VDI_CHECK_THREAD(thread)) { \
|
|
return CL_OUT_OF_HOST_MEMORY; \
|
|
}
|
|
|
|
#define RUNTIME_ENTRY_VOID(ret, func, args) \
|
|
CL_API_ENTRY ret CL_API_CALL \
|
|
func args \
|
|
{ \
|
|
amd::Thread* thread = amd::Thread::current(); \
|
|
if (!VDI_CHECK_THREAD(thread)) { \
|
|
return; \
|
|
}
|
|
|
|
#define RUNTIME_EXIT \
|
|
/* FIXME_lmoriche: we should check to thread->lastError here! */ \
|
|
}
|
|
|
|
namespace amd {
|
|
|
|
namespace detail {
|
|
|
|
template <typename T>
|
|
struct ParamInfo
|
|
{
|
|
static inline std::pair<const void*, size_t> get(const T& param) {
|
|
return std::pair<const void*, size_t>(¶m, sizeof(T));
|
|
}
|
|
};
|
|
|
|
template <>
|
|
struct ParamInfo<const char*>
|
|
{
|
|
static inline std::pair<const void*, size_t> get(const char* param) {
|
|
return std::pair<const void*, size_t>(param, strlen(param) + 1);
|
|
}
|
|
};
|
|
|
|
template <int N>
|
|
struct ParamInfo<char[N]>
|
|
{
|
|
static inline std::pair<const void*, size_t> get(const char* param) {
|
|
return std::pair<const void*, size_t>(param, strlen(param) + 1);
|
|
}
|
|
};
|
|
|
|
} // namespace detail
|
|
|
|
struct PlatformIDS { const struct KHRicdVendorDispatchRec* dispatch_; };
|
|
class PlatformID {
|
|
public:
|
|
static PlatformIDS Platform;
|
|
};
|
|
#define AMD_PLATFORM (reinterpret_cast<cl_platform_id>(&amd::PlatformID::Platform))
|
|
|
|
} // namespace amd
|
|
|
|
#endif /* _VDI_COMMON_H */ |