Kaydet (Commit) 645e09ff authored tarafından Kohei Yoshida's avatar Kohei Yoshida Kaydeden (comit) Markus Mohrhard

Put all opencl related code inside sc::opencl namespace.

Change-Id: Ia6c1fd88ed08022347c60af33a8620b9cf278c12
üst 6db34b6b
......@@ -7,7 +7,6 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#include <config_features.h>
#include "formulagroup.hxx"
#include "document.hxx"
#include "formulacell.hxx"
......@@ -23,12 +22,11 @@
#define SINGLEARRAYLEN 100
#define DOUBLEARRAYLEN 100
#define SVDOUBLELEN 100
namespace sc {
namespace sc { namespace opencl {
// A single public entry point for a factory function:
namespace opencl {
extern sc::FormulaGroupInterpreter *createFormulaGroupInterpreter();
}
extern sc::FormulaGroupInterpreter *createFormulaGroupInterpreter();
/////time test dbg
double getTimeDiff(const TimeValue& t1, const TimeValue& t2)
......@@ -1063,17 +1061,15 @@ bool FormulaGroupInterpreterGroundwater::interpret(ScDocument& rDoc, const ScAdd
return true;
}
namespace opencl {
sc::FormulaGroupInterpreter *createFormulaGroupInterpreter()
{
if (getenv("SC_SOFTWARE"))
return NULL;
if (getenv("SC_GROUNDWATER"))
return new sc::FormulaGroupInterpreterGroundwater();
return new FormulaGroupInterpreterGroundwater();
return new sc::FormulaGroupInterpreterOpenCL();
return new FormulaGroupInterpreterOpenCL();
}
} // namespace opencl
......
......@@ -12,6 +12,9 @@
#ifndef USE_EXTERNAL_KERNEL
#define KERNEL( ... )# __VA_ARGS__
namespace sc { namespace opencl {
// Double precision is a default of spreadsheets
// cl_khr_fp64: Khronos extension
// cl_amd_fp64: AMD extension
......@@ -380,6 +383,8 @@ __kernel void oclSub( fp_t ltData, __global fp_t *rtData, __global fp_t *outData
}
);
}}
#endif // USE_EXTERNAL_KERNEL
#endif //_OCL_KERNEL_H_
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
......@@ -7,24 +7,19 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <cmath>
#include "openclwrapper.hxx"
#include "sal/config.h"
#include "random.hxx"
#include "openclwrapper.hxx"
#include "oclkernels.hxx"
#ifdef SAL_WIN32
#include <Windows.h>
#endif
//#define USE_MAP_BUFFER
using namespace std;
GPUEnv OpenclDevice::gpuEnv;
int OpenclDevice::isInited =0;
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <cmath>
#ifdef SAL_WIN32
#ifdef WIN32
#include <Windows.h>
#define OPENCL_DLL_NAME "opencllo.dll"
#define OCLERR -1
......@@ -40,6 +35,16 @@ int OpenclDevice::isInited =0;
#define OCL_CHECK(value1,value2,str) \
if(value1!=value2) \
fprintf(stderr,"[OCL_ERROR] %s\n",str);
#endif
using namespace std;
namespace sc { namespace opencl {
GPUEnv OpenclDevice::gpuEnv;
int OpenclDevice::isInited =0;
#ifdef WIN32
HINSTANCE HOpenclDll = NULL;
void * OpenclDll = NULL;
......@@ -69,7 +74,7 @@ void OpenclDevice::freeOpenclDll()
int OpenclDevice::initEnv()
{
#ifdef SAL_WIN32
#ifdef WIN32
while( 1 )
{
if( 1 == loadOpencl() )
......@@ -83,14 +88,14 @@ int OpenclDevice::initEnv()
int OpenclDevice::releaseOpenclRunEnv()
{
releaseOpenclEnv( &gpuEnv );
#ifdef SAL_WIN32
#ifdef WIN32
freeOpenclDll();
#endif
return 1;
}
///////////////////////////////////////////////////////
///////////////////////////////////////////////////////
inline int OpenclDevice::addKernelConfig( int kCount, const char *kName )
int OpenclDevice::addKernelConfig( int kCount, const char *kName )
{
if ( kCount < 1 )
fprintf(stderr,"Error: ( KCount < 1 )" SAL_DETAIL_WHERE "addKernelConfig\n" );
......@@ -2660,4 +2665,6 @@ int OclCalc::oclHostMatrixInverse32Bits( const char* aKernelName, float *fpOclMa
return 0;
}
}}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
......@@ -39,6 +39,32 @@
#define CL_QUEUE_THREAD_HANDLE_AMD 0x403E
#define CL_MAP_WRITE_INVALIDATE_REGION (1 << 2)
#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 0; \
}
#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
#define MAX_CLFILE_NUM 50
#define MAX_CLKERNEL_NUM 200
#define MAX_KERNEL_NAME_LEN 64
#if defined(_MSC_VER)
#ifndef strcasecmp
#define strcasecmp strcmp
......@@ -48,8 +74,6 @@
#include <cstdio>
#include <vector>
typedef unsigned int uint;
typedef struct _KernelEnv
{
cl_context mpkContext;
......@@ -59,52 +83,25 @@ typedef struct _KernelEnv
char mckKernelName[150];
} KernelEnv;
typedef struct _OpenCLEnv
{
cl_platform_id mpOclPlatformID;
cl_context mpOclContext;
cl_device_id mpOclDevsID;
cl_command_queue mpOclCmdQueue;
} OpenCLEnv;
#if defined __cplusplus
extern "C" {
#endif
//user defined, this is function wrapper which is used to set the input parameters,
//luanch kernel and copy data from GPU to CPU or CPU to GPU.
// 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.
typedef int ( *cl_kernel_function )( void **userdata, KernelEnv *kenv );
#if defined __cplusplus
}
#endif
#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 0; \
}
#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); \
}
namespace sc { namespace opencl {
#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); \
}
typedef unsigned int uint;
#define MAX_KERNEL_STRING_LEN 64
#define MAX_CLFILE_NUM 50
#define MAX_CLKERNEL_NUM 200
#define MAX_KERNEL_NAME_LEN 64
typedef struct _OpenCLEnv
{
cl_platform_id mpOclPlatformID;
cl_context mpOclContext;
cl_device_id mpOclDevsID;
cl_command_queue mpOclCmdQueue;
} OpenCLEnv;
typedef struct _GPUEnv
{
......@@ -214,14 +211,12 @@ public:
#ifdef WIN32
static int loadOpencl();
static int openclInite();
static void freeOpenclDll();
#endif
int getOpenclState();
void setOpenclState( int state );
inline static int addKernelConfig( int kCount, const char *kName );
static int addKernelConfig( int kCount, const char *kName );
};
class OclCalc: public OpenclDevice,OpenclCalcBase
......@@ -293,5 +288,8 @@ public:
friend class agency;
};
}}
#endif
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
......@@ -7,7 +7,6 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#include <config_features.h>
#include "formulagroup.hxx"
#include "document.hxx"
#include "formulacell.hxx"
......@@ -17,6 +16,7 @@
#include "scmatrix.hxx"
#include "formula/vectortoken.hxx"
#include "config_features.h"
#include <vector>
#include <boost/unordered_map.hpp>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment