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/.
|
|
|
|
*/
|
|
|
|
|
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
|
|
|
#ifndef SC_OPENCLWRAPPER_HXX
|
|
|
|
#define SC_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-07-13 22:54:17 +03:00
|
|
|
// CL_MAP_WRITE_INVALIDATE_REGION is new in OpenCL 1.2.
|
|
|
|
|
|
|
|
// When compiling against an older OpenCL, use CL_MAP_WRITE.
|
|
|
|
|
|
|
|
// FIXME: But what if this code has been compiled against OpenCL 1.2
|
|
|
|
// headers but then runs against an OpenCL 1.1 implementation?
|
|
|
|
// Probably the code should check at run-time the version of the
|
|
|
|
// OpenCL implementation and choose which flag to use based on that.
|
|
|
|
#ifdef CL_MAP_WRITE_INVALIDATE_REGION
|
|
|
|
#define OPENCLWRAPPER_CL_MAP_WRITE_FLAG CL_MAP_WRITE_INVALIDATE_REGION
|
|
|
|
#else
|
|
|
|
#define OPENCLWRAPPER_CL_MAP_WRITE_FLAG CL_MAP_WRITE
|
|
|
|
#endif
|
|
|
|
|
2013-07-24 15:16:55 -04:00
|
|
|
#define MaxTextExtent 4096
|
|
|
|
//support AMD opencl
|
|
|
|
#define CL_QUEUE_THREAD_HANDLE_AMD 0x403E
|
|
|
|
#define CL_MAP_WRITE_INVALIDATE_REGION (1 << 2)
|
|
|
|
|
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; \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define CHECK_OPENCL_PTR(status,name) \
|
|
|
|
if( status != CL_SUCCESS ) \
|
|
|
|
{ \
|
|
|
|
printf ("OpenCL error code is %d at " SAL_DETAIL_WHERE " when %s .\n", status, name); \
|
|
|
|
return NULL; \
|
2013-09-10 17:01:15 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
#define CHECK_OPENCL_VOID(status,name) \
|
|
|
|
if( status != CL_SUCCESS ) \
|
|
|
|
{ \
|
|
|
|
printf ("OpenCL error code is %d at " SAL_DETAIL_WHERE " when %s .\n", status, name); \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define CHECK_OPENCL_RELEASE(status,name) \
|
|
|
|
if ( name != NULL ) \
|
|
|
|
clReleaseMemObject( name ); \
|
|
|
|
if( status != CL_SUCCESS ) \
|
|
|
|
{ \
|
|
|
|
printf ("OpenCL error code is %d at " SAL_DETAIL_WHERE " when clReleaseMemObject( %s ).\n", status, #name); \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define MAX_KERNEL_STRING_LEN 64
|
2013-09-16 18:29:37 -04:00
|
|
|
#define MAX_CLFILE_NUM 50
|
2013-09-10 17:01:15 -04:00
|
|
|
#define MAX_CLKERNEL_NUM 200
|
|
|
|
#define MAX_KERNEL_NAME_LEN 64
|
|
|
|
|
2013-06-16 17:18:23 +01:00
|
|
|
#if defined(_MSC_VER)
|
|
|
|
#ifndef strcasecmp
|
|
|
|
#define strcasecmp strcmp
|
|
|
|
#endif
|
|
|
|
#endif
|
2013-06-26 14:04:25 +01:00
|
|
|
|
2013-08-05 10:21:36 -04:00
|
|
|
#include <cstdio>
|
|
|
|
#include <vector>
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
extern "C" {
|
|
|
|
|
2013-09-10 17:01:15 -04:00
|
|
|
// user defined, this is function wrapper which is used to set the input
|
|
|
|
// parameters, launch kernel and copy data from GPU to CPU or CPU to GPU.
|
2013-07-24 15:16:55 -04:00
|
|
|
typedef int ( *cl_kernel_function )( void **userdata, KernelEnv *kenv );
|
2013-06-16 17:18:23 +01:00
|
|
|
|
|
|
|
}
|
2013-06-26 12:19:51 +01:00
|
|
|
|
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
|
2013-07-24 15:16:55 -04:00
|
|
|
int mnKhrFp64Flag;
|
|
|
|
int 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
|
|
|
};
|
|
|
|
|
2013-07-24 15:16:55 -04:00
|
|
|
class OpenclDevice
|
|
|
|
{
|
2013-06-16 17:18:23 +01:00
|
|
|
public:
|
2013-06-26 12:19:51 +01:00
|
|
|
static GPUEnv gpuEnv;
|
|
|
|
static int isInited;
|
2013-09-17 19:31:41 +02:00
|
|
|
static OString maCacheFolder;
|
|
|
|
|
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
|
|
|
static int registOpenclKernel();
|
|
|
|
static int releaseOpenclRunEnv();
|
|
|
|
static int initOpenclRunEnv( GPUEnv *gpu );
|
|
|
|
static int releaseOpenclEnv( GPUEnv *gpuInfo );
|
|
|
|
static int initOpenclRunEnv( int argc );
|
|
|
|
static int generatBinFromKernelSource( cl_program program, const char * clFileName );
|
2013-09-17 04:24:36 +02:00
|
|
|
static int 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
|
|
|
|
2013-09-14 01:22:41 +02:00
|
|
|
static int initOpenclAttr( OpenCLEnv * env );
|
2013-09-16 18:51:51 -04:00
|
|
|
static int setKernelEnv( KernelEnv *envInfo );
|
2013-06-26 12:19:51 +01:00
|
|
|
|
2013-09-16 18:51:51 -04:00
|
|
|
static int getOpenclState();
|
|
|
|
static void setOpenclState( int state );
|
2013-06-16 17:18:23 +01:00
|
|
|
};
|
|
|
|
|
2013-09-13 18:59:41 -04:00
|
|
|
size_t getOpenCLPlatformCount();
|
2013-09-14 01:22:41 +02:00
|
|
|
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
|
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
|
|
|
*/
|
2013-09-14 16:07:42 +02:00
|
|
|
bool switchOpenclDevice(const OUString* pDeviceId, bool bAutoSelect);
|
2013-09-13 14:11:43 +02:00
|
|
|
|
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: */
|