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
This commit is contained in:
@@ -43,7 +43,6 @@ struct GPUEnv
|
|||||||
cl_platform_id mpPlatformID;
|
cl_platform_id mpPlatformID;
|
||||||
cl_device_type mDevType;
|
cl_device_type mDevType;
|
||||||
cl_context mpContext;
|
cl_context mpContext;
|
||||||
cl_device_id *mpArryDevsID;
|
|
||||||
cl_device_id mpDevID;
|
cl_device_id mpDevID;
|
||||||
cl_command_queue mpCmdQueue[OPENCL_CMDQUEUE_SIZE];
|
cl_command_queue mpCmdQueue[OPENCL_CMDQUEUE_SIZE];
|
||||||
cl_program mpArryPrograms[MAX_CLFILE_NUM]; //one program object maps one kernel source file
|
cl_program mpArryPrograms[MAX_CLFILE_NUM]; //one program object maps one kernel source file
|
||||||
|
@@ -148,32 +148,29 @@ std::vector<std::shared_ptr<osl::File> > binaryGenerated( const char * clFileNam
|
|||||||
if(clStatus != CL_SUCCESS)
|
if(clStatus != CL_SUCCESS)
|
||||||
return aGeneratedFiles;
|
return aGeneratedFiles;
|
||||||
|
|
||||||
// grab the handles to all of the devices in the context.
|
assert(numDevices == 1);
|
||||||
std::unique_ptr<cl_device_id[]> pArryDevsID(new cl_device_id[numDevices]);
|
|
||||||
|
// grab the handle to the device in the context.
|
||||||
|
cl_device_id pDevID;
|
||||||
clStatus = clGetContextInfo( context, CL_CONTEXT_DEVICES,
|
clStatus = clGetContextInfo( context, CL_CONTEXT_DEVICES,
|
||||||
sizeof( cl_device_id ) * numDevices, pArryDevsID.get(), NULL );
|
sizeof( cl_device_id ), &pDevID, NULL );
|
||||||
|
|
||||||
if(clStatus != CL_SUCCESS)
|
if(clStatus != CL_SUCCESS)
|
||||||
return aGeneratedFiles;
|
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 )
|
aGeneratedFiles.push_back(std::shared_ptr<osl::File>(pNewFile));
|
||||||
{
|
SAL_INFO("opencl.file", "Opening binary file '" << fileName << "' for reading: success");
|
||||||
OString fileName = createFileName(gpuEnv.mpArryDevsID[i], clFileName);
|
}
|
||||||
osl::File* pNewFile = new osl::File(rtl::OStringToOUString(fileName, RTL_TEXTENCODING_UTF8));
|
else
|
||||||
if(pNewFile->open(osl_File_OpenFlag_Read) == osl::FileBase::E_None)
|
{
|
||||||
{
|
SAL_INFO("opencl.file", "Opening binary file '" << fileName << "' for reading: FAIL");
|
||||||
aGeneratedFiles.push_back(std::shared_ptr<osl::File>(pNewFile));
|
delete 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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return aGeneratedFiles;
|
return aGeneratedFiles;
|
||||||
@@ -206,59 +203,37 @@ bool generatBinFromKernelSource( cl_program program, const char * clFileName )
|
|||||||
sizeof(numDevices), &numDevices, NULL );
|
sizeof(numDevices), &numDevices, NULL );
|
||||||
CHECK_OPENCL( clStatus, "clGetProgramInfo" );
|
CHECK_OPENCL( clStatus, "clGetProgramInfo" );
|
||||||
|
|
||||||
std::vector<cl_device_id> pArryDevsID(numDevices);
|
assert(numDevices == 1);
|
||||||
/* grab the handles to all of the devices in the program. */
|
|
||||||
|
cl_device_id pDevID;
|
||||||
|
/* grab the handle to the device in the program. */
|
||||||
clStatus = clGetProgramInfo( program, CL_PROGRAM_DEVICES,
|
clStatus = clGetProgramInfo( program, CL_PROGRAM_DEVICES,
|
||||||
sizeof(cl_device_id) * numDevices, &pArryDevsID[0], NULL );
|
sizeof(cl_device_id), &pDevID, NULL );
|
||||||
CHECK_OPENCL( clStatus, "clGetProgramInfo" );
|
CHECK_OPENCL( clStatus, "clGetProgramInfo" );
|
||||||
|
|
||||||
/* figure out the sizes of each of the binaries. */
|
/* figure out the size of the binary. */
|
||||||
std::vector<size_t> binarySizes(numDevices);
|
size_t binarySize;
|
||||||
|
|
||||||
clStatus = clGetProgramInfo( program, CL_PROGRAM_BINARY_SIZES,
|
clStatus = clGetProgramInfo( program, CL_PROGRAM_BINARY_SIZES,
|
||||||
sizeof(size_t) * numDevices, &binarySizes[0], NULL );
|
sizeof(size_t), &binarySize, NULL );
|
||||||
CHECK_OPENCL( clStatus, "clGetProgramInfo" );
|
CHECK_OPENCL( clStatus, "clGetProgramInfo" );
|
||||||
|
|
||||||
/* copy over all of the generated binaries. */
|
/* copy over the generated binary. */
|
||||||
std::unique_ptr<char*[]> binaries(new char*[numDevices]);
|
if ( binarySize != 0 )
|
||||||
|
|
||||||
for ( size_t i = 0; i < numDevices; i++ )
|
|
||||||
{
|
{
|
||||||
if ( binarySizes[i] != 0 )
|
char *binary = new char[binarySize];
|
||||||
{
|
clStatus = clGetProgramInfo( program, CL_PROGRAM_BINARIES,
|
||||||
binaries[i] = new char[binarySizes[i]];
|
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
|
else
|
||||||
{
|
SAL_INFO("opencl.file", "Writing binary file '" << fileName << "': success");
|
||||||
binaries[i] = NULL;
|
delete[] binary;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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];
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -315,7 +290,6 @@ void releaseOpenCLEnv( GPUEnv *gpuInfo )
|
|||||||
}
|
}
|
||||||
bIsInited = false;
|
bIsInited = false;
|
||||||
gpuInfo->mnIsUserCreated = 0;
|
gpuInfo->mnIsUserCreated = 0;
|
||||||
free( gpuInfo->mpArryDevsID );
|
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -325,46 +299,22 @@ bool buildProgram(const char* buildOption, GPUEnv* gpuInfo, int idx)
|
|||||||
cl_int clStatus;
|
cl_int clStatus;
|
||||||
//char options[512];
|
//char options[512];
|
||||||
// create a cl program executable for all the devices specified
|
// create a cl program executable for all the devices specified
|
||||||
if (!gpuInfo->mnIsUserCreated)
|
clStatus = clBuildProgram(gpuInfo->mpArryPrograms[idx], 1, &gpuInfo->mpDevID,
|
||||||
{
|
buildOption, NULL, NULL);
|
||||||
clStatus = clBuildProgram(gpuInfo->mpArryPrograms[idx], 1, gpuInfo->mpArryDevsID,
|
|
||||||
buildOption, NULL, NULL);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
clStatus = clBuildProgram(gpuInfo->mpArryPrograms[idx], 1, &(gpuInfo->mpDevID),
|
|
||||||
buildOption, NULL, NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( clStatus != CL_SUCCESS )
|
if ( clStatus != CL_SUCCESS )
|
||||||
{
|
{
|
||||||
size_t length;
|
size_t length;
|
||||||
if ( !gpuInfo->mnIsUserCreated )
|
clStatus = clGetProgramBuildInfo( gpuInfo->mpArryPrograms[idx], gpuInfo->mpDevID,
|
||||||
{
|
CL_PROGRAM_BUILD_LOG, 0, NULL, &length);
|
||||||
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);
|
|
||||||
}
|
|
||||||
if ( clStatus != CL_SUCCESS )
|
if ( clStatus != CL_SUCCESS )
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unique_ptr<char[]> buildLog(new char[length]);
|
std::unique_ptr<char[]> buildLog(new char[length]);
|
||||||
if ( !gpuInfo->mnIsUserCreated )
|
clStatus = clGetProgramBuildInfo( gpuInfo->mpArryPrograms[idx], gpuInfo->mpDevID,
|
||||||
{
|
CL_PROGRAM_BUILD_LOG, length, buildLog.get(), &length );
|
||||||
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 );
|
|
||||||
}
|
|
||||||
if ( clStatus != CL_SUCCESS )
|
if ( clStatus != CL_SUCCESS )
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
@@ -496,14 +446,14 @@ bool initOpenCLRunEnv( GPUEnv *gpuInfo )
|
|||||||
bool bKhrFp64 = false;
|
bool bKhrFp64 = false;
|
||||||
bool bAmdFp64 = false;
|
bool bAmdFp64 = false;
|
||||||
|
|
||||||
checkDeviceForDoubleSupport(gpuInfo->mpArryDevsID[0], bKhrFp64, bAmdFp64);
|
checkDeviceForDoubleSupport(gpuInfo->mpDevID, bKhrFp64, bAmdFp64);
|
||||||
|
|
||||||
gpuInfo->mnKhrFp64Flag = bKhrFp64;
|
gpuInfo->mnKhrFp64Flag = bKhrFp64;
|
||||||
gpuInfo->mnAmdFp64Flag = bAmdFp64;
|
gpuInfo->mnAmdFp64Flag = bAmdFp64;
|
||||||
|
|
||||||
gpuInfo->mnPreferredVectorWidthFloat = 0;
|
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);
|
&gpuInfo->mnPreferredVectorWidthFloat, NULL);
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
@@ -830,15 +780,6 @@ bool switchOpenCLDevice(const OUString* pDevice, bool bAutoSelect, bool bForceEv
|
|||||||
|
|
||||||
initOpenCLAttr(&env);
|
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);
|
return !initOpenCLRunEnv(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -3889,7 +3889,7 @@ void DynamicKernel::CreateKernel()
|
|||||||
SAL_INFO("sc.opencl", "Created program " << mpProgram);
|
SAL_INFO("sc.opencl", "Created program " << mpProgram);
|
||||||
|
|
||||||
err = clBuildProgram(mpProgram, 1,
|
err = clBuildProgram(mpProgram, 1,
|
||||||
::opencl::gpuEnv.mpArryDevsID, "", NULL, NULL);
|
&::opencl::gpuEnv.mpDevID, "", NULL, NULL);
|
||||||
if (err != CL_SUCCESS)
|
if (err != CL_SUCCESS)
|
||||||
{
|
{
|
||||||
#if OSL_DEBUG_LEVEL > 0
|
#if OSL_DEBUG_LEVEL > 0
|
||||||
@@ -3897,7 +3897,7 @@ void DynamicKernel::CreateKernel()
|
|||||||
{
|
{
|
||||||
cl_build_status stat;
|
cl_build_status stat;
|
||||||
cl_int e = clGetProgramBuildInfo(
|
cl_int e = clGetProgramBuildInfo(
|
||||||
mpProgram, ::opencl::gpuEnv.mpArryDevsID[0],
|
mpProgram, ::opencl::gpuEnv.mpDevID,
|
||||||
CL_PROGRAM_BUILD_STATUS, sizeof(cl_build_status),
|
CL_PROGRAM_BUILD_STATUS, sizeof(cl_build_status),
|
||||||
&stat, 0);
|
&stat, 0);
|
||||||
SAL_WARN_IF(
|
SAL_WARN_IF(
|
||||||
@@ -3909,7 +3909,7 @@ void DynamicKernel::CreateKernel()
|
|||||||
{
|
{
|
||||||
size_t n;
|
size_t n;
|
||||||
e = clGetProgramBuildInfo(
|
e = clGetProgramBuildInfo(
|
||||||
mpProgram, ::opencl::gpuEnv.mpArryDevsID[0],
|
mpProgram, ::opencl::gpuEnv.mpDevID,
|
||||||
CL_PROGRAM_BUILD_LOG, 0, 0, &n);
|
CL_PROGRAM_BUILD_LOG, 0, 0, &n);
|
||||||
SAL_WARN_IF(
|
SAL_WARN_IF(
|
||||||
e != CL_SUCCESS || n == 0, "sc.opencl",
|
e != CL_SUCCESS || n == 0, "sc.opencl",
|
||||||
@@ -3920,7 +3920,7 @@ void DynamicKernel::CreateKernel()
|
|||||||
{
|
{
|
||||||
std::vector<char> log(n);
|
std::vector<char> log(n);
|
||||||
e = clGetProgramBuildInfo(
|
e = clGetProgramBuildInfo(
|
||||||
mpProgram, ::opencl::gpuEnv.mpArryDevsID[0],
|
mpProgram, ::opencl::gpuEnv.mpDevID,
|
||||||
CL_PROGRAM_BUILD_LOG, n, &log[0], 0);
|
CL_PROGRAM_BUILD_LOG, n, &log[0], 0);
|
||||||
SAL_WARN_IF(
|
SAL_WARN_IF(
|
||||||
e != CL_SUCCESS || n == 0, "sc.opencl",
|
e != CL_SUCCESS || n == 0, "sc.opencl",
|
||||||
|
Reference in New Issue
Block a user