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