Exemplo n.º 1
0
        void oclLogPtx(cl_program cpProgram, cl_device_id cdDevice, const char* cPtxFileName)
        {
            // Grab the number of devices associated with the program
            cl_uint num_devices;
            clGetProgramInfo(cpProgram, CL_PROGRAM_NUM_DEVICES, sizeof(cl_uint), &num_devices, NULL);
            
            // Grab the device ids
            cl_device_id* devices = (cl_device_id*) malloc(num_devices * sizeof(cl_device_id));
            clGetProgramInfo(cpProgram, CL_PROGRAM_DEVICES, num_devices * sizeof(cl_device_id), devices, 0);
            
            // Grab the sizes of the binaries
            size_t* binary_sizes = (size_t*)malloc(num_devices * sizeof(size_t));
            clGetProgramInfo(cpProgram, CL_PROGRAM_BINARY_SIZES, num_devices * sizeof(size_t), binary_sizes, NULL);
            
            // Now get the binaries
            char** ptx_code = (char**)malloc(num_devices * sizeof(char*));
            for( unsigned int i=0; i<num_devices; ++i)
            {
                ptx_code[i] = (char*)malloc(binary_sizes[i]);
            }
            clGetProgramInfo(cpProgram, CL_PROGRAM_BINARIES, 0, ptx_code, NULL);
            
            // Find the index of the device of interest
            unsigned int idx = 0;
            while((idx < num_devices) && (devices[idx] != cdDevice))
            {
                ++idx;
            }
            
            // If the index is associated, log the result
            if(idx < num_devices)
            {
                // if a separate filename is supplied, dump ptx there
                if (NULL != cPtxFileName)
                {
                    LogErrorArg1("Writing ptx to separate file: %s ...", cPtxFileName);
                    FILE* pFileStream = NULL;
#ifdef _WIN32
                    fopen_s(&pFileStream, cPtxFileName, "wb");
#else
                    pFileStream = fopen(cPtxFileName, "wb");
#endif
                    
                    fwrite(ptx_code[idx], binary_sizes[idx], 1, pFileStream);
                    fclose(pFileStream);
                }
                else
                    LogErrorArg1("Program Binary:%s ", ptx_code[idx]);
            }
            
            // Cleanup
            free(devices);
            free(binary_sizes);
            for(unsigned int i = 0; i < num_devices; ++i)
            {
                free(ptx_code[i]);
            }
            free( ptx_code );
        }
Exemplo n.º 2
0
 cl_int oclPlatformID(cl_platform_id* clSelectedPlatformID, const char* lpStrProvider)
 {
     char chBuffer[1024];
     cl_uint num_platforms;
     cl_platform_id* clPlatformIDs;
     cl_int ciErrNum;
     *clSelectedPlatformID = NULL;
     
     // Get OpenCL platform count
     ciErrNum = clGetPlatformIDs (0, NULL, &num_platforms);
     if (ciErrNum != CL_SUCCESS)
     {
         LogErrorArg1("Error code: %i in clGetPlatformIDs Call!!", ciErrNum);
         return -1000;
     }
     else
     {
         if(num_platforms == 0)
         {
             LogError("No OpenCL platform found!");
             return -2000;
         }
         else
         {
             // if there's a platform or more, make space for ID's
             if ((clPlatformIDs = (cl_platform_id*)malloc(num_platforms * sizeof(cl_platform_id))) == NULL)
             {
                 LogError("Failed to allocate memory for cl_platform ID's!");
                 return -3000;
             }
             
             // get platform info for each platform and trap the NVIDIA platform if found
             ciErrNum = clGetPlatformIDs (num_platforms, clPlatformIDs, NULL);
             for(cl_uint i = 0; i < num_platforms; ++i)
             {
                 ciErrNum = clGetPlatformInfo (clPlatformIDs[i], CL_PLATFORM_NAME, 1024, &chBuffer, NULL);
                 if(ciErrNum == CL_SUCCESS)
                 {
                     if(strstr(chBuffer, lpStrProvider) != NULL)
                     {
                         *clSelectedPlatformID = clPlatformIDs[i];
                         break;
                     }
                 }
             }
             
             // default to zeroeth platform if NVIDIA not found
             if(*clSelectedPlatformID == NULL)
             {
                 LogWarningArg1("%s OpenCL platform not found - defaulting to first platform!", lpStrProvider);
                 *clSelectedPlatformID = clPlatformIDs[0];
             }
             
             free(clPlatformIDs);
         }
     }
     
     return CL_SUCCESS;
 }
Exemplo n.º 3
0
bool SceneGraph::readConfig(const AnsiStr& strFP) {
	if(!FileExists(strFP)) {
		LogErrorArg1("File %s not found to read scene config.", strFP.cptr());
		return false;
	}

	SettingsScript* script = new SettingsScript(strFP, SettingsScript::fmRead);
	m_camera.setRoll(script->readFloat("camera", "roll"));
	m_camera.setTilt(script->readFloat("camera", "tilt"));
	m_camera.setZoom(script->readFloat("camera", "zoom"));
	m_camera.setPan(script->readVec2f("camera", "pan"));

	SAFE_DELETE(script);

	return true;
}