[Libreoffice-commits] core.git: include/opencl opencl/source sc/source

Tor Lillqvist tml at collabora.com
Wed Sep 16 07:52:20 PDT 2015


 include/opencl/openclwrapper.hxx         |    1 
 opencl/source/openclwrapper.cxx          |  151 +++++++++----------------------
 sc/source/core/opencl/formulagroupcl.cxx |    8 -
 3 files changed, 50 insertions(+), 110 deletions(-)

New commits:
commit 11e1c55ce05a78a486b0ea5668b1a424cd9c8f11
Author: Tor Lillqvist <tml at collabora.com>
Date:   Wed Sep 16 17:48:43 2015 +0300

    YAGNI
    
    We use only one OpenCL device per context or program, so get rid of
    half-implemented (or half-reverted?) "support" for multiple devices per
    context.
    
    Change-Id: I951f29e867e5b3f96f6e051567ee38d607bd7ecf

diff --git a/include/opencl/openclwrapper.hxx b/include/opencl/openclwrapper.hxx
index fe67772..1541739 100644
--- a/include/opencl/openclwrapper.hxx
+++ b/include/opencl/openclwrapper.hxx
@@ -43,7 +43,6 @@ struct GPUEnv
     cl_platform_id mpPlatformID;
     cl_device_type mDevType;
     cl_context mpContext;
-    cl_device_id *mpArryDevsID;
     cl_device_id mpDevID;
     cl_command_queue mpCmdQueue[OPENCL_CMDQUEUE_SIZE];
     cl_program mpArryPrograms[MAX_CLFILE_NUM]; //one program object maps one kernel source file
diff --git a/opencl/source/openclwrapper.cxx b/opencl/source/openclwrapper.cxx
index 79aabba..d99b131 100644
--- a/opencl/source/openclwrapper.cxx
+++ b/opencl/source/openclwrapper.cxx
@@ -148,32 +148,29 @@ std::vector<std::shared_ptr<osl::File> > binaryGenerated( const char * clFileNam
     if(clStatus != CL_SUCCESS)
         return aGeneratedFiles;
 
-    // grab the handles to all of the devices in the context.
-    std::unique_ptr<cl_device_id[]> pArryDevsID(new cl_device_id[numDevices]);
+    assert(numDevices == 1);
+
+    // grab the handle to the device in the context.
+    cl_device_id pDevID;
     clStatus = clGetContextInfo( context, CL_CONTEXT_DEVICES,
-            sizeof( cl_device_id ) * numDevices, pArryDevsID.get(), NULL );
+            sizeof( cl_device_id ), &pDevID, NULL );
 
     if(clStatus != CL_SUCCESS)
         return aGeneratedFiles;
 
-    for ( size_t i = 0; i < numDevices; i++ )
+    assert(pDevID == gpuEnv.mpDevID);
+
+    OString fileName = createFileName(gpuEnv.mpDevID, clFileName);
+    osl::File* pNewFile = new osl::File(rtl::OStringToOUString(fileName, RTL_TEXTENCODING_UTF8));
+    if(pNewFile->open(osl_File_OpenFlag_Read) == osl::FileBase::E_None)
     {
-        if ( pArryDevsID[i] != 0 )
-        {
-            OString fileName = createFileName(gpuEnv.mpArryDevsID[i], clFileName);
-            osl::File* pNewFile = new osl::File(rtl::OStringToOUString(fileName, RTL_TEXTENCODING_UTF8));
-            if(pNewFile->open(osl_File_OpenFlag_Read) == osl::FileBase::E_None)
-            {
-                aGeneratedFiles.push_back(std::shared_ptr<osl::File>(pNewFile));
-                SAL_INFO("opencl.file", "Opening binary file '" << fileName << "' for reading: success");
-            }
-            else
-            {
-                SAL_INFO("opencl.file", "Opening binary file '" << fileName << "' for reading: FAIL");
-                delete pNewFile;
-                break;
-            }
-        }
+        aGeneratedFiles.push_back(std::shared_ptr<osl::File>(pNewFile));
+        SAL_INFO("opencl.file", "Opening binary file '" << fileName << "' for reading: success");
+    }
+    else
+    {
+        SAL_INFO("opencl.file", "Opening binary file '" << fileName << "' for reading: FAIL");
+        delete pNewFile;
     }
 
     return aGeneratedFiles;
@@ -206,59 +203,37 @@ bool generatBinFromKernelSource( cl_program program, const char * clFileName )
                    sizeof(numDevices), &numDevices, NULL );
     CHECK_OPENCL( clStatus, "clGetProgramInfo" );
 
-    std::vector<cl_device_id> pArryDevsID(numDevices);
-    /* grab the handles to all of the devices in the program. */
+    assert(numDevices == 1);
+
+    cl_device_id pDevID;
+    /* grab the handle to the device in the program. */
     clStatus = clGetProgramInfo( program, CL_PROGRAM_DEVICES,
-                   sizeof(cl_device_id) * numDevices, &pArryDevsID[0], NULL );
+                   sizeof(cl_device_id), &pDevID, NULL );
     CHECK_OPENCL( clStatus, "clGetProgramInfo" );
 
