[Libreoffice-commits] core.git: Branch 'feature/calc-pluggable-opencl' - 2 commits - sc/source
Kohei Yoshida
kohei.yoshida at collabora.com
Mon Sep 16 15:27:32 PDT 2013
sc/source/core/opencl/openclwrapper.cxx | 173 ++++++++++----------------------
sc/source/core/opencl/openclwrapper.hxx | 16 --
2 files changed, 61 insertions(+), 128 deletions(-)
New commits:
commit 6670b6456a5b34cf32128f0b0a36183a34bd6f80
Author: Kohei Yoshida <kohei.yoshida at collabora.com>
Date: Mon Sep 16 18:21:28 2013 -0400
Remove unused methods.
Change-Id: Idfb6acde20e883e4c20e0f640fdb96ac50bb349f
diff --git a/sc/source/core/opencl/openclwrapper.cxx b/sc/source/core/opencl/openclwrapper.cxx
index 7d34b95..df35f3d 100644
--- a/sc/source/core/opencl/openclwrapper.cxx
+++ b/sc/source/core/opencl/openclwrapper.cxx
@@ -436,17 +436,6 @@ int OpenclDevice::releaseOpenclEnv( GPUEnv *gpuInfo )
return 1;
}
-int OpenclDevice::runKernelWrapper( cl_kernel_function function, const char * kernelName, void **usrdata )
-{
- printf("oclwrapper:runKernel_wrapper...\n");
- if ( registerKernelWrapper( kernelName, function ) != 1 )
- {
- fprintf(stderr, "Error:runKernel_wrapper:registerKernelWrapper fail!\n");
- return -1;
- }
- return ( runKernel( kernelName, usrdata ) );
-}
-
int OpenclDevice::cachedOfKernerPrg( const GPUEnv *gpuEnvCached, const char * clFileName )
{
int i;
@@ -625,43 +614,6 @@ int OpenclDevice::compileKernelFile( GPUEnv *gpuInfo, const char *buildOption )
return 1;
}
-int OpenclDevice::getKernelEnvAndFunc( const char *kernelName, KernelEnv *env, cl_kernel_function *function)
-{
- for (size_t i = 0, n = gpuEnv.maKernelNames.size(); i < n; ++i)
- {
- const char* pName = gpuEnv.maKernelNames[i];
- if (!strcasecmp(kernelName, pName))
- {
- env->mpkContext = gpuEnv.mpContext;
- env->mpkCmdQueue = gpuEnv.mpCmdQueue;
- env->mpkProgram = gpuEnv.mpArryPrograms[0];
- env->mpkKernel = gpuEnv.mpArryKernels[i];
- *function = gpuEnv.mpArryKnelFuncs[i];
- return 1;
- }
- }
-
- return 0;
-}
-
-int OpenclDevice::runKernel( const char *kernelName, void **userdata)
-{
- KernelEnv kEnv;
- cl_kernel_function function;
- int status;
-
- memset( &kEnv, 0, sizeof( KernelEnv ) );
- status = getKernelEnvAndFunc( kernelName, &kEnv, &function );
- strcpy( kEnv.mckKernelName, kernelName );
- if ( status == 1 )
- {
- if ( &kEnv == (KernelEnv *) NULL || &function == (cl_kernel_function *) NULL)
- return 0;
- return ( function( userdata, &kEnv ) );
- }
- return 0;
-}
-
int OpenclDevice::initOpenclRunEnv( int argc )
{
if ( MAX_CLKERNEL_NUM <= 0 )
@@ -891,18 +843,6 @@ int OpenclDevice::initOpenclRunEnv( GPUEnv *gpuInfo )
return 0;
}
-int OpenclDevice::registerKernelWrapper( const char *kernelName, cl_kernel_function function )
-{
- for (size_t i = 0, n = gpuEnv.maKernelNames.size(); i < n; ++i)
- {
- if (!strcasecmp(kernelName, gpuEnv.maKernelNames[i]))
- {
- gpuEnv.mpArryKnelFuncs[i] = function;
- return 1;
- }
- }
- return 0;
-}
void OpenclDevice::setOpenclState( int state )
{
diff --git a/sc/source/core/opencl/openclwrapper.hxx b/sc/source/core/opencl/openclwrapper.hxx
index 1dfed15..bd0fb4f 100644
--- a/sc/source/core/opencl/openclwrapper.hxx
+++ b/sc/source/core/opencl/openclwrapper.hxx
@@ -114,7 +114,6 @@ struct GPUEnv
cl_program mpArryPrograms[MAX_CLFILE_NUM]; //one program object maps one kernel source file
char mArryKnelSrcFile[MAX_CLFILE_NUM][256]; //the max len of kernel file name is 256
std::vector<const char*> maKernelNames;
- cl_kernel_function mpArryKnelFuncs[MAX_CLKERNEL_NUM];
int mnFileCount; // only one kernel file
int mnIsUserCreated; // 1: created , 0:no create and needed to create by opencl wrapper
int mnKhrFp64Flag;
@@ -190,12 +189,8 @@ public:
static int initOpenclAttr( OpenCLEnv * env );
int setKernelEnv( KernelEnv *envInfo );
- int runKernel( const char *kernelName, void **userdata );
int convertToString( const char *filename, char **source );
int checkKernelName( KernelEnv *envInfo, const char *kernelName );
- int registerKernelWrapper( const char *kernelName, cl_kernel_function function );
- int runKernelWrapper( cl_kernel_function function, const char * kernelName, void **usrdata );
- int getKernelEnvAndFunc( const char *kernelName, KernelEnv *env, cl_kernel_function *function );
int getOpenclState();
void setOpenclState( int state );
commit 1061d671236c8e10d1e4dfcd86a630d6615c794c
Author: Kohei Yoshida <kohei.yoshida at collabora.com>
Date: Mon Sep 16 16:32:25 2013 -0400
Use std::vector to store pre-defined kernel names.
Change-Id: I5de148a98411f85f5318ee6e5b0b41786d152a83
diff --git a/sc/source/core/opencl/openclwrapper.cxx b/sc/source/core/opencl/openclwrapper.cxx
index a5dcd57..7d34b95 100644
--- a/sc/source/core/opencl/openclwrapper.cxx
+++ b/sc/source/core/opencl/openclwrapper.cxx
@@ -64,15 +64,51 @@ int OpenclDevice::releaseOpenclRunEnv()
return 1;
}
-///////////////////////////////////////////////////////
-///////////////////////////////////////////////////////
-int OpenclDevice::addKernelConfig( int kCount, const char *kName )
-{
- if ( kCount < 1 )
- fprintf(stderr,"Error: ( KCount < 1 )" SAL_DETAIL_WHERE "addKernelConfig\n" );
- strcpy( gpuEnv.mArrykernelNames[kCount-1], kName );
- gpuEnv.mnKernelCount++;
- return 0;
+
+namespace {
+
+const char* pKernelNames[] = {
+
+ "oclFormulaMin",
+ "oclFormulaMax",
+ "oclFormulaSum",
+ "oclFormulaCount",
+ "oclFormulaAverage",
+ "oclFormulaSumproduct",
+ "oclFormulaMtxInv",
+
+ "oclSignedAdd",
+ "oclSignedSub",
+ "oclSignedMul",
+ "oclSignedDiv",
+ "oclAverageDelta",
+ "oclMaxDelta",
+ "oclMinDelta",
+ "oclSubDelta",
+ "oclLUDecomposition",
+ "oclAverageDeltaRPN",
+ "oclMaxDeltaRPN",
+ "oclMinDeltaRPN",
+ "oclMoreColArithmeticOperator",
+ "oclColumnH",
+ "oclColumnL",
+ "oclColumnN",
+ "oclColumnJ",
+ "oclMaxSub",
+ "oclAverageSub",
+ "oclMinSub",
+ "oclMaxAdd",
+ "oclAverageAdd",
+ "oclMinAdd",
+ "oclMaxMul",
+ "oclAverageMul"
+ "oclMinMul",
+ "oclMaxDiv",
+ "oclAverageDiv"
+ "oclMinDiv",
+ "oclSub"
+};
+
}
int OpenclDevice::registOpenclKernel()
@@ -81,46 +117,10 @@ int OpenclDevice::registOpenclKernel()
memset( &gpuEnv, 0, sizeof(gpuEnv) );
gpuEnv.mnFileCount = 0; //argc;
- gpuEnv.mnKernelCount = 0UL;
-
- addKernelConfig( 1, (const char*) "oclFormulaMin" );
- addKernelConfig( 2, (const char*) "oclFormulaMax" );
- addKernelConfig( 3, (const char*) "oclFormulaSum" );
- addKernelConfig( 4, (const char*) "oclFormulaCount" );
- addKernelConfig( 5, (const char*) "oclFormulaAverage" );
- addKernelConfig( 6, (const char*) "oclFormulaSumproduct" );
- addKernelConfig( 7, (const char*) "oclFormulaMtxInv" );
-
- addKernelConfig( 8, (const char*) "oclSignedAdd" );
- addKernelConfig( 9, (const char*) "oclSignedSub" );
- addKernelConfig( 10, (const char*) "oclSignedMul" );
- addKernelConfig( 11, (const char*) "oclSignedDiv" );
- addKernelConfig( 12, (const char*) "oclAverageDelta" );
- addKernelConfig( 13, (const char*) "oclMaxDelta" );
- addKernelConfig( 14, (const char*) "oclMinDelta" );
- addKernelConfig( 15, (const char*) "oclSubDelta" );
- addKernelConfig( 16, (const char*) "oclLUDecomposition" );
- addKernelConfig( 17, (const char*) "oclAverageDeltaRPN" );
- addKernelConfig( 18, (const char*) "oclMaxDeltaRPN" );
- addKernelConfig( 19, (const char*) "oclMinDeltaRPN" );
- addKernelConfig( 20, (const char*) "oclMoreColArithmeticOperator" );
- addKernelConfig( 21, (const char*) "oclColumnH" );
- addKernelConfig( 22, (const char*) "oclColumnL" );
- addKernelConfig( 23, (const char*) "oclColumnN" );
- addKernelConfig( 24, (const char*) "oclColumnJ" );
- addKernelConfig( 25, (const char*) "oclMaxSub" );
- addKernelConfig( 26, (const char*) "oclAverageSub" );
- addKernelConfig( 27, (const char*) "oclMinSub" );
- addKernelConfig( 28, (const char*) "oclMaxAdd" );
- addKernelConfig( 29, (const char*) "oclAverageAdd" );
- addKernelConfig( 30, (const char*) "oclMinAdd" );
- addKernelConfig( 31, (const char*) "oclMaxMul" );
- addKernelConfig( 32, (const char*) "oclAverageMul" );
- addKernelConfig( 33, (const char*) "oclMinMul" );
- addKernelConfig( 34, (const char*) "oclMaxDiv" );
- addKernelConfig( 35, (const char*) "oclAverageDiv" );
- addKernelConfig( 36, (const char*) "oclMinDiv" );
- addKernelConfig( 37, (const char*) "oclSub" );// for svDouble type
+
+ for (size_t i = 0, n = SAL_N_ELEMENTS(pKernelNames); i < n; ++i)
+ gpuEnv.maKernelNames.push_back(pKernelNames[i]);
+
return 0;
}
@@ -145,23 +145,24 @@ int OpenclDevice::setKernelEnv( KernelEnv *envInfo )
int OpenclDevice::checkKernelName( KernelEnv *envInfo, const char *kernelName )
{
- //printf("checkKernelName,total count of kernels...%d\n", gpuEnv.kernelCount);
- int kCount;
int nFlag = 0;
- for ( kCount=0; kCount < gpuEnv.mnKernelCount; kCount++ )
+ size_t i = 0;
+ for (size_t n = gpuEnv.maKernelNames.size(); i < n; ++i)
{
- if ( strcasecmp( kernelName, gpuEnv.mArrykernelNames[kCount]) == 0 )
+ const char* pName = gpuEnv.maKernelNames[i];
+ if (!strcasecmp(kernelName, pName))
{
nFlag = 1;
printf("match %s kernel right\n",kernelName);
break;
}
}
+
if ( !nFlag )
{
printf("can't find kernel: %s\n",kernelName);
}
- envInfo->mpkKernel = gpuEnv.mpArryKernels[kCount];
+ envInfo->mpkKernel = gpuEnv.mpArryKernels[i];
strcpy( envInfo->mckKernelName, kernelName );
if ( envInfo == (KernelEnv *) NULL )
{
@@ -626,11 +627,10 @@ int OpenclDevice::compileKernelFile( GPUEnv *gpuInfo, const char *buildOption )
int OpenclDevice::getKernelEnvAndFunc( const char *kernelName, KernelEnv *env, cl_kernel_function *function)
{
- int i;
- //printf("----------------OpenclDevice::getKernelEnvAndFunc\n");
- for ( i = 0; i < gpuEnv.mnKernelCount; i++ )
+ for (size_t i = 0, n = gpuEnv.maKernelNames.size(); i < n; ++i)
{
- if ( strcasecmp( kernelName, gpuEnv.mArrykernelNames[i]) == 0 )
+ const char* pName = gpuEnv.maKernelNames[i];
+ if (!strcasecmp(kernelName, pName))
{
env->mpkContext = gpuEnv.mpContext;
env->mpkCmdQueue = gpuEnv.mpCmdQueue;
@@ -640,6 +640,7 @@ int OpenclDevice::getKernelEnvAndFunc( const char *kernelName, KernelEnv *env, c
return 1;
}
}
+
return 0;
}
@@ -702,7 +703,7 @@ int OpenclDevice::initOpenclRunEnv( int argc )
printf("----use float type in kernel----\n");
status = compileKernelFile( &gpuEnv, "-Dfp_t=float -Dfp_t4=float4 -Dfp_t16=float16" );
}
- if ( status == 0 || gpuEnv.mnKernelCount == 0 )
+ if (status == 0 || gpuEnv.maKernelNames.empty())
{
printf("compileKernelFile failed.\n");
return 1;
@@ -892,11 +893,9 @@ int OpenclDevice::initOpenclRunEnv( GPUEnv *gpuInfo )
}
int OpenclDevice::registerKernelWrapper( const char *kernelName, cl_kernel_function function )
{
- int i;
- //printf("oclwrapper:registerKernelWrapper...%d\n", gpuEnv.mnKernelCount);
- for ( i = 0; i < gpuEnv.mnKernelCount; i++ )
+ for (size_t i = 0, n = gpuEnv.maKernelNames.size(); i < n; ++i)
{
- if ( strcasecmp( kernelName, gpuEnv.mArrykernelNames[i]) == 0 )
+ if (!strcasecmp(kernelName, gpuEnv.maKernelNames[i]))
{
gpuEnv.mpArryKnelFuncs[i] = function;
return 1;
diff --git a/sc/source/core/opencl/openclwrapper.hxx b/sc/source/core/opencl/openclwrapper.hxx
index cefec0d..1dfed15 100644
--- a/sc/source/core/opencl/openclwrapper.hxx
+++ b/sc/source/core/opencl/openclwrapper.hxx
@@ -59,7 +59,7 @@ if( status != CL_SUCCESS ) \
}
#define MAX_KERNEL_STRING_LEN 64
-#define MAX_CLFILE_NUM 50
+#define MAX_CLFILE_NUM 100
#define MAX_CLKERNEL_NUM 200
#define MAX_KERNEL_NAME_LEN 64
@@ -112,11 +112,11 @@ struct GPUEnv
cl_command_queue mpCmdQueue;
cl_kernel mpArryKernels[MAX_CLFILE_NUM];
cl_program mpArryPrograms[MAX_CLFILE_NUM]; //one program object maps one kernel source file
- char mArryKnelSrcFile[MAX_CLFILE_NUM][256], //the max len of kernel file name is 256
- mArrykernelNames[MAX_CLKERNEL_NUM][MAX_KERNEL_STRING_LEN + 1];
- cl_kernel_function mpArryKnelFuncs[MAX_CLKERNEL_NUM];
- int mnKernelCount, mnFileCount, // only one kernel file
- mnIsUserCreated; // 1: created , 0:no create and needed to create by opencl wrapper
+ char mArryKnelSrcFile[MAX_CLFILE_NUM][256]; //the max len of kernel file name is 256
+ std::vector<const char*> maKernelNames;
+ cl_kernel_function mpArryKnelFuncs[MAX_CLKERNEL_NUM];
+ int mnFileCount; // only one kernel file
+ int mnIsUserCreated; // 1: created , 0:no create and needed to create by opencl wrapper
int mnKhrFp64Flag;
int mnAmdFp64Flag;
};
@@ -199,7 +199,6 @@ public:
int getOpenclState();
void setOpenclState( int state );
- static int addKernelConfig( int kCount, const char *kName );
};
class OclCalc: public OpenclDevice,OpenclCalcBase
More information about the Libreoffice-commits
mailing list