本文整理汇总了C++中Platform::getDevices方法的典型用法代码示例。如果您正苦于以下问题:C++ Platform::getDevices方法的具体用法?C++ Platform::getDevices怎么用?C++ Platform::getDevices使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Platform
的用法示例。
在下文中一共展示了Platform::getDevices方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(void)
{
try {
/*
* First Forge call should be a window creation call
* so that necessary OpenGL context is created for any
* other fg::* object to be created successfully
*/
fg::Window wnd(DIMX, DIMY, "Fractal Demo");
wnd.makeCurrent();
/* create an font object and load necessary font
* and later pass it on to window object so that
* it can be used for rendering text */
fg::Font fnt;
#ifdef OS_WIN
fnt.loadSystemFont("Calibri", 32);
#else
fnt.loadSystemFont("Vera", 32);
#endif
wnd.setFont(&fnt);
/*
* Split the window into grid regions
*/
wnd.grid(WIN_ROWS, WIN_COLS);
/* Create several plot objects which creates the necessary
* vertex buffer objects to hold the different plot types
*/
fg::Plot plt0(SIZE, fg::f32); //create a default plot
fg::Plot plt1(SIZE, fg::f32, fg::FG_LINE, fg::FG_NONE); //or specify a specific plot type
fg::Plot plt2(SIZE, fg::f32, fg::FG_LINE, fg::FG_TRIANGLE); //last parameter specifies marker shape
fg::Plot plt3(SIZE, fg::f32, fg::FG_SCATTER, fg::FG_POINT);
/*
* Set plot colors
*/
plt0.setColor(fg::FG_YELLOW);
plt1.setColor(fg::FG_BLUE);
plt2.setColor(fg::FG_WHITE); //use a forge predefined color
plt3.setColor((fg::Color) 0xABFF01FF); //or any hex-valued color
/*
* Set draw limits for plots
*/
plt0.setAxesLimits(FRANGE_END, FRANGE_START, 1.1f, -1.1f);
plt1.setAxesLimits(FRANGE_END, FRANGE_START, 1.1f, -1.1f);
plt2.setAxesLimits(FRANGE_END, FRANGE_START, 1.1f, -1.1f);
plt3.setAxesLimits(FRANGE_END, FRANGE_START, 1.1f, -1.1f);
Platform plat = getPlatform();
// Select the default platform and create a context using this platform and the GPU
#if defined(OS_MAC)
CGLContextObj cgl_current_ctx = CGLGetCurrentContext();
CGLShareGroupObj cgl_share_group = CGLGetShareGroup(cgl_current_ctx);
cl_context_properties cps[] = {
CL_CONTEXT_PROPERTY_USE_CGL_SHAREGROUP_APPLE, (cl_context_properties)cgl_share_group,
0
};
#elif defined(OS_LNX)
cl_context_properties cps[] = {
CL_GL_CONTEXT_KHR, (cl_context_properties)wnd.context(),
CL_GLX_DISPLAY_KHR, (cl_context_properties)wnd.display(),
CL_CONTEXT_PLATFORM, (cl_context_properties)plat(),
0
};
#else /* OS_WIN */
cl_context_properties cps[] = {
CL_GL_CONTEXT_KHR, (cl_context_properties)wnd.context(),
CL_WGL_HDC_KHR, (cl_context_properties)wnd.display(),
CL_CONTEXT_PLATFORM, (cl_context_properties)plat(),
0
};
#endif
std::vector<Device> devs;
plat.getDevices(CL_DEVICE_TYPE_GPU, &devs);
Device device;
for (auto& d : devs) {
if (checkExtnAvailability(d, CL_GL_SHARING_EXT)) {
device = d;
break;
}
}
Context context(device, cps);
CommandQueue queue(context, device);
cl::Buffer devOut(context, CL_MEM_READ_WRITE, sizeof(float) * SIZE * 2);
kernel(devOut, queue);
/* copy your data into the vertex buffer object exposed by
* fg::Plot class and then proceed to rendering.
* To help the users with copying the data from compute
* memory to display memory, Forge provides copy headers
* along with the library to help with this task
*/
fg::copy(plt0, devOut, queue);
fg::copy(plt1, devOut, queue);
//.........这里部分代码省略.........
示例2: main
int main(void)
{
try {
/*
* First Forge call should be a window creation call
* so that necessary OpenGL context is created for any
* other fg::* object to be created successfully
*/
fg::Window wnd(DIMX, DIMY, "Fractal Demo");
wnd.makeCurrent();
/* create an font object and load necessary font
* and later pass it on to window object so that
* it can be used for rendering text */
fg::Font fnt;
#ifdef OS_WIN
fnt.loadSystemFont("Calibri", 32);
#else
fnt.loadSystemFont("Vera", 32);
#endif
wnd.setFont(&fnt);
/* Create an image object which creates the necessary
* textures and pixel buffer objects to hold the image
* */
fg::Image img(DIMX, DIMY, fg::FG_RGBA, fg::u8);
Platform plat = getPlatform();
// Select the default platform and create a context using this platform and the GPU
#if defined(OS_MAC)
CGLContextObj cgl_current_ctx = CGLGetCurrentContext();
CGLShareGroupObj cgl_share_group = CGLGetShareGroup(cgl_current_ctx);
cl_context_properties cps[] = {
CL_CONTEXT_PROPERTY_USE_CGL_SHAREGROUP_APPLE, (cl_context_properties)cgl_share_group,
0
};
#elif defined(OS_LNX)
cl_context_properties cps[] = {
CL_GL_CONTEXT_KHR, (cl_context_properties)wnd.context(),
CL_GLX_DISPLAY_KHR, (cl_context_properties)wnd.display(),
CL_CONTEXT_PLATFORM, (cl_context_properties)plat(),
0
};
#else /* OS_WIN */
cl_context_properties cps[] = {
CL_GL_CONTEXT_KHR, (cl_context_properties)wnd.context(),
CL_WGL_HDC_KHR, (cl_context_properties)wnd.display(),
CL_CONTEXT_PLATFORM, (cl_context_properties)plat(),
0
};
#endif
std::vector<Device> devs;
plat.getDevices(CL_DEVICE_TYPE_GPU, &devs);
Device device;
for (auto& d : devs) {
if (checkExtnAvailability(d, CL_GL_SHARING_EXT)) {
device = d;
break;
}
}
Context context(device, cps);
CommandQueue queue(context, device);
/* copy your data into the pixel buffer object exposed by
* fg::Image class and then proceed to rendering.
* To help the users with copying the data from compute
* memory to display memory, Forge provides copy headers
* along with the library to help with this task
*/
cl::Buffer devOut(context, CL_MEM_READ_WRITE, IMG_SIZE);
kernel(devOut, queue);
fg::copy(img, devOut, queue);
do {
wnd.draw(img);
} while(!wnd.close());
}catch (fg::Error err) {
std::cout << err.what() << "(" << err.err() << ")" << std::endl;
} catch (cl::Error err) {
std::cout << err.what() << "(" << err.err() << ")" << std::endl;
}
return 0;
}
示例3: main
int main(void)
{
try {
/*
* First Forge call should be a window creation call
* so that necessary OpenGL context is created for any
* other fg::* object to be created successfully
*/
fg::Window wnd(DIMX, DIMY, "Histogram Demo");
wnd.makeCurrent();
/* create an font object and load necessary font
* and later pass it on to window object so that
* it can be used for rendering text */
fg::Font fnt;
#ifdef OS_WIN
fnt.loadSystemFont("Calibri", 32);
#else
fnt.loadSystemFont("Vera", 32);
#endif
wnd.setFont(&fnt);
/*
* Split the window into grid regions
*/
wnd.grid(WIN_ROWS, WIN_COLS);
/* Create an image object which creates the necessary
* textures and pixel buffer objects to hold the image
* */
fg::Image img(DIMX, DIMY, fg::FG_RGBA, fg::u8);
/*
* Create histogram object while specifying desired number of bins
*/
fg::Histogram hist(NBINS, fg::u8);
/*
* Set histogram colors
*/
hist.setBarColor(fg::FG_YELLOW);
/* set x axis limits to maximum and minimum values of data
* and y axis limits to range [0, nBins]*/
hist.setAxesLimits(1, 0, 1000, 0);
Platform plat = getPlatform();
// Select the default platform and create a context using this platform and the GPU
#if defined(OS_MAC)
CGLContextObj cgl_current_ctx = CGLGetCurrentContext();
CGLShareGroupObj cgl_share_group = CGLGetShareGroup(cgl_current_ctx);
cl_context_properties cps[] = {
CL_CONTEXT_PROPERTY_USE_CGL_SHAREGROUP_APPLE, (cl_context_properties)cgl_share_group,
0
};
#elif defined(OS_LNX)
cl_context_properties cps[] = {
CL_GL_CONTEXT_KHR, (cl_context_properties)wnd.context(),
CL_GLX_DISPLAY_KHR, (cl_context_properties)wnd.display(),
CL_CONTEXT_PLATFORM, (cl_context_properties)plat(),
0
};
#else /* OS_WIN */
cl_context_properties cps[] = {
CL_GL_CONTEXT_KHR, (cl_context_properties)wnd.context(),
CL_WGL_HDC_KHR, (cl_context_properties)wnd.display(),
CL_CONTEXT_PLATFORM, (cl_context_properties)plat(),
0
};
#endif
std::vector<Device> devs;
plat.getDevices(CL_DEVICE_TYPE_GPU, &devs);
Device device;
for (auto& d : devs) {
if (checkExtnAvailability(d, CL_GL_SHARING_EXT)) {
device = d;
break;
}
}
Context context(device, cps);
CommandQueue queue(context, device);
cl::Buffer devOut(context, CL_MEM_READ_WRITE, IMG_SIZE);
cl::Buffer histOut(context, CL_MEM_READ_WRITE, NBINS * sizeof(int));
/*
* generate image, and prepare data to pass into
* Histogram's underlying vertex buffer object
*/
kernel(devOut, histOut, queue);
/* To help the users with copying the data from compute
* memory to display memory, Forge provides copy headers
* along with the library to help with this task
*/
fg::copy(img, devOut, queue);
fg::copy(hist, histOut, queue);
do {
kernel(devOut, histOut, queue);
//.........这里部分代码省略.........
示例4: main
int main(void)
{
try {
/*
* First Forge call should be a window creation call
* so that necessary OpenGL context is created for any
* other fg::* object to be created successfully
*/
fg::Window wnd(DIMX, DIMY, "Plot3d Demo");
wnd.makeCurrent();
/* create an font object and load necessary font
* and later pass it on to window object so that
* it can be used for rendering text */
fg::Font fnt;
#ifdef OS_WIN
fnt.loadSystemFont("Calibri", 32);
#else
fnt.loadSystemFont("Vera", 32);
#endif
wnd.setFont(&fnt);
/* Create several plot objects which creates the necessary
* vertex buffer objects to hold the different plot types
*/
fg::Plot3 plot3(ZSIZE, fg::f32);
/*
* Set draw limits for plots
*/
plot3.setAxesLimits(1.1f, -1.1f, 1.1f, -1.1f, 10.f, 0.f);
/*
* Set draw limits for plots
*/
plot3.setAxesLimits(1.1f, -1.1f, 1.1f, -1.1f, 10.f, 0.f);
/*
* Set axis titles
*/
plot3.setAxesTitles("x-axis", "y-axis", "z-axis");
Platform plat = getPlatform();
// Select the default platform and create a context using this platform and the GPU
#if defined(OS_MAC)
CGLContextObj cgl_current_ctx = CGLGetCurrentContext();
CGLShareGroupObj cgl_share_group = CGLGetShareGroup(cgl_current_ctx);
cl_context_properties cps[] = {
CL_CONTEXT_PROPERTY_USE_CGL_SHAREGROUP_APPLE, (cl_context_properties)cgl_share_group,
0
};
#elif defined(OS_LNX)
cl_context_properties cps[] = {
CL_GL_CONTEXT_KHR, (cl_context_properties)wnd.context(),
CL_GLX_DISPLAY_KHR, (cl_context_properties)wnd.display(),
CL_CONTEXT_PLATFORM, (cl_context_properties)plat(),
0
};
#else /* OS_WIN */
cl_context_properties cps[] = {
CL_GL_CONTEXT_KHR, (cl_context_properties)wnd.context(),
CL_WGL_HDC_KHR, (cl_context_properties)wnd.display(),
CL_CONTEXT_PLATFORM, (cl_context_properties)plat(),
0
};
#endif
std::vector<Device> devs;
plat.getDevices(CL_DEVICE_TYPE_GPU, &devs);
Device device;
CommandQueue queue;
Context context;
for (auto& d : devs) {
if (checkExtnAvailability(d, CL_GL_SHARING_EXT)) {
device = d;
context = Context(device, cps);
try {
queue = CommandQueue(context, device);
break;
} catch (cl::Error err) {
continue;
}
}
}
cl::Buffer devOut(context, CL_MEM_READ_WRITE, sizeof(float) * ZSIZE * 3);
static float t=0;
kernel(devOut, queue, t);
/* copy your data into the pixel buffer object exposed by
* fg::Surface class and then proceed to rendering.
* To help the users with copying the data from compute
* memory to display memory, Forge provides copy headers
* along with the library to help with this task
*/
fg::copy(plot3, devOut, queue);
do {
t+=0.01;
kernel(devOut, queue, t);
//.........这里部分代码省略.........