示例#1
0
文件: myocl.cpp 项目: CGAnderson/Bolt
MyOclContext initOcl(cl_int clDeviceType, int deviceIndex, int verbose) 
{
	MyOclContext ocl;

	cl_int err;
	std::vector< cl::Platform > platformList;
	cl::Platform::get(&platformList);
	CHECK_OPENCL_ERROR(platformList.size()!=0 ? CL_SUCCESS : -1, "cl::Platform::get");
	if (verbose) {
		std::cerr << "info: Found: " << platformList.size() << " platforms." << std::endl;
	}

	//FIXME - add support for multiple vendors here, right now just pick the first platform.
	std::string platformVendor;
	platformList[0].getInfo((cl_platform_info)CL_PLATFORM_VENDOR, &platformVendor);
	if (verbose) {
		std::cout << "info: platform is: " << platformVendor << "\n";
	}
	cl_context_properties cprops[3] = 
	{CL_CONTEXT_PLATFORM, (cl_context_properties)(platformList[0])(), 0};



	cl::Context context(
		clDeviceType, 
		cprops,
		NULL,
		NULL,
		&err);
	CHECK_OPENCL_ERROR(err, "Context::Context()");  
	ocl._context = context;


	std::vector<cl::Device> devices;
	devices = context.getInfo<CL_CONTEXT_DEVICES>();
	CHECK_OPENCL_ERROR(
		devices.size() > 0 ? CL_SUCCESS : -1, "devices.size() > 0");


	if (0) {
		int deviceCnt = 0;
		std::for_each(devices.begin(), devices.end(), [&] (cl::Device &d) {
			std::cout << "#" << deviceCnt << "  ";
			printDevice(d);
			deviceCnt ++;
		});
	}

	if (verbose) {
		std::cout << "info: selected device #" << deviceIndex << "  ";
		printDevice(devices[deviceIndex]);
	}
	ocl._device = devices[deviceIndex];

	cl::CommandQueue q(ocl._context, ocl._device);
	ocl._queue = q;

	return ocl;
};
示例#2
0
文件: main.c 项目: quano1/FS
int main()
{
    srand(time(NULL));

    unsigned char arrCharDevice[MAX_DEVICE][DEVICE_SIZE];
    unsigned char chDevice[] = {0xb,0x0,'F','S','o','f','\0',0x0,0x1,0x0,0x0};
    int i,j;
    device **ppd;
    device *tmp;

    linkedlist ll;
    initializeLL(&ll);  //initialize linkedlist
    initArrayDeviceData(arrCharDevice, MAX_DEVICE, DEVICE_SIZE);    //create data array of device
    ppd = initArrayDevice(arrCharDevice, MAX_DEVICE, DEVICE_SIZE);  //create array of device

    for(i=0; i<MAX_DEVICE; i++) {
        printDevice(*(ppd+i));
        addFirst(&ll, *(ppd+i));    //insert device into linkedlist
    }

    FL; printLL(&ll);

    tmp = (device*)chDevice;
    FL;printDevice(tmp);

    insertElement(&ll, tmp, 5);            //insert above device into linkedlist
    FL;printLL(&ll);

    rmElement(&ll,4);                       //remove element from linkedlist
    FL;printLL(&ll);

    free(tmp);
    freeLL(&ll);
    freeArrayDevice(&ppd, MAX_DEVICE);

    unsigned short asdf = 0xF0AA;
    unsigned char *asda = (char*)malloc(sizeof(asdf));

    FL; PRINT_HEX(asdf); EL;
    printf("%X", asdf&0xff); EL;

    convertToChar(asda, &asdf, 0, sizeof(short));

    FL; PRINT_HEX(*asda); SP; PRINT_HEX(*(asda+1)); EL;

    PRINT_UINT(sizeof(aaa)); EL;

    return 0;
}
void createDevices(Devices& devices)
{
    std::pair<Devices::iterator, bool> insertPair = devices.insert(boost::make_shared<Device>(1));
    if (insertPair.second && insertPair.first != devices.end())
    {
        devices.modify(insertPair.first, Device::update_ip_address("192.168.1.10"));
        (*insertPair.first)->deviceType("hc800");
    }

    insertPair = devices.insert(boost::make_shared<Device>(2));
    if (insertPair.second && insertPair.first != devices.end())
    {
        devices.modify(insertPair.first, Device::update_ip_address("192.168.1.9"));
        (*insertPair.first)->deviceType("hc250");
    }

    insertPair = devices.insert(boost::make_shared<Device>(3));
    if (insertPair.second && insertPair.first != devices.end())
    {
        devices.modify(insertPair.first, Device::update_ip_address("192.168.1.8"));
        (*insertPair.first)->deviceType("c7");
    }

    std::cout << "indexed by device id" << std::endl;
    BOOST_FOREACH(const Device::Ptr device, devices)
    {
        printDevice(device);
    }
	void AudioMasterMind::printDevices() 
	{
		CoInitialize(NULL);

		IMMDeviceEnumerator* deviceEnumeratorPtr = NULL;
		HRESULT hr = CoCreateInstance(
			__uuidof(MMDeviceEnumerator), NULL, CLSCTX_ALL,
			__uuidof(IMMDeviceEnumerator),
			(void**)&deviceEnumeratorPtr
		);

		if (FAILED(hr)) 
		{
			BOOST_LOG_TRIVIAL(error) << "Failed to create IMMDeviceEnumerator hr:" << hr;
			return;
		}

		IMMDeviceCollection* deviceCollectionPtr = NULL;
		hr = deviceEnumeratorPtr->EnumAudioEndpoints(eAll, DEVICE_STATEMASK_ALL, &deviceCollectionPtr);

		if (FAILED(hr)) 
		{
			BOOST_LOG_TRIVIAL(error) << "Failed to enumerate audio endpoints ";
			return;
		}

		UINT deviceCount = 0;
		hr = deviceCollectionPtr->GetCount(&deviceCount);

		if (FAILED(hr)) 
		{
			BOOST_LOG_TRIVIAL(error) << "Failed to get the count of devices";
			return;
		}

		BOOST_LOG_TRIVIAL(info) << "Device Count is: " << deviceCount;


		for (unsigned int i = 0; i < deviceCount; ++i) 
		{
			IMMDevice* devicePtr = NULL;
			hr = deviceCollectionPtr->Item(i, &devicePtr);
			if (FAILED(hr))
			{
				BOOST_LOG_TRIVIAL(error) << "Failed to get item no. " << i;
				return;
			}

			printDevice(devicePtr);

		}


	}
示例#5
0
文件: myocl.cpp 项目: CGAnderson/Bolt
void printContext(const cl::Context &c) 
{
	cl_int numDevices = c.getInfo<CL_CONTEXT_NUM_DEVICES>();

	std::cout <<"Context: #devices=" << numDevices
		//<< ", props=" << c.getInfo<CL_CONTEXT_PROPERTIES>() 
		<< ", refCnt=" << c.getInfo<CL_CONTEXT_REFERENCE_COUNT>()
		<< "\n";

	std::vector<cl::Device> devices;
	devices = c.getInfo<CL_CONTEXT_DEVICES>();

	int deviceCnt = 0;
	std::for_each(devices.begin(), devices.end(), [&] (cl::Device &d) {
		std::cout << "#" << deviceCnt << "  ";
		printDevice(d);
		deviceCnt ++;
	}); 
};
示例#6
0
RKCaughtX11WindowPart::RKCaughtX11WindowPart (RKCaughtX11Window *window) : KParts::Part (0) {
	RK_TRACE (MISC);

	setComponentData (KGlobal::mainComponent ());

	setWidget (window);
	RKCaughtX11WindowPart::window = window;

	setXMLFile ("rkcatchedx11windowpart.rc");

	window->dynamic_size_action = new KToggleAction (i18n ("Draw area follows size of window"), window);
	connect (window->dynamic_size_action, SIGNAL (triggered()), window, SLOT (fixedSizeToggled()));
	actionCollection ()->addAction ("toggle_fixed_size", window->dynamic_size_action);
	window->actions_not_for_preview.append (window->dynamic_size_action);

	QAction *action;
	action = actionCollection ()->addAction ("set_fixed_size_1", window, SLOT (setFixedSize1()));
	action->setText (i18n ("Set fixed size 500x500"));
	window->actions_not_for_preview.append (action);
	action = actionCollection ()->addAction ("set_fixed_size_2", window, SLOT (setFixedSize2()));
	action->setText (i18n ("Set fixed size 1000x1000"));
	window->actions_not_for_preview.append (action);
	action = actionCollection ()->addAction ("set_fixed_size_3", window, SLOT (setFixedSize3()));
	action->setText (i18n ("Set fixed size 2000x2000"));
	window->actions_not_for_preview.append (action);
	action = actionCollection ()->addAction ("set_fixed_size_manual", window, SLOT (setFixedSizeManual()));
	action->setText (i18n ("Set specified fixed size..."));
	window->actions_not_for_preview.append (action);

	action = actionCollection ()->addAction ("plot_prev", window, SLOT (previousPlot()));
	window->actions_not_for_preview.append (action);
 	action->setText (i18n ("Previous plot"));
	action->setIcon (RKStandardIcons::getIcon (RKStandardIcons::ActionMoveLeft));
	window->plot_prev_action = (KAction*) action;
	action = actionCollection ()->addAction ("plot_first", window, SLOT (firstPlot()));
	window->actions_not_for_preview.append (action);
 	action->setText (i18n ("First plot"));
	action->setIcon (RKStandardIcons::getIcon (RKStandardIcons::ActionMoveFirst));
	window->plot_first_action = (KAction*) action;
	action = actionCollection ()->addAction ("plot_next", window, SLOT (nextPlot()));
	window->actions_not_for_preview.append (action);
 	action->setText (i18n ("Next plot"));
	action->setIcon (RKStandardIcons::getIcon (RKStandardIcons::ActionMoveRight));
	window->plot_next_action = (KAction*) action;
	action = actionCollection ()->addAction ("plot_last", window, SLOT (lastPlot()));
	window->actions_not_for_preview.append (action);
 	action->setText (i18n ("Last plot"));
	action->setIcon (RKStandardIcons::getIcon (RKStandardIcons::ActionMoveLast));
	window->plot_last_action = (KAction*) action;
	action = window->plot_list_action = new KSelectAction (i18n ("Go to plot"), 0);
	window->actions_not_for_preview.append (action);
	window->plot_list_action->setToolBarMode (KSelectAction::MenuMode);
	action->setIcon (RKStandardIcons::getIcon (RKStandardIcons::ActionListPlots));
	actionCollection ()->addAction ("plot_list", action);
	connect (action, SIGNAL (triggered(int)), window, SLOT (gotoPlot(int)));

	action = actionCollection ()->addAction ("plot_force_append", window, SLOT (forceAppendCurrentPlot()));
	window->actions_not_for_preview.append (action);
 	action->setText (i18n ("Append this plot"));
	action->setIcon (RKStandardIcons::getIcon (RKStandardIcons::ActionSnapshot));
	window->plot_force_append_action = (KAction*) action;
	action = actionCollection ()->addAction ("plot_remove", window, SLOT (removeCurrentPlot()));
	window->actions_not_for_preview.append (action);
 	action->setText (i18n ("Remove this plot"));
	action->setIcon (RKStandardIcons::getIcon (RKStandardIcons::ActionRemovePlot));
	window->plot_remove_action = (KAction*) action;

	action = actionCollection ()->addAction ("plot_clear_history", window, SLOT (clearHistory()));
	window->plot_clear_history_action = (KAction*) action;
 	action->setText (i18n ("Clear history"));
	action->setIcon (RKStandardIcons::getIcon (RKStandardIcons::ActionClear));
	window->actions_not_for_preview.append (action);

	action = actionCollection ()->addAction ("plot_properties", window, SLOT (showPlotInfo()));
	window->plot_properties_action = (KAction*) action;
	action->setText (i18n ("Plot properties"));
	action->setIcon (RKStandardIcons::getIcon (RKStandardIcons::ActionDocumentInfo));
	window->actions_not_for_preview.append (action);

	action = actionCollection ()->addAction ("device_activate", window, SLOT (activateDevice()));
	action->setText (i18n ("Make active"));
	action->setIcon (RKStandardIcons::getIcon (RKStandardIcons::ActionFlagGreen));
	window->actions_not_for_preview.append (action);
	action = actionCollection ()->addAction ("device_copy_to_output", window, SLOT (copyDeviceToOutput()));
	action->setText (i18n ("Copy to output"));
	action->setIcon (RKStandardIcons::getIcon (RKStandardIcons::WindowOutput));
	action = actionCollection ()->addAction (KStandardAction::Print, "device_print", window, SLOT (printDevice()));
	action = actionCollection ()->addAction ("device_copy_to_r_object", window, SLOT (copyDeviceToRObject()));
	action->setText (i18n ("Store as R object..."));
	action = actionCollection ()->addAction ("device_duplicate", window, SLOT (duplicateDevice()));
	action->setText (i18n ("Duplicate"));
	action->setIcon (RKStandardIcons::getIcon (RKStandardIcons::ActionWindowDuplicate));

	action = window->stop_interaction = actionCollection ()->addAction ("stop_interaction", window, SLOT (stopInteraction()));
	action->setText (i18n ("Stop interaction"));
	action->setIcon (RKStandardIcons::getIcon (RKStandardIcons::ActionInterrupt));
	action->setVisible (false);

	// initialize context for plugins
	RKComponentGUIXML *context = RKComponentMap::getContext ("x11");
	if (!context) return;
	RKContextHandler *context_handler = context->makeContextHandler (this);
	insertChildClient (context_handler);
	RKComponentPropertyInt *devnum_property = new RKComponentPropertyInt (this, false, 0);
	devnum_property->setIntValue (window->device_number);
	context_handler->addChild ("devnum", devnum_property);
}