2013-06-16 17:18:23 +01:00
|
|
|
/* -*- 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/.
|
|
|
|
*/
|
|
|
|
|
2014-04-18 19:10:04 +02:00
|
|
|
#ifndef INCLUDED_SC_SOURCE_CORE_OPENCL_OPENCLWRAPPER_HXX
|
|
|
|
#define INCLUDED_SC_SOURCE_CORE_OPENCL_OPENCLWRAPPER_HXX
|
2013-06-16 17:18:23 +01:00
|
|
|
|
2013-06-26 14:04:25 +01:00
|
|
|
#include <config_features.h>
|
2013-07-08 21:35:26 +01:00
|
|
|
#include <formula/opcode.hxx>
|
2013-07-09 12:02:43 +01:00
|
|
|
#include <sal/detail/log.h>
|
2013-09-17 23:04:54 +02:00
|
|
|
#include <osl/file.hxx>
|
|
|
|
#include <vector>
|
|
|
|
#include <boost/shared_ptr.hpp>
|
2013-07-08 21:35:26 +01:00
|
|
|
#include <cassert>
|
2013-09-13 14:11:43 +02:00
|
|
|
#include "platforminfo.hxx"
|
2013-09-11 14:22:48 -04:00
|
|
|
|
2013-09-17 04:24:36 +02:00
|
|
|
#include <rtl/string.hxx>
|
|
|
|
|
2013-09-11 14:22:48 -04:00
|
|
|
#include "clcc/clew.h"
|
2013-06-16 17:18:23 +01:00
|
|
|
|
2013-09-10 17:01:15 -04:00
|
|
|
#define CHECK_OPENCL(status,name) \
|
|
|
|
if( status != CL_SUCCESS ) \
|
|
|
|
{ \
|
|
|
|
printf ("OpenCL error code is %d at " SAL_DETAIL_WHERE " when %s .\n", status, name); \
|
2013-09-16 22:16:54 -04:00
|
|
|
return false; \
|
|
|
|
}
|
|
|
|
|
2013-09-16 18:29:37 -04:00
|
|
|
#define MAX_CLFILE_NUM 50
|
2013-09-10 17:01:15 -04:00
|
|
|
|
2013-08-05 10:21:36 -04:00
|
|
|
#include <cstdio>
|
|
|
|
|
2013-07-24 15:16:55 -04:00
|
|
|
typedef struct _KernelEnv
|
|
|
|
{
|
2013-07-08 10:49:05 +01:00
|
|
|
cl_context mpkContext;
|
|
|
|
cl_command_queue mpkCmdQueue;
|
|
|
|
cl_program mpkProgram;
|
2013-06-16 17:18:23 +01:00
|
|
|
} KernelEnv;
|
|
|
|
|
2013-09-10 17:01:15 -04:00
|
|
|
namespace sc { namespace opencl {
|
Patch for milestone1-0829-v4.
1. Add the parser based on RPN;
2. For test sample1 named "ground-water-daily.xls", using the compound formula
to do calculation;
Add the compound kernels:
Formulae include "AVERAGE,MAX and MIN".Compound formulae include "AVERAGE
-(+,*,/)","MAX -(+,*,/)" and "MIN -(+,*,/)";
3. For formulae which do not work in GPU, they'll work in CPU;
4. For compound operators(-,+,*,/), they'll be calculated one by one in GPU as
the sequence of RPN;
5. Add the start and end position to fit for the sliding window;
6. Modify kernels by using vector for AMD GPU.
Conflicts:
sc/source/core/opencl/formulagroupcl.cxx
sc/source/core/opencl/openclwrapper.cxx
Change-Id: I6157008575ce89ddd3e7bf552a87812474af4125
2013-08-30 15:35:17 -04:00
|
|
|
|
2013-09-10 17:01:15 -04:00
|
|
|
typedef unsigned int uint;
|
2013-06-16 17:18:23 +01:00
|
|
|
|
2013-09-16 15:35:31 -04:00
|
|
|
struct OpenCLEnv
|
2013-09-10 17:01:15 -04:00
|
|
|
{
|
|
|
|
cl_platform_id mpOclPlatformID;
|
|
|
|
cl_context mpOclContext;
|
|
|
|
cl_device_id mpOclDevsID;
|
|
|
|
cl_command_queue mpOclCmdQueue;
|
2013-09-16 15:35:31 -04:00
|
|
|
};
|
2013-06-16 17:18:23 +01:00
|
|
|
|
2013-09-16 15:35:31 -04:00
|
|
|
struct GPUEnv
|
2013-07-24 15:16:55 -04:00
|
|
|
{
|
2013-06-16 17:18:23 +01:00
|
|
|
//share vb in all modules in hb library
|
2013-07-08 10:49:05 +01:00
|
|
|
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
|
2013-09-16 16:32:25 -04:00
|
|
|
int mnIsUserCreated; // 1: created , 0:no create and needed to create by opencl wrapper
|
2014-01-17 11:49:26 +01:00
|
|
|
bool mnKhrFp64Flag;
|
|
|
|
bool mnAmdFp64Flag;
|
2013-09-16 15:35:31 -04:00
|
|
|
};
|
2013-06-16 17:18:23 +01:00
|
|
|
|
2013-09-16 15:35:31 -04:00
|
|
|
struct SingleVectorFormula
|
Patch for milestone1-0829-v4.
1. Add the parser based on RPN;
2. For test sample1 named "ground-water-daily.xls", using the compound formula
to do calculation;
Add the compound kernels:
Formulae include "AVERAGE,MAX and MIN".Compound formulae include "AVERAGE
-(+,*,/)","MAX -(+,*,/)" and "MIN -(+,*,/)";
3. For formulae which do not work in GPU, they'll work in CPU;
4. For compound operators(-,+,*,/), they'll be calculated one by one in GPU as
the sequence of RPN;
5. Add the start and end position to fit for the sliding window;
6. Modify kernels by using vector for AMD GPU.
Conflicts:
sc/source/core/opencl/formulagroupcl.cxx
sc/source/core/opencl/openclwrapper.cxx
Change-Id: I6157008575ce89ddd3e7bf552a87812474af4125
2013-08-30 15:35:17 -04:00
|
|
|
{
|
|
|
|
const double *mdpInputLeftData;
|
|
|
|
const double *mdpInputRightData;
|
|
|
|
size_t mnInputLeftDataSize;
|
|
|
|
size_t mnInputRightDataSize;
|
|
|
|
uint mnInputLeftStartPosition;
|
|
|
|
uint mnInputRightStartPosition;
|
|
|
|
int mnInputLeftOffset;
|
|
|
|
int mnInputRightOffset;
|
2013-09-16 15:35:31 -04:00
|
|
|
};
|
Patch for milestone1-0829-v4.
1. Add the parser based on RPN;
2. For test sample1 named "ground-water-daily.xls", using the compound formula
to do calculation;
Add the compound kernels:
Formulae include "AVERAGE,MAX and MIN".Compound formulae include "AVERAGE
-(+,*,/)","MAX -(+,*,/)" and "MIN -(+,*,/)";
3. For formulae which do not work in GPU, they'll work in CPU;
4. For compound operators(-,+,*,/), they'll be calculated one by one in GPU as
the sequence of RPN;
5. Add the start and end position to fit for the sliding window;
6. Modify kernels by using vector for AMD GPU.
Conflicts:
sc/source/core/opencl/formulagroupcl.cxx
sc/source/core/opencl/openclwrapper.cxx
Change-Id: I6157008575ce89ddd3e7bf552a87812474af4125
2013-08-30 15:35:17 -04:00
|
|
|
|
2013-09-16 15:35:31 -04:00
|
|
|
struct DoubleVectorFormula
|
Patch for milestone1-0829-v4.
1. Add the parser based on RPN;
2. For test sample1 named "ground-water-daily.xls", using the compound formula
to do calculation;
Add the compound kernels:
Formulae include "AVERAGE,MAX and MIN".Compound formulae include "AVERAGE
-(+,*,/)","MAX -(+,*,/)" and "MIN -(+,*,/)";
3. For formulae which do not work in GPU, they'll work in CPU;
4. For compound operators(-,+,*,/), they'll be calculated one by one in GPU as
the sequence of RPN;
5. Add the start and end position to fit for the sliding window;
6. Modify kernels by using vector for AMD GPU.
Conflicts:
sc/source/core/opencl/formulagroupcl.cxx
sc/source/core/opencl/openclwrapper.cxx
Change-Id: I6157008575ce89ddd3e7bf552a87812474af4125
2013-08-30 15:35:17 -04:00
|
|
|
{
|
|
|
|
const double *mdpInputData;
|
|
|
|
size_t mnInputDataSize;
|
|
|
|
uint mnInputStartPosition;
|
|
|
|
uint mnInputEndPosition;
|
|
|
|
int mnInputStartOffset;
|
|
|
|
int mnInputEndOffset;
|
2013-09-16 15:35:31 -04:00
|
|
|
};
|
|
|
|
|
2014-10-03 15:16:06 -04:00
|
|
|
class OpenCLDevice
|
2013-07-24 15:16:55 -04:00
|
|
|
{
|
2013-06-16 17:18:23 +01:00
|
|
|
public:
|
2013-06-26 12:19:51 +01:00
|
|
|
static GPUEnv gpuEnv;
|
2014-02-28 15:41:21 +02:00
|
|
|
static bool bIsInited;
|
2013-09-17 19:31:41 +02:00
|
|
|
static OString maCacheFolder;
|
|
|
|
|
2014-10-03 15:16:06 -04:00
|
|
|
static void registerOpenCLKernel();
|
|
|
|
static bool initOpenCLRunEnv( GPUEnv *gpu );
|
|
|
|
static void releaseOpenCLEnv( GPUEnv *gpuInfo );
|
|
|
|
static bool initOpenCLRunEnv( int argc );
|
2014-01-17 11:49:58 +01:00
|
|
|
static bool generatBinFromKernelSource( cl_program program, const char * clFileName );
|
|
|
|
static bool writeBinaryToFile( const OString& rName, const char* birary, size_t numBytes );
|
2013-09-17 23:04:54 +02:00
|
|
|
static std::vector<boost::shared_ptr<osl::File> > binaryGenerated( const char * clFileName, cl_context context);
|
2013-10-01 05:56:34 +02:00
|
|
|
static bool buildProgramFromBinary(const char* buildOption, GPUEnv* gpuEnv, const char* filename, int idx);
|
Patch for milestone1-0829-v4.
1. Add the parser based on RPN;
2. For test sample1 named "ground-water-daily.xls", using the compound formula
to do calculation;
Add the compound kernels:
Formulae include "AVERAGE,MAX and MIN".Compound formulae include "AVERAGE
-(+,*,/)","MAX -(+,*,/)" and "MIN -(+,*,/)";
3. For formulae which do not work in GPU, they'll work in CPU;
4. For compound operators(-,+,*,/), they'll be calculated one by one in GPU as
the sequence of RPN;
5. Add the start and end position to fit for the sliding window;
6. Modify kernels by using vector for AMD GPU.
Conflicts:
sc/source/core/opencl/formulagroupcl.cxx
sc/source/core/opencl/openclwrapper.cxx
Change-Id: I6157008575ce89ddd3e7bf552a87812474af4125
2013-08-30 15:35:17 -04:00
|
|
|
|
2014-10-03 15:16:06 -04:00
|
|
|
static bool initOpenCLAttr( OpenCLEnv * env );
|
2014-01-17 11:49:58 +01:00
|
|
|
static void setKernelEnv( KernelEnv *envInfo );
|
2013-06-16 17:18:23 +01:00
|
|
|
};
|
|
|
|
|
2013-09-13 18:59:41 -04:00
|
|
|
size_t getOpenCLPlatformCount();
|
2014-10-03 15:16:06 -04:00
|
|
|
const std::vector<OpenCLPlatformInfo>& fillOpenCLInfo();
|
2013-09-14 01:22:41 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
2013-09-14 16:07:42 +02:00
|
|
|
*
|
|
|
|
* @return returns true if there is a valid opencl device that has been set up
|
2013-09-14 01:22:41 +02:00
|
|
|
*/
|
2014-10-03 15:16:06 -04:00
|
|
|
bool switchOpenCLDevice(const OUString* pDeviceId, bool bAutoSelect,
|
2013-11-25 22:13:32 +01:00
|
|
|
bool bForceEvaluation);
|
2013-09-13 14:11:43 +02:00
|
|
|
|
2013-11-22 20:27:48 +01:00
|
|
|
void getOpenCLDeviceInfo(size_t& rDeviceId, size_t& rPlatformId);
|
|
|
|
|
2013-09-10 17:01:15 -04:00
|
|
|
}}
|
|
|
|
|
2013-06-26 12:19:51 +01:00
|
|
|
#endif
|
2013-09-10 17:01:15 -04:00
|
|
|
|
2013-06-26 12:19:51 +01:00
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|