Lines Matching refs:clEnv
200 static inline void RelinquishMagickCLDevices(MagickCLEnv clEnv) in RelinquishMagickCLDevices() argument
205 if (clEnv->devices != (MagickCLDevice *) NULL) in RelinquishMagickCLDevices()
207 for (i = 0; i < clEnv->number_devices; i++) in RelinquishMagickCLDevices()
208 clEnv->devices[i]=RelinquishMagickCLDevice(clEnv->devices[i]); in RelinquishMagickCLDevices()
209 clEnv->devices=(MagickCLDevice *) RelinquishMagickMemory(clEnv->devices); in RelinquishMagickCLDevices()
211 clEnv->number_devices=0; in RelinquishMagickCLDevices()
377 static void SelectOpenCLDevice(MagickCLEnv clEnv,cl_device_type type) in SelectOpenCLDevice() argument
386 for (i = 0; i < clEnv->number_devices; i++) in SelectOpenCLDevice()
387 clEnv->devices[i]->enabled=MagickFalse; in SelectOpenCLDevice()
389 for (i = 0; i < clEnv->number_devices; i++) in SelectOpenCLDevice()
391 device=clEnv->devices[i]; in SelectOpenCLDevice()
396 for (j = i+1; j < clEnv->number_devices; j++) in SelectOpenCLDevice()
401 other_device=clEnv->devices[j]; in SelectOpenCLDevice()
608 clEnv; in AcquireMagickCLEnv() local
610 clEnv=(MagickCLEnv) AcquireMagickMemory(sizeof(*clEnv)); in AcquireMagickCLEnv()
611 if (clEnv != (MagickCLEnv) NULL) in AcquireMagickCLEnv()
613 (void) memset(clEnv,0,sizeof(*clEnv)); in AcquireMagickCLEnv()
614 ActivateSemaphoreInfo(&clEnv->lock); in AcquireMagickCLEnv()
615 clEnv->cpu_score=MAGICKCORE_OPENCL_UNDEFINED_SCORE; in AcquireMagickCLEnv()
616 clEnv->enabled=MagickTrue; in AcquireMagickCLEnv()
619 clEnv->enabled=MagickFalse; in AcquireMagickCLEnv()
621 return clEnv; in AcquireMagickCLEnv()
741 static void LoadOpenCLDeviceBenchmark(MagickCLEnv clEnv,const char *xml) in LoadOpenCLDeviceBenchmark() argument
809 clEnv->cpu_score=device_benchmark->score; in LoadOpenCLDeviceBenchmark()
818 for (i = 0; i < clEnv->number_devices; i++) in LoadOpenCLDeviceBenchmark()
820 device=clEnv->devices[i]; in LoadOpenCLDeviceBenchmark()
913 static MagickBooleanType LoadOpenCLBenchmarks(MagickCLEnv clEnv) in LoadOpenCLBenchmarks() argument
935 for (i = 0; i < clEnv->number_devices; i++) in LoadOpenCLBenchmarks()
936 clEnv->devices[i]->score=1.0; in LoadOpenCLBenchmarks()
938 SelectOpenCLDevice(clEnv,CL_DEVICE_TYPE_GPU); in LoadOpenCLBenchmarks()
943 LoadOpenCLDeviceBenchmark(clEnv,(const char *) GetStringInfoDatum(option)); in LoadOpenCLBenchmarks()
948 static void AutoSelectOpenCLDevices(MagickCLEnv clEnv) in AutoSelectOpenCLDevices() argument
966 SelectOpenCLDevice(clEnv,CL_DEVICE_TYPE_GPU); in AutoSelectOpenCLDevices()
968 SelectOpenCLDevice(clEnv,CL_DEVICE_TYPE_CPU); in AutoSelectOpenCLDevices()
971 for (i = 0; i < clEnv->number_devices; i++) in AutoSelectOpenCLDevices()
972 clEnv->devices[i]->enabled=MagickFalse; in AutoSelectOpenCLDevices()
973 clEnv->enabled=MagickFalse; in AutoSelectOpenCLDevices()
977 if (LoadOpenCLBenchmarks(clEnv) == MagickFalse) in AutoSelectOpenCLDevices()
981 if (clEnv->cpu_score == MAGICKCORE_OPENCL_UNDEFINED_SCORE) in AutoSelectOpenCLDevices()
985 for (i = 0; i < clEnv->number_devices; i++) in AutoSelectOpenCLDevices()
987 if (clEnv->devices[i]->score == MAGICKCORE_OPENCL_UNDEFINED_SCORE) in AutoSelectOpenCLDevices()
996 BenchmarkOpenCLDevices(clEnv); in AutoSelectOpenCLDevices()
998 best_score=clEnv->cpu_score; in AutoSelectOpenCLDevices()
999 for (i = 0; i < clEnv->number_devices; i++) in AutoSelectOpenCLDevices()
1000 best_score=MagickMin(clEnv->devices[i]->score,best_score); in AutoSelectOpenCLDevices()
1002 for (i = 0; i < clEnv->number_devices; i++) in AutoSelectOpenCLDevices()
1004 if (clEnv->devices[i]->score != best_score) in AutoSelectOpenCLDevices()
1005 clEnv->devices[i]->enabled=MagickFalse; in AutoSelectOpenCLDevices()
1104 static void RunDeviceBenckmark(MagickCLEnv clEnv,MagickCLEnv testEnv, in RunDeviceBenckmark() argument
1110 default_CLEnv=clEnv; in RunDeviceBenckmark()
1114 static void CacheOpenCLBenchmarks(MagickCLEnv clEnv) in CacheOpenCLBenchmarks() argument
1138 clEnv->cpu_score); in CacheOpenCLBenchmarks()
1139 for (i = 0; i < clEnv->number_devices; i++) in CacheOpenCLBenchmarks()
1144 device=clEnv->devices[i]; in CacheOpenCLBenchmarks()
1148 if (IsSameOpenCLDevice(clEnv->devices[j],device)) in CacheOpenCLBenchmarks()
1171 static void BenchmarkOpenCLDevices(MagickCLEnv clEnv) in BenchmarkOpenCLDevices() argument
1191 for (i = 0; i < clEnv->number_devices; i++) in BenchmarkOpenCLDevices()
1192 clEnv->devices[i]->score=MAGICKCORE_OPENCL_UNDEFINED_SCORE; in BenchmarkOpenCLDevices()
1194 for (i = 0; i < clEnv->number_devices; i++) in BenchmarkOpenCLDevices()
1196 device=clEnv->devices[i]; in BenchmarkOpenCLDevices()
1198 RunDeviceBenckmark(clEnv,testEnv,device); in BenchmarkOpenCLDevices()
1201 for (j = i+1; j < clEnv->number_devices; j++) in BenchmarkOpenCLDevices()
1206 other_device=clEnv->devices[j]; in BenchmarkOpenCLDevices()
1214 clEnv->cpu_score=RunOpenCLBenchmark(MagickTrue); in BenchmarkOpenCLDevices()
1215 default_CLEnv=clEnv; in BenchmarkOpenCLDevices()
1218 CacheOpenCLBenchmarks(clEnv); in BenchmarkOpenCLDevices()
1536 clEnv; in DumpOpenCLProfileData() local
1542 clEnv=GetCurrentOpenCLEnv(); in DumpOpenCLProfileData()
1543 if (clEnv == (MagickCLEnv) NULL) in DumpOpenCLProfileData()
1546 for (i = 0; i < clEnv->number_devices; i++) in DumpOpenCLProfileData()
1547 if (clEnv->devices[i]->profile_kernels != MagickFalse) in DumpOpenCLProfileData()
1549 if (i == clEnv->number_devices) in DumpOpenCLProfileData()
1557 for (i = 0; i < clEnv->number_devices; i++) in DumpOpenCLProfileData()
1562 device=clEnv->devices[i]; in DumpOpenCLProfileData()
1929 clEnv; in GetOpenCLDevices() local
1931 clEnv=GetCurrentOpenCLEnv(); in GetOpenCLDevices()
1932 if (clEnv == (MagickCLEnv) NULL) in GetOpenCLDevices()
1938 InitializeOpenCL(clEnv,exception); in GetOpenCLDevices()
1940 *length=clEnv->number_devices; in GetOpenCLDevices()
1941 return(clEnv->devices); in GetOpenCLDevices()
2029 clEnv; in GetOpenCLEnabled() local
2031 clEnv=GetCurrentOpenCLEnv(); in GetOpenCLEnabled()
2032 if (clEnv == (MagickCLEnv) NULL) in GetOpenCLEnabled()
2034 return(clEnv->enabled); in GetOpenCLEnabled()
2109 static MagickBooleanType HasOpenCLDevices(MagickCLEnv clEnv, in HasOpenCLDevices() argument
2126 for (i = 0; i < clEnv->number_devices; i++) in HasOpenCLDevices()
2128 if ((clEnv->devices[i]->enabled != MagickFalse)) in HasOpenCLDevices()
2131 if (i == clEnv->number_devices) in HasOpenCLDevices()
2136 for (i = 0; i < clEnv->number_devices; i++) in HasOpenCLDevices()
2138 if ((clEnv->devices[i]->enabled != MagickFalse) && in HasOpenCLDevices()
2139 (clEnv->devices[i]->program == (cl_program) NULL)) in HasOpenCLDevices()
2163 for (i = 0; i < clEnv->number_devices; i++) in HasOpenCLDevices()
2171 device=clEnv->devices[i]; in HasOpenCLDevices()
2218 static cl_uint GetOpenCLDeviceCount(MagickCLEnv clEnv,cl_platform_id platform) in GetOpenCLDeviceCount() argument
2226 if (clEnv->library->clGetPlatformInfo(platform,CL_PLATFORM_VERSION, in GetOpenCLDeviceCount()
2231 if (clEnv->library->clGetDeviceIDs(platform, in GetOpenCLDeviceCount()
2237 static void LoadOpenCLDevices(MagickCLEnv clEnv) in LoadOpenCLDevices() argument
2277 number_devices=GetOpenCLDeviceCount(clEnv,platforms[i]); in LoadOpenCLDevices()
2281 clEnv->number_devices+=number_devices; in LoadOpenCLDevices()
2283 if (clEnv->number_devices == 0) in LoadOpenCLDevices()
2288 clEnv->devices=(MagickCLDevice *) AcquireQuantumMemory(clEnv->number_devices, in LoadOpenCLDevices()
2290 if (clEnv->devices == (MagickCLDevice *) NULL) in LoadOpenCLDevices()
2292 RelinquishMagickCLDevices(clEnv); in LoadOpenCLDevices()
2296 (void) memset(clEnv->devices,0,clEnv->number_devices* in LoadOpenCLDevices()
2298 devices=(cl_device_id *) AcquireQuantumMemory(clEnv->number_devices, in LoadOpenCLDevices()
2303 RelinquishMagickCLDevices(clEnv); in LoadOpenCLDevices()
2306 clEnv->number_contexts=(size_t) number_platforms; in LoadOpenCLDevices()
2307 clEnv->contexts=(cl_context *) AcquireQuantumMemory(clEnv->number_contexts, in LoadOpenCLDevices()
2309 if (clEnv->contexts == (cl_context *) NULL) in LoadOpenCLDevices()
2313 RelinquishMagickCLDevices(clEnv); in LoadOpenCLDevices()
2322 status=clEnv->library->clGetDeviceIDs(platforms[i],CL_DEVICE_TYPE_CPU | in LoadOpenCLDevices()
2323 CL_DEVICE_TYPE_GPU,(cl_uint) clEnv->number_devices,devices,&number_devices); in LoadOpenCLDevices()
2330 clEnv->contexts[i]=openCL_library->clCreateContext(properties,number_devices, in LoadOpenCLDevices()
2344 device->context=clEnv->contexts[i]; in LoadOpenCLDevices()
2385 clEnv->devices[next]=device; in LoadOpenCLDevices()
2388 if (next != clEnv->number_devices) in LoadOpenCLDevices()
2389 RelinquishMagickCLDevices(clEnv); in LoadOpenCLDevices()
2394 MagickPrivate MagickBooleanType InitializeOpenCL(MagickCLEnv clEnv, in InitializeOpenCL() argument
2400 LockSemaphoreInfo(clEnv->lock); in InitializeOpenCL()
2401 if (clEnv->initialized != MagickFalse) in InitializeOpenCL()
2403 UnlockSemaphoreInfo(clEnv->lock); in InitializeOpenCL()
2404 return(HasOpenCLDevices(clEnv,exception)); in InitializeOpenCL()
2408 clEnv->library=openCL_library; in InitializeOpenCL()
2409 LoadOpenCLDevices(clEnv); in InitializeOpenCL()
2410 if (clEnv->number_devices > 0) in InitializeOpenCL()
2411 AutoSelectOpenCLDevices(clEnv); in InitializeOpenCL()
2413 clEnv->initialized=MagickTrue; in InitializeOpenCL()
2415 for (i=0; i < (ssize_t) clEnv->number_devices; i++) in InitializeOpenCL()
2417 if (strncmp(clEnv->devices[i]->platform_name,"NVIDIA",6) == 0) in InitializeOpenCL()
2418 clEnv->devices[i]->enabled=MagickFalse; in InitializeOpenCL()
2420 UnlockSemaphoreInfo(clEnv->lock); in InitializeOpenCL()
2421 return(HasOpenCLDevices(clEnv,exception)); in InitializeOpenCL()
2990 static MagickCLEnv RelinquishMagickCLEnv(MagickCLEnv clEnv) in RelinquishMagickCLEnv() argument
2992 if (clEnv == (MagickCLEnv) NULL) in RelinquishMagickCLEnv()
2995 RelinquishSemaphoreInfo(&clEnv->lock); in RelinquishMagickCLEnv()
2996 RelinquishMagickCLDevices(clEnv); in RelinquishMagickCLEnv()
2997 if (clEnv->contexts != (cl_context *) NULL) in RelinquishMagickCLEnv()
3002 for (i=0; i < clEnv->number_contexts; i++) in RelinquishMagickCLEnv()
3003 if (clEnv->contexts[i] != (cl_context) NULL) in RelinquishMagickCLEnv()
3004 (void) openCL_library->clReleaseContext(clEnv->contexts[i]); in RelinquishMagickCLEnv()
3005 clEnv->contexts=(cl_context *) RelinquishMagickMemory(clEnv->contexts); in RelinquishMagickCLEnv()
3007 return((MagickCLEnv) RelinquishMagickMemory(clEnv)); in RelinquishMagickCLEnv()
3032 MagickPrivate MagickCLDevice RequestOpenCLDevice(MagickCLEnv clEnv) in RequestOpenCLDevice() argument
3044 if (clEnv == (MagickCLEnv) NULL) in RequestOpenCLDevice()
3047 if (clEnv->number_devices == 1) in RequestOpenCLDevice()
3049 if (clEnv->devices[0]->enabled) in RequestOpenCLDevice()
3050 return(clEnv->devices[0]); in RequestOpenCLDevice()
3058 for (i = 0; i < clEnv->number_devices; i++) in RequestOpenCLDevice()
3060 if (clEnv->devices[i]->enabled == MagickFalse) in RequestOpenCLDevice()
3063 score=clEnv->devices[i]->score+(clEnv->devices[i]->score* in RequestOpenCLDevice()
3064 clEnv->devices[i]->requested); in RequestOpenCLDevice()
3067 device=clEnv->devices[i]; in RequestOpenCLDevice()
3171 clEnv; in SetOpenCLEnabled() local
3173 clEnv=GetCurrentOpenCLEnv(); in SetOpenCLEnabled()
3174 if (clEnv == (MagickCLEnv) NULL) in SetOpenCLEnabled()
3176 clEnv->enabled=value; in SetOpenCLEnabled()
3177 return(clEnv->enabled); in SetOpenCLEnabled()