Exemplo n.º 1
0
void checkOpenCL()
{
	DevicesInfo devices;
	getOpenCLDevices(devices);

	for (size_t i = 0; i < devices.size(); i++)
	{
		const DeviceInfo *info = devices[i];
		printf("%s : %s\nMax Compute unit:%d\n%s\n%s", 
			info->deviceName.c_str(), info->deviceVersion.c_str(), info->maxComputeUnits, 
			info->compilationExtraOptions.c_str(),
			info->deviceExtensions.c_str());
	}
}
Exemplo n.º 2
0
void checkOpenCL()
{
	PlatformsInfo platforms;
	getOpenCLPlatforms(platforms);

	for (size_t p = 0; p < platforms.size(); p++)
	{
		DevicesInfo devices;
		getOpenCLDevices(devices, CVCL_DEVICE_TYPE_GPU, platforms[p]);

		for (size_t i = 0; i < devices.size(); i++)
		{
		    	const DeviceInfo *info = devices[i];
		    	printf("%s : %s\n", info->deviceName.c_str(), info->deviceVersion.c_str());
		}
	}
}
Exemplo n.º 3
0
// ResourceUsageWindow::InitWindow -- Initialization Commands here
void ResourceUsageWindow::InitWindow(BList &list)
{
	BRect rtab = Bounds();
	BRect rlist = Bounds();
	rtab.top += 10;
	rlist.top += 10;
	rlist.left += 12;
	rlist.right -= 15 + B_V_SCROLL_BAR_WIDTH;
	rlist.bottom -= 47;

	// Create the TabView and Tabs
	BTabView *tabView = new BTabView(rtab,"resource_usage_tabview");
	tabView->SetViewUIColor(B_PANEL_BACKGROUND_COLOR);
	
	rtab = tabView->Bounds();
	rtab.InsetBy(5,5);
	
	// Create the ListViews
	BListView *IRQListView = new BListView(rlist, "IRQListView",
		B_SINGLE_SELECTION_LIST, B_FOLLOW_LEFT | B_FOLLOW_TOP,
		B_WILL_DRAW | B_NAVIGABLE);
	BListView *DMAListView = new BListView(rlist, "DMAListView",
		B_SINGLE_SELECTION_LIST, B_FOLLOW_LEFT | B_FOLLOW_TOP,
		B_WILL_DRAW | B_NAVIGABLE);
	BListView *IORangeListView = new BListView(rlist, "IORangeListView",
		B_SINGLE_SELECTION_LIST, B_FOLLOW_LEFT | B_FOLLOW_TOP,
		B_WILL_DRAW | B_NAVIGABLE);
	BListView *memoryListView = new BListView(rlist, "memoryListView",
		B_SINGLE_SELECTION_LIST, B_FOLLOW_LEFT | B_FOLLOW_TOP,
		B_WILL_DRAW | B_NAVIGABLE);
	
	BScrollView *IRQScrollView = new BScrollView("scroll_list1", IRQListView,
		B_FOLLOW_LEFT|B_FOLLOW_TOP, 0, false, true, B_FANCY_BORDER);
	BScrollView *DMAScrollView = new BScrollView("scroll_list2", DMAListView,
		B_FOLLOW_LEFT|B_FOLLOW_TOP, 0, false, true, B_FANCY_BORDER);
	BScrollView *IORangeScrollView = new BScrollView("scroll_list3",
		IORangeListView, B_FOLLOW_LEFT|B_FOLLOW_TOP, 0, false, true,
		B_FANCY_BORDER);
	BScrollView *memoryScrollView = new BScrollView("scroll_list4",
		memoryListView, B_FOLLOW_LEFT|B_FOLLOW_TOP, 0, false, true,
		B_FANCY_BORDER);
	
	BTab *tab = new BTab();
	tabView->AddTab(IRQScrollView, tab);
	tab->SetLabel(B_TRANSLATE("IRQ"));
	tab = new BTab();
	tabView->AddTab(DMAScrollView, tab);
	tab->SetLabel(B_TRANSLATE("DMA"));
	tab = new BTab();
	tabView->AddTab(IORangeScrollView, tab);
	tab->SetLabel(B_TRANSLATE("IO Range"));
	tab = new BTab();
	tabView->AddTab(memoryScrollView, tab);
	tab->SetLabel(B_TRANSLATE("Memory Range"));
	
	{
		uint32 mask = 1;
		
		for (int i=0;i<16;mask<<=1,i++) {
			bool first = true;
			
			for (int32 j=0; j<list.CountItems(); j++) {
				DevicesInfo *deviceInfo = (DevicesInfo *)list.ItemAt(j);
				struct device_configuration *current = deviceInfo->GetCurrent();
				resource_descriptor r;
				
				int32 num = count_resource_descriptors_of_type(current,
					B_IRQ_RESOURCE);
				
				for (int32 k=0;k<num;k++) {
					get_nth_resource_descriptor_of_type(current, k, B_IRQ_RESOURCE,
							&r, sizeof(resource_descriptor));
					
					if (mask & r.d.m.mask) {
						IRQListView->AddItem(new IRQDMAItem(first ? i : -1,
							deviceInfo->GetCardName()));
						first = false;
					}
				}
			}
			
			if (first) {
				IRQListView->AddItem(new IRQDMAItem(i, ""));
			}
		}
	}
	
	{
		uint32 mask = 1;
		
		for (int i=0;i<8;mask<<=1,i++) {
			bool first = true;
			
			for (int32 j=0; j<list.CountItems(); j++) {
				DevicesInfo *deviceInfo = (DevicesInfo *)list.ItemAt(j);
				struct device_configuration *current = deviceInfo->GetCurrent();
				resource_descriptor r;
				
				int32 num = count_resource_descriptors_of_type(current,
					B_DMA_RESOURCE);
				
				for (int32 k=0;k<num;k++) {
					get_nth_resource_descriptor_of_type(current, k,
						B_DMA_RESOURCE,	&r, sizeof(resource_descriptor));
					
					if (mask & r.d.m.mask) {
						DMAListView->AddItem(new IRQDMAItem(first ? i : -1,
							deviceInfo->GetCardName()));
						first = false;
					}
				}
			}
			
			if (first) {
				DMAListView->AddItem(new IRQDMAItem(i, ""));
			}
		}
	}

	{
		for (int32 j=0; j<list.CountItems(); j++) {
			DevicesInfo *deviceInfo = (DevicesInfo *)list.ItemAt(j);
			struct device_configuration *current = deviceInfo->GetCurrent();
			resource_descriptor r;
			
			int32 num = count_resource_descriptors_of_type(current,
				B_IO_PORT_RESOURCE);
			
			for (int32 k=0;k<num;k++) {
				get_nth_resource_descriptor_of_type(current, k,
					B_IO_PORT_RESOURCE,	&r, sizeof(resource_descriptor));
				
				IORangeListView->AddItem(new RangeItem(r.d.r.minbase, 
					r.d.r.minbase + r.d.r.len - 1, deviceInfo->GetCardName()));
			}
		}
	
		IORangeListView->SortItems(&RangeItem::Compare);
	}
	
	{
		for (int32 j=0; j<list.CountItems(); j++) {
			DevicesInfo *deviceInfo = (DevicesInfo *)list.ItemAt(j);
			struct device_configuration *current = deviceInfo->GetCurrent();
			resource_descriptor r;
			
			int32 num = count_resource_descriptors_of_type(current,
				B_MEMORY_RESOURCE);
			
			for (int32 k=0;k<num;k++) {
				get_nth_resource_descriptor_of_type(current, k, B_MEMORY_RESOURCE,
						&r, sizeof(resource_descriptor));
				
				memoryListView->AddItem(new RangeItem(r.d.r.minbase, 
					r.d.r.minbase + r.d.r.len - 1, deviceInfo->GetCardName()));
			}
		}
	
		memoryListView->SortItems(&RangeItem::Compare);
	}
	
	
	BBox *background = new BBox(Bounds(), "background");
	background->SetBorder(B_NO_BORDER);
	AddChild(background);
	background->AddChild(tabView);
}
Exemplo n.º 4
0
static PyObject*
select_ocl_device(PyObject *self, PyObject *arg) {
    int preferred_device_num = PyInt_AsLong(arg);

    cl_platform_id platforms[32];
    cl_uint n_platforms;
    cl_device_id *devices;
    cl_uint n_devices;
    char p_prof[1024];
    cl_uint d_vendor_id;
    char d_vers[1024];
    char d_prof[1024];
    size_t d_max_work_group_size;
    size_t d_max_work_item_sizes[3];
    int d_num = 0;

    cl_safe(clGetPlatformIDs(32, platforms, &n_platforms));

    for (int i = 0; i < n_platforms; i++) {
        cl_safe(clGetPlatformInfo(platforms[i], CL_PLATFORM_PROFILE, 1024,
                                  p_prof, NULL));

        cl_safe(clGetDeviceIDs(platforms[i], CL_DEVICE_TYPE_ALL, 0, NULL,
                               &n_devices));

        devices = (cl_device_id*)calloc(sizeof(cl_device_id), n_devices);
        cl_safe(clGetDeviceIDs(platforms[i], CL_DEVICE_TYPE_ALL, n_devices,
                               devices, NULL));

        for (int j = 0; j < n_devices; j++) {
            cl_device_id d = devices[j];
            cl_safe(clGetDeviceInfo(d, CL_DEVICE_VENDOR_ID, sizeof(d_vendor_id), &d_vendor_id, NULL));
            cl_safe(clGetDeviceInfo(d, CL_DEVICE_VERSION, 1024, d_vers, NULL));
            cl_safe(clGetDeviceInfo(d, CL_DEVICE_PROFILE, 1024, d_prof, NULL));
            cl_safe(clGetDeviceInfo(d, CL_DEVICE_MAX_WORK_GROUP_SIZE,
                                    sizeof(d_max_work_group_size),
                                    &d_max_work_group_size, NULL));
            cl_safe(clGetDeviceInfo(d, CL_DEVICE_MAX_WORK_ITEM_SIZES,
                                    sizeof(d_max_work_item_sizes),
                                    &d_max_work_item_sizes, NULL));

            if (d_num == preferred_device_num) {
                bool found_device = false;
                DevicesInfo devicesInfo;
                getOpenCLDevices(devicesInfo, CVCL_DEVICE_TYPE_ALL, NULL);
                for(vector<const DeviceInfo*>::iterator it = devicesInfo.begin(); it != devicesInfo.end(); ++it) {
                    const DeviceInfo *deviceInfo = *it;
                    if (deviceInfo->deviceVendorId == d_vendor_id) {
                        setDevice(deviceInfo);
                        found_device = true;
                        break;
                    }
                }
                free(devices);
                if (!found_device) {
                    PyErr_SetString(PyExc_RuntimeError, "Couldn't set the device");
                    return (PyObject*)NULL;
                }
                if (ocl_device_is_compatible(d_vers, d_prof, p_prof,
                                             d_max_work_group_size,
                                             d_max_work_item_sizes)) {
                    Py_RETURN_TRUE;
                } else {
                    PyErr_SetString(PyExc_ValueError, "Selected an incompatible device");
                    return (PyObject*)NULL;
                }
            }
            d_num++;
        }
        free(devices);
    }
    PyErr_SetString(PyExc_IndexError, "Invalid device number");
    return (PyObject*)NULL;
}
Exemplo n.º 5
0
	matches im_utility::diff(const std::string &im_file1, const std::string &im_file2, const parameters &params, key_points *im1_kps, key_points *im2_kps)
	{
		using namespace cv;
		matches mt;
		std::vector<KeyPoint> im1_key_points, im2_key_points;
		std::vector<DMatch> matches;
		std::vector<DMatch> good_matches;

		double min_hessian = 400.0;
		if (params.find(key_hessian_threshold) != params.end()) min_hessian = params.at(key_hessian_threshold);
		double sigma = 2.0;
		if (params.find(key_match_threshold) != params.end()) sigma = params.at(key_match_threshold);
		int speedup = speedup_default;
		if (params.find(key_speedup) != params.end())
			speedup = params.at(key_speedup);

		//auto info = getBuildInformation();
		
		if (speedup == speedup_use_cuda)
		{
			using namespace gpu;
			DeviceInfo dev;
			auto name = dev.name();
			GpuMat img1, img2;

			// upload data
			img1.upload(imread(im_file1, CV_LOAD_IMAGE_GRAYSCALE));
			img2.upload(imread(im_file2, CV_LOAD_IMAGE_GRAYSCALE));

			// detect keypoints & computing descriptors
			SURF_GPU surf;
			GpuMat kps_gpu1, kps_gpu2;
			GpuMat desc_gpu1, desc_gpu2;

			surf(img1, GpuMat(), kps_gpu1, desc_gpu1);
			surf(img2, GpuMat(), kps_gpu2, desc_gpu2);

			// matching descriptors
			BFMatcher_GPU matcher_gpu(NORM_L2);
			GpuMat trainIdx, distance;
			matcher_gpu.matchSingle(desc_gpu1, desc_gpu2, trainIdx, distance);

			// download results
			std::vector<float> desc1, desc2;
			surf.downloadKeypoints(kps_gpu1, im1_key_points);
			surf.downloadKeypoints(kps_gpu2, im2_key_points);
			surf.downloadDescriptors(desc_gpu1, desc1);
			surf.downloadDescriptors(desc_gpu2, desc2);
			BFMatcher_GPU::matchDownload(trainIdx, distance, matches);

			good_matches = matches;
		}
		else if (speedup == speedup_use_ocl)
		{
			using namespace ocl;
			DevicesInfo devs;
			getOpenCLDevices(devs, CVCL_DEVICE_TYPE_GPU);

			int dev = 0;
			if (params.find(key_ocl_dev) != params.end())
				dev = params.at(key_ocl_dev);

 			if (dev < 0 || dev >= devs.size()) dev = 0;
			setDevice(devs[dev]);

			SURF_OCL surf(800.0);
			BFMatcher_OCL matcher(NORM_L2);
			oclMat desc1, desc2;
			oclMat im1, im2;
			im1 = imread(im_file1, CV_LOAD_IMAGE_GRAYSCALE);
			im2 = imread(im_file2, CV_LOAD_IMAGE_GRAYSCALE);
			surf(im1, oclMat(), im1_key_points, desc1);
			surf(im2, oclMat(), im2_key_points, desc2);
			matcher.match(desc1, desc2, matches);

			double max_dist = 0;
			double min_dist = 100;
			for (int i = 0; i < desc1.rows; i++)
			{
				double dist = matches[i].distance;
				if (dist < min_dist) min_dist = dist;
				if (dist > max_dist) max_dist = dist;
			}

			for (int i = 0; i < desc1.rows; i++)
			{
				if (matches[i].distance <= max(sigma * min_dist, 0.02))
				{
					good_matches.push_back(matches[i]);
				}
			}
		}
		else
		{
			auto get_file_desc = [](const std::string &filename, double min_hessian, std::vector<cv::KeyPoint> *out_key_points)
			{
				using namespace cv;
				Mat desc;
				Mat img = imread(filename, CV_LOAD_IMAGE_GRAYSCALE);
				if (!img.data) return desc;

				SurfFeatureDetector detecter(min_hessian);

				std::vector<KeyPoint> key_points;
				detecter.detect(img, key_points);

				if (out_key_points) *out_key_points = key_points;

				if (key_points.empty())
				{
					std::cout << "no feature detected: " << filename << std::endl;
					return desc;
				}

				SurfDescriptorExtractor extractor;
				extractor.compute(img, key_points, desc);

				return desc;
			};

			auto im1_desc = get_file_desc(im_file1, min_hessian, &im1_key_points);
			auto im2_desc = get_file_desc(im_file2, min_hessian, &im2_key_points);
			
			FlannBasedMatcher matcher;

			matcher.match(im1_desc, im2_desc, matches);

			double max_dist = 0;
			double min_dist = 100;
			for (int i = 0; i < im1_desc.rows; i++)
			{
				double dist = matches[i].distance;
				if (dist < min_dist) min_dist = dist;
				if (dist > max_dist) max_dist = dist;
			}

			for (int i = 0; i < im1_desc.rows; i++)
			{
				if (matches[i].distance <= max(sigma * min_dist, 0.02))
				{
					good_matches.push_back(matches[i]);
				}
			}
		}

		auto conv_keypoint = [](const std::vector<KeyPoint> &kps)
		{
			key_points out;
			std::transform(kps.begin(), kps.end(), std::back_inserter(out), [](const KeyPoint &kp){
				//return key_point{ kp.pt.x, kp.pt.y, kp.size, kp.angle };
				key_point p;
				p.x = kp.pt.x;
				p.y = kp.pt.y;
				p.size = kp.size;
				p.angle = kp.angle;
				return p;
			});
			return out;
		};

		auto kps1 = conv_keypoint(im1_key_points);
		auto kps2 = conv_keypoint(im2_key_points);

		if (im1_kps)
			*im1_kps = kps1;
		if (im2_kps)
			*im2_kps = kps2;

		std::transform(good_matches.begin(), good_matches.end(), std::back_inserter(mt), [&](const DMatch &m)
		{
			//return match{ kps1[m.queryIdx] , kps2[m.trainIdx] , m.distance };
			match ma;
			ma.pt1 = kps1[m.queryIdx];
			ma.pt2 = kps2[m.trainIdx];
			ma.distance = m.distance;
			return ma;
		});

		return mt;
	}
Exemplo n.º 6
0
static bool selectOpenCLDevice()
{
    std::string platform;
    std::vector<std::string> deviceTypes;
    std::string deviceName;
    const char* configuration = getenv("OPENCV_OPENCL_DEVICE");
    if (configuration)
    {
        if (!parseOpenCLDeviceConfiguration(std::string(configuration), platform, deviceTypes, deviceName))
            return false;
    }

    bool isID = false;
    int deviceID = -1;
    if (deviceName.length() == 1)
    // We limit ID range to 0..9, because we want to write:
    // - '2500' to mean i5-2500
    // - '8350' to mean AMD FX-8350
    // - '650' to mean GeForce 650
    // To extend ID range change condition to '> 0'
    {
        isID = true;
        for (size_t i = 0; i < deviceName.length(); i++)
        {
            if (!isdigit(deviceName[i]))
            {
                isID = false;
                break;
            }
        }
        if (isID)
        {
            deviceID = atoi(deviceName.c_str());
            CV_Assert(deviceID >= 0);
        }
    }

    const PlatformInfo* platformInfo = NULL;
    if (platform.length() > 0)
    {
        PlatformsInfo platforms;
        getOpenCLPlatforms(platforms);
        for (size_t i = 0; i < platforms.size(); i++)
        {
            if (platforms[i]->platformName.find(platform) != std::string::npos)
            {
                platformInfo = platforms[i];
                break;
            }
        }
        if (platformInfo == NULL)
        {
            std::cerr << "ERROR: Can't find OpenCL platform by name: " << platform << std::endl;
            goto not_found;
        }
    }

    if (deviceTypes.size() == 0)
    {
        if (!isID)
        {
            deviceTypes.push_back("GPU");
            deviceTypes.push_back("CPU");
        }
        else
        {
            deviceTypes.push_back("ALL");
        }
    }
    for (size_t t = 0; t < deviceTypes.size(); t++)
    {
        int deviceType = 0;
        if (deviceTypes[t] == "GPU")
        {
            deviceType = CVCL_DEVICE_TYPE_GPU;
        }
        else if (deviceTypes[t] == "CPU")
        {
            deviceType = CVCL_DEVICE_TYPE_CPU;
        }
        else if (deviceTypes[t] == "ACCELERATOR")
        {
            deviceType = CVCL_DEVICE_TYPE_ACCELERATOR;
        }
        else if (deviceTypes[t] == "ALL")
        {
            deviceType = CVCL_DEVICE_TYPE_ALL;
        }
        else
        {
            std::cerr << "ERROR: Unsupported device type for OpenCL device (GPU, CPU, ACCELERATOR): " << deviceTypes[t] << std::endl;
            goto not_found;
        }

        DevicesInfo devices;
        getOpenCLDevices(devices, deviceType, platformInfo);

        for (size_t i = (isID ? deviceID : 0);
             (isID ? (i == (size_t)deviceID) : true) && (i < devices.size());
             i++)
        {
            if (isID || devices[i]->deviceName.find(deviceName) != std::string::npos)
            {
                // check for OpenCL 1.1
                if (devices[i]->deviceVersionMajor < 1 ||
                        (devices[i]->deviceVersionMajor == 1 && devices[i]->deviceVersionMinor < 1))
                {
                    std::cerr << "Skip unsupported version of OpenCL device: " << devices[i]->deviceName
                            << "(" << devices[i]->platform->platformName << ")" << std::endl;
                    continue; // unsupported version of device, skip it
                }
                try
                {
                    setDevice(devices[i]);
                }
                catch (...)
                {
                    std::cerr << "ERROR: Can't select OpenCL device: " << devices[i]->deviceName
                            << "(" << devices[i]->platform->platformName << ")" << std::endl;
                    goto not_found;
                }
                return true;
            }
        }
    }
not_found:
    std::cerr << "ERROR: Required OpenCL device not found, check configuration: " << (configuration == NULL ? "" : configuration) << std::endl
            << "    Platform: " << (platform.length() == 0 ? "any" : platform) << std::endl
            << "    Device types: ";
    for (size_t t = 0; t < deviceTypes.size(); t++)
    {
        std::cerr << deviceTypes[t] << " ";
    }
    std::cerr << std::endl << "    Device name: " << (deviceName.length() == 0 ? "any" : deviceName) << std::endl;
    return false;
}