-    /* figure out the sizes of each of the binaries. */
-    std::vector<size_t> binarySizes(numDevices);
+    /* figure out the size of the binary. */
+    size_t binarySize;
 
     clStatus = clGetProgramInfo( program, CL_PROGRAM_BINARY_SIZES,
-                   sizeof(size_t) * numDevices, &binarySizes[0], NULL );
+                   sizeof(size_t), &binarySize, NULL );
     CHECK_OPENCL( clStatus, "clGetProgramInfo" );
 
-    /* copy over all of the generated binaries. */
-    std::unique_ptr<char*[]> binaries(new char*[numDevices]);
-
-    for ( size_t i = 0; i < numDevices; i++ )
+    /* copy over the generated binary. */
+    if ( binarySize != 0 )
     {
-        if ( binarySizes[i] != 0 )
-        {
-            binaries[i] = new char[binarySizes[i]];
-        }
+        char *binary = new char[binarySize];
+        clStatus = clGetProgramInfo( program, CL_PROGRAM_BINARIES,
+                                     sizeof(char *), &binary, NULL );
+        CHECK_OPENCL(clStatus,"clGetProgramInfo");
+
+        OString fileName = createFileName(pDevID, clFileName);
+        if ( !writeBinaryToFile( fileName,
+                                 binary, binarySize ) )
+            SAL_INFO("opencl.file", "Writing binary file '" << fileName << "': FAIL");
         else
-        {
-            binaries[i] = NULL;
-        }
-    }
-
-    clStatus = clGetProgramInfo( program, CL_PROGRAM_BINARIES,
-                   sizeof(char *) * numDevices, binaries.get(), NULL );
-    CHECK_OPENCL(clStatus,"clGetProgramInfo");
-
-    /* dump out each binary into its own separate file. */
-    for ( size_t i = 0; i < numDevices; i++ )
-    {
-
-        if ( binarySizes[i] != 0 )
-        {
-            OString fileName = createFileName(pArryDevsID[i], clFileName);
-            if ( !writeBinaryToFile( fileName,
-                        binaries[i], binarySizes[i] ) )
-                SAL_INFO("opencl.file", "Writing binary file '" << fileName << "': FAIL");
-            else
-                SAL_INFO("opencl.file", "Writing binary file '" << fileName << "': success");
-        }
-    }
-
-    // Release all resources and memory
-    for ( size_t i = 0; i < numDevices; i++ )
-    {
-        delete[] binaries[i];
+            SAL_INFO("opencl.file", "Writing binary file '" << fileName << "': success");
+        delete[] binary;
     }
-
     return true;
 }
 
@@ -315,7 +290,6 @@ void releaseOpenCLEnv( GPUEnv *gpuInfo )
     }
     bIsInited = false;
     gpuInfo->mnIsUserCreated = 0;
-    free( gpuInfo->mpArryDevsID );
 
     return;
 }
@@ -325,46 +299,22 @@ bool buildProgram(const char* buildOption, GPUEnv* gpuInfo, int idx)
     cl_int clStatus;
     //char options[512];
     // create a cl program executable for all the devices specified
-    if (!gpuInfo->mnIsUserCreated)
-    {
-        clStatus = clBuildProgram(gpuInfo->mpArryPrograms[idx], 1, gpuInfo->mpArryDevsID,
-                       buildOption, NULL, NULL);
-    }
-    else
-    {
-        clStatus = clBuildProgram(gpuInfo->mpArryPrograms[idx], 1, &(gpuInfo->mpDevID),
-                       buildOption, NULL, NULL);
-    }
+    clStatus = clBuildProgram(gpuInfo->mpArryPrograms[idx], 1, &gpuInfo->mpDevID,
+                              buildOption, NULL, NULL);
 
     if ( clStatus != CL_SUCCESS )
     {
         size_t length;
-        if ( !gpuInfo->mnIsUserCreated )
-        {
-            clStatus = clGetProgramBuildInfo( gpuInfo->mpArryPrograms[idx], gpuInfo->mpArryDevsID[0],
-                           CL_PROGRAM_BUILD_LOG, 0, NULL, &length );
-        }
-        else
-        {
-            clStatus = clGetProgramBuildInfo( gpuInfo->mpArryPrograms[idx], gpuInfo->mpDevID,
-                           CL_PROGRAM_BUILD_LOG, 0, NULL, &length);
-        }
+        clStatus = clGetProgramBuildInfo( gpuInfo->mpArryPrograms[idx], gpuInfo->mpDevID,
+                                          CL_PROGRAM_BUILD_LOG, 0, NULL, &length);
         if ( clStatus != CL_SUCCESS )
         {
             return false;
         }
 
         std::unique_ptr<char[]> buildLog(new char[length]);
-        if ( !gpuInfo->mnIsUserCreated )
-        {
-            clStatus = clGetProgramBuildInfo( gpuInfo->mpArryPrograms[idx], gpuInfo->mpArryDevsID[0],
-                           CL_PROGRAM_BUILD_LOG, length, buildLog.get(), &length );
-        }
-        else
-        {
-            clStatus = clGetProgramBuildInfo( gpuInfo->mpArryPrograms[idx], gpuInfo->mpDevID,
-                           CL_PROGRAM_BUILD_LOG, length, buildLog.get(), &length );
-        }
+        clStatus = clGetProgramBuildInfo( gpuInfo->mpArryPrograms[idx], gpuInfo->mpDevID,
+                                          CL_PROGRAM_BUILD_LOG, length, buildLog.get(), &length );
         if ( clStatus != CL_SUCCESS )
         {
             return false;
@@ -496,14 +446,14 @@ bool initOpenCLRunEnv( GPUEnv *gpuInfo )
     bool bKhrFp64 = false;
     bool bAmdFp64 = false;
 
-    checkDeviceForDoubleSupport(gpuInfo->mpArryDevsID[0], bKhrFp64, bAmdFp64);
+    checkDeviceForDoubleSupport(gpuInfo->mpDevID, bKhrFp64, bAmdFp64);
 
     gpuInfo->mnKhrFp64Flag = bKhrFp64;
     gpuInfo->mnAmdFp64Flag = bAmdFp64;
 
     gpuInfo->mnPreferredVectorWidthFloat = 0;
 
-    clGetDeviceInfo(gpuInfo->mpArryDevsID[0], CL_DEVICE_PREFERRED_VECTOR_WIDTH_FLOAT, sizeof(cl_uint),
+    clGetDeviceInfo(gpuInfo->mpDevID, CL_DEVICE_PREFERRED_VECTOR_WIDTH_FLOAT, sizeof(cl_uint),
                     &gpuInfo->mnPreferredVectorWidthFloat, NULL);
 
     return false;
@@ -830,15 +780,6 @@ bool switchOpenCLDevice(const OUString* pDevice, bool bAutoSelect, bool bForceEv
 
     initOpenCLAttr(&env);
 
-    // why do we need this at all?
-
-    // (Assuming the above question refers to the mpArryDevsID
-    // initialisation below.) Because otherwise the code crashes in
-    // initOpenCLRunEnv(). Confused? You should be.
-
-    gpuEnv.mpArryDevsID = static_cast<cl_device_id*>(malloc( sizeof(cl_device_id) ));
-    gpuEnv.mpArryDevsID[0] = pDeviceId;
-
     return !initOpenCLRunEnv(0);
 }
 
diff --git a/sc/source/core/opencl/formulagroupcl.cxx b/sc/source/core/opencl/formulagroupcl.cxx
index c5b2822..340f391 100644
--- a/sc/source/core/opencl/formulagroupcl.cxx
+++ b/sc/source/core/opencl/formulagroupcl.cxx
@@ -3889,7 +3889,7 @@ void DynamicKernel::CreateKernel()
             SAL_INFO("sc.opencl", "Created program " << mpProgram);
 
             err = clBuildProgram(mpProgram, 1,
-                ::opencl::gpuEnv.mpArryDevsID, "", NULL, NULL);
+                &::opencl::gpuEnv.mpDevID, "", NULL, NULL);
             if (err != CL_SUCCESS)
             {
 #if OSL_DEBUG_LEVEL > 0
@@ -3897,7 +3897,7 @@ void DynamicKernel::CreateKernel()
                 {
                     cl_build_status stat;
                     cl_int e = clGetProgramBuildInfo(
-                        mpProgram, ::opencl::gpuEnv.mpArryDevsID[0],
+                        mpProgram, ::opencl::gpuEnv.mpDevID,
                         CL_PROGRAM_BUILD_STATUS, sizeof(cl_build_status),
                         &stat, 0);
                     SAL_WARN_IF(
@@ -3909,7 +3909,7 @@ void DynamicKernel::CreateKernel()
                     {
                         size_t n;
                         e = clGetProgramBuildInfo(
-                            mpProgram, ::opencl::gpuEnv.mpArryDevsID[0],
+                            mpProgram, ::opencl::gpuEnv.mpDevID,
                             CL_PROGRAM_BUILD_LOG, 0, 0, &n);
                         SAL_WARN_IF(
                             e != CL_SUCCESS || n == 0, "sc.opencl",
@@ -3920,7 +3920,7 @@ void DynamicKernel::CreateKernel()
                         {
                             std::vector<char> log(n);
                             e = clGetProgramBuildInfo(
-                                mpProgram, ::opencl::gpuEnv.mpArryDevsID[0],
+                                mpProgram, ::opencl::gpuEnv.mpDevID,
                                 CL_PROGRAM_BUILD_LOG, n, &log[0], 0);
                             SAL_WARN_IF(
                                 e != CL_SUCCESS || n == 0, "sc.opencl",


More information about the Libreoffice-commits mailing list