summaryrefslogtreecommitdiff
path: root/include/opencl
diff options
context:
space:
mode:
authorTor Lillqvist <tml@collabora.com>2014-11-27 15:13:12 +0200
committerTor Lillqvist <tml@collabora.com>2014-11-27 15:32:58 +0200
commita70b717ef872c0ac652883ecd2a82c4cc29763e2 (patch)
tree0975349b1b8798eb9d444d7c91d97d52a2f6fa4e /include/opencl
parentd83b031346799bff0a3298387f76b16baad2e5cf (diff)
Move more Calc-independent OpenCL stuff from the sc to the opencl module
No cleanups yet. Just removed the "sc" namespace parts now when this stuff is no longer Calc-specific. There is still horribly confusing use of the same OpenCLDevice name for both a class and as a namespace, for instance. And the OpenCLDevice class has only public static members even, so effectively it acts as just a namespace anyway... Etc. Change-Id: Idc5f30a721df0101426c676f04a85e02c5dc8443
Diffstat (limited to 'include/opencl')
-rw-r--r--include/opencl/openclwrapper.hxx109
1 files changed, 109 insertions, 0 deletions
diff --git a/include/opencl/openclwrapper.hxx b/include/opencl/openclwrapper.hxx
new file mode 100644
index 000000000000..ba7aada44f14
--- /dev/null
+++ b/include/opencl/openclwrapper.hxx
@@ -0,0 +1,109 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#ifndef INCLUDED_SC_SOURCE_CORE_OPENCL_OPENCLWRAPPER_HXX
+#define INCLUDED_SC_SOURCE_CORE_OPENCL_OPENCLWRAPPER_HXX
+
+#include <config_features.h>
+
+#include <cassert>
+#include <vector>
+
+#include <boost/shared_ptr.hpp>
+#include <clew.h>
+
+#include <sal/detail/log.h>
+#include <opencl/opencldllapi.h>
+#include <opencl/platforminfo.hxx>
+#include <osl/file.hxx>
+#include <rtl/string.hxx>
+
+
+#define CHECK_OPENCL(status,name) \
+if( status != CL_SUCCESS ) \
+{ \
+ printf ("OpenCL error code is %d at " SAL_DETAIL_WHERE " when %s .\n", status, name); \
+ return false; \
+}
+
+#define MAX_CLFILE_NUM 50
+
+#include <cstdio>
+
+struct KernelEnv
+{
+ cl_context mpkContext;
+ cl_command_queue mpkCmdQueue;
+ cl_program mpkProgram;
+};
+
+namespace opencl {
+
+struct OpenCLEnv
+{
+ cl_platform_id mpOclPlatformID;
+ cl_context mpOclContext;
+ cl_device_id mpOclDevsID;
+ cl_command_queue mpOclCmdQueue;
+};
+
+struct GPUEnv
+{
+ //share vb in all modules in hb library
+ cl_platform_id mpPlatformID;
+ cl_device_type mDevType;
+ cl_context mpContext;
+ cl_device_id *mpArryDevsID;
+ cl_device_id mpDevID;
+ cl_command_queue mpCmdQueue;
+ cl_program mpArryPrograms[MAX_CLFILE_NUM]; //one program object maps one kernel source file
+ int mnIsUserCreated; // 1: created , 0:no create and needed to create by opencl wrapper
+ bool mnKhrFp64Flag;
+ bool mnAmdFp64Flag;
+};
+
+class OPENCL_DLLPUBLIC OpenCLDevice
+{
+public:
+ static GPUEnv gpuEnv;
+ static bool bIsInited;
+ static OString maCacheFolder;
+
+ static bool initOpenCLRunEnv( GPUEnv *gpu );
+ static void releaseOpenCLEnv( GPUEnv *gpuInfo );
+ static bool initOpenCLRunEnv( int argc );
+ static bool generatBinFromKernelSource( cl_program program, const char * clFileName );
+ static bool writeBinaryToFile( const OString& rName, const char* birary, size_t numBytes );
+ static std::vector<boost::shared_ptr<osl::File> > binaryGenerated( const char * clFileName, cl_context context);
+ static bool buildProgramFromBinary(const char* buildOption, GPUEnv* gpuEnv, const char* filename, int idx);
+
+ static bool initOpenCLAttr( OpenCLEnv * env );
+ static void setKernelEnv( KernelEnv *envInfo );
+};
+
+OPENCL_DLLPUBLIC const std::vector<OpenCLPlatformInfo>& fillOpenCLInfo();
+
+/**
+ * Used to set or switch between OpenCL devices.
+ *
+ * @param pDeviceId the id of the opencl device of type cl_device_id, NULL means use software calculation
+ * @param bAutoSelect use the algorithm to select the best OpenCL device
+ *
+ * @return returns true if there is a valid opencl device that has been set up
+ */
+OPENCL_DLLPUBLIC bool switchOpenCLDevice(const OUString* pDeviceId, bool bAutoSelect,
+ bool bForceEvaluation);
+
+OPENCL_DLLPUBLIC void getOpenCLDeviceInfo(size_t& rDeviceId, size_t& rPlatformId);
+
+}
+
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */