本文整理汇总了C++中runCuda函数的典型用法代码示例。如果您正苦于以下问题:C++ runCuda函数的具体用法?C++ runCuda怎么用?C++ runCuda使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了runCuda函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: display
void display(){
runCuda();
string title = "565Raytracer | " + utilityCore::convertIntToString(iterations) + " Frames";
glutSetWindowTitle(title.c_str());
glBindBuffer( GL_PIXEL_UNPACK_BUFFER, pbo);
glBindTexture(GL_TEXTURE_2D, displayImage);
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, width, height,
GL_RGBA, GL_UNSIGNED_BYTE, NULL);
glClear(GL_COLOR_BUFFER_BIT);
// VAO, shader program, and texture already bound
glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, 0);
//draw text
char displaystring[200];
strcpy ( displaystring, "Press H for help." );
drawText ( 50, 50, displaystring);
glutPostRedisplay();
glutSwapBuffers();
}
示例2: initCuda
void initCuda()
{
// First initialize OpenGL context, so we can properly set the GL
// for CUDA. NVIDIA notes this is necessary in order to achieve
// optimal performance with OpenGL/CUDA interop. use command-line
// specified CUDA device, otherwise use device with highest Gflops/s
int devCount= 0;
cudaGetDeviceCount(&devCount);
if( devCount < 1 )
{
printf("No GPUS detected\n");
exit(EXIT_FAILURE);
}
cudaGLSetGLDevice( 0 );
//Set Up scenary
setup_scene();
createPBO(&pbo);
createTexture(&textureID,image_width,image_height);
// Clean up on program exit
atexit(cleanupCuda);
runCuda();
}
示例3: Render
//-----------------------------------------------------------------------------
// Name: Render()
// Desc: Draws the scene
//-----------------------------------------------------------------------------
VOID Render()
{
// Clear the backbuffer to a black color
float ClearColor[4] = {0, 0, 0, 0};
g_pd3dDevice->ClearRenderTargetView(g_pSwapChainRTV, ClearColor);
// Run CUDA to update vertex positions
runCuda();
// Draw frame
{
// Setup the world, view, and projection matrices
SetupMatrices();
// Render the vertex buffer contents
UINT stride = sizeof(CUSTOMVERTEX);
UINT offset = 0;
g_pd3dDevice->IASetVertexBuffers(0, 1, &g_pVB, &stride, &offset);
g_pSimpleTechnique->GetPassByIndex(0)->Apply(0);
g_pd3dDevice->Draw(g_NumVertices, 0);
}
// Present the backbuffer contents to the display
g_pSwapChain->Present(0, 0);
anim += 0.01f;
}
示例4: display
void display(){
// DEBUG: display only one frame
/*
if ( frame > 5 )
return;
*/
runCuda();
time_t seconds2 = time (NULL);
if(seconds2-seconds >= 1){
fps = fpstracker/(seconds2-seconds);
fpstracker = 0;
seconds = seconds2;
}
string title = "CIS565 Rasterizer | "+ utilityCore::convertIntToString((int)fps) + "FPS";
glutSetWindowTitle(title.c_str());
glBindBuffer( GL_PIXEL_UNPACK_BUFFER, pbo);
glBindTexture(GL_TEXTURE_2D, displayImage);
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, width, height,
GL_RGBA, GL_UNSIGNED_BYTE, NULL);
glClear(GL_COLOR_BUFFER_BIT);
// VAO, shader program, and texture already bound
glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, 0);
glutPostRedisplay();
glutSwapBuffers();
}
示例5: mainLoop
void mainLoop() {
while(!glfwWindowShouldClose(window)){
glfwPollEvents();
runCuda();
time_t seconds2 = time (NULL);
if(seconds2-seconds >= 1){
fps = fpstracker/(seconds2-seconds);
fpstracker = 0;
seconds = seconds2;
}
string title = "CIS565 Rasterizer | " + utilityCore::convertIntToString((int)fps) + " FPS";
glfwSetWindowTitle(window, title.c_str());
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pbo);
glBindTexture(GL_TEXTURE_2D, displayImage);
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
glClear(GL_COLOR_BUFFER_BIT);
// VAO, shader program, and texture already bound
glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, 0);
glfwSwapBuffers(window);
}
glfwDestroyWindow(window);
glfwTerminate();
}
示例6: main
int main( int argc, char *argv[] ) {
initDisplay();
// get number of SMs on this GPU
int devID;
/*cudaDeviceProp props;
cudaGetDevice(&devID);
cudaGetDeviceProperties(&props, devID);
check();
printf("using device %s \n", props.name);
printf("number of MPs %d \n", props.multiProcessorCount);
printf("max threads per block %d \n", props.maxThreadsPerBlock);
printf("max concurrent kernels %d \n", props.concurrentKernels);
printf("number of bodies %d \n", numBodies);
*/
if(argc == 2)
{
if(strcmp(argv[1], "--cpu") == 0)
{
gpu = false;
}
else if(strcmp(argv[1], "--gpu") == 0)
{
gpu = true;
}
else
{
printf("wrong argument %s \nallowed: NULL, --cpu, --gpu \n", argv[1]);
exit(EXIT_FAILURE);
}
}
if(randData){
loadDataRand(numBodies);
}else{
loadData("data/data.tab", numBodies);
}
init(numBodies);
printf("stop with CTRL+C\n");
do {
runCuda();
showGalaxy(h_particleData, numBodies, false);
//count++;
} while (count < 64);
printf("finished...\n");
if(gpu)
{
cudaFree(d_particleData);
}
closeWindow();
printf("close...\n");
return EXIT_SUCCESS;
}
示例7: runTest
////////////////////////////////////////////////////////////////////////////////
//! Run a simple test for CUDA
////////////////////////////////////////////////////////////////////////////////
CUTBoolean runTest(int argc, char** argv)
{
if (!cutCheckCmdLineFlag(argc, (const char **)argv, "noqatest") ||
cutCheckCmdLineFlag(argc, (const char **)argv, "noprompt"))
{
g_bQAReadback = true;
fpsLimit = frameCheckNumber;
}
// First initialize OpenGL context, so we can properly set the GL for CUDA.
// This is necessary in order to achieve optimal performance with OpenGL/CUDA interop.
if (CUTFalse == initGL(argc, argv)) {
return CUTFalse;
}
// use command-line specified CUDA device, otherwise use device with highest Gflops/s
if( cutCheckCmdLineFlag(argc, (const char**)argv, "device") )
cutilGLDeviceInit(argc, argv);
else {
cudaGLSetGLDevice( cutGetMaxGflopsDeviceId() );
}
// Create the CUTIL timer
cutilCheckError( cutCreateTimer( &timer));
// register callbacks
glutDisplayFunc(display);
glutKeyboardFunc(keyboard);
glutMouseFunc(mouse);
glutMotionFunc(motion);
if (g_bQAReadback) {
g_CheckRender = new CheckBackBuffer(window_width, window_height, 4);
g_CheckRender->setPixelFormat(GL_RGBA);
g_CheckRender->setExecPath(argv[0]);
g_CheckRender->EnableQAReadback(true);
}
// create VBO
createVBO(&vbo);
// run the cuda part
runCuda(vbo);
// check result of Cuda step
checkResultCuda(argc, argv, vbo);
atexit(cleanup);
// start rendering mainloop
glutMainLoop();
cudaThreadExit();
return CUTTrue;
}
示例8: initCuda
void initCuda(){
// Use device with highest Gflops/s
cudaGLSetGLDevice( compat_getMaxGflopsDeviceId() );
initPBO(&pbo);
// Clean up on program exit
atexit(cleanupCuda);
runCuda();
}
示例9: initCuda
void initCuda(){
// Use device with highest Gflops/s
// Had to update this to remove cutil version
cudaGLSetGLDevice( gpuGetMaxGflopsDeviceId() );
initPBO(&pbo);
// Clean up on program exit
atexit(cleanupCuda);
runCuda();
}
示例10: display
////////////////////////////////////////////////////////////////////////////////
//! Display callback
////////////////////////////////////////////////////////////////////////////////
void display()
{
// run CUDA kernel to generate vertex positions
boost::shared_ptr<thrust::device_vector<ms::point> > dv = runCuda();
if (!dv)
return;
ms::gl_buffer<ms::point> glb(dv->size());
glb << *dv;
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// set view matrix
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(0.0, 0.0, translate_z);
glRotatef(rotate_x, 1.0, 0.0, 0.0);
glRotatef(rotate_y, 0.0, 1.0, 0.0);
// render from the vbo
glBindBuffer(GL_ARRAY_BUFFER,
glb.buffer());
glVertexPointer(3, // GLint size
GL_FLOAT, // GLenum type
24, // GLsizei stride
0); // offset
// assert (displayable.size_bytes == mesh_width * mesh_height * sizeof(mephitis::point));
//glColor3f(1.0, 1.0, 1.0);
glColorPointer(3,
GL_FLOAT,
24,
(const GLvoid*)(sizeof(float) * 3));
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_COLOR_ARRAY);
glDrawArrays(GL_POINTS, // GLenum mode
0, // GLint first
glb.size() // GLsizei count
);
glDisableClientState(GL_COLOR_ARRAY);
glDisableClientState(GL_VERTEX_ARRAY);
glutSwapBuffers();
glutPostRedisplay();
}
示例11: display
////////////////////////////////////////////////////////////////////////////////
//! Display callback
////////////////////////////////////////////////////////////////////////////////
void display()
{
sdkStartTimer(&timer);
// run CUDA kernel to generate vertex positions
runCuda(&cuda_vbo_resource);
//簡易ライトセット
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glLightfv(GL_LIGHT0, GL_POSITION, gkLightPos);
glLightfv(GL_LIGHT0, GL_DIFFUSE, gkLightDiff);
// glLightfv(GL_LIGHT0, GL_AMBIENT, gkLightAmb);
glEnable(GL_LIGHT1);
glLightfv(GL_LIGHT1, GL_POSITION, gkLightPos2);
glLightfv(GL_LIGHT1, GL_DIFFUSE, gkLightDiff2);
//Zバッファ有効
glEnable(GL_DEPTH_TEST);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// set view matrix
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(0.0, 0.0, translate_z);
glRotatef(rotate_x, 1.0, 0.0, 0.0);
glRotatef(rotate_y, 0.0, 1.0, 0.0);
// Earth
// glMaterialfv(GL_FRONT, GL_DIFFUSE, gkMaterial);
glutSolidSphere(50.0 * h_axis_radius, 20, 20);
glDisable(GL_LIGHTING);
// render from the vbo
glBindBuffer(GL_ARRAY_BUFFER, vbo);
glVertexPointer(4, GL_FLOAT, 0, 0);
glEnableClientState(GL_VERTEX_ARRAY);
glColor3f(1.0, 1.0, 1.0);
glDrawArrays(GL_POINTS, 0, mesh_width * mesh_height);
glDisableClientState(GL_VERTEX_ARRAY);
glutSwapBuffers();
g_fAnim += 0.01f;
sdkStopTimer(&timer);
computeFPS();
}
示例12: initCuda
void initCuda(){
// Use device with highest Gflops/s
#if CUDA_VERSION >= 5000
cudaGLSetGLDevice( gpuGetMaxGflopsDeviceId() );
#else
cudaGLSetGLDevice( cutGetMaxGflopsDeviceId() );
#endif
initPBO(&pbo);
// Clean up on program exit
atexit(cleanupCuda);
runCuda();
}
示例13: initCuda
void initCuda(){
// Use device with highest Gflops/s
cudaGLSetGLDevice( cutGetMaxGflopsDeviceId() );
initPBO(&pbo);
dptr=NULL;
cudaGLMapBufferObject((void**)&dptr, pbo);
clearPBOpos(dptr,width,height);
cudaGLUnmapBufferObject(pbo);
// Clean up on program exit
atexit(cleanupCuda);
SetScissorWindow(glm::vec4(300,300,500,500));
texture.mapptr = stbi_load("cow.jpeg",&texture.width, &texture.height,&texture.depth,0);
runCuda();
}
示例14: display
////////////////////////////////////////////////////////////////////////////////
//! Display callback
////////////////////////////////////////////////////////////////////////////////
void display()
{
cutilCheckError(cutStartTimer(timer));
// run CUDA kernel to generate vertex positions
runCuda(vbo);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// set view matrix
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(0.0, 0.0, translate_z);
glRotatef(rotate_x, 1.0, 0.0, 0.0);
glRotatef(rotate_y, 0.0, 1.0, 0.0);
// render from the vbo
glBindBuffer(GL_ARRAY_BUFFER, vbo);
glVertexPointer(4, GL_FLOAT, 0, 0);
glEnableClientState(GL_VERTEX_ARRAY);
glColor3f(1.0, 0.0, 0.0);
glDrawArrays(GL_POINTS, 0, mesh_width * mesh_height);
glDisableClientState(GL_VERTEX_ARRAY);
if (g_CheckRender && g_CheckRender->IsQAReadback() && g_Verify) {
// readback for QA testing
printf("> (Frame %d) Readback BackBuffer\n", frameCount);
g_CheckRender->readback( window_width, window_height );
g_CheckRender->savePPM(sOriginal[g_Index], true, NULL);
if (!g_CheckRender->PPMvsPPM(sOriginal[g_Index], sReference[g_Index], MAX_EPSILON_ERROR, 0.15f)) {
g_TotalErrors++;
}
else
{
printf( "TEST PASSED\n" );
}
g_Verify = false;
}
glutSwapBuffers();
glutPostRedisplay();
anim += 0.01;
cutilCheckError(cutStopTimer(timer));
computeFPS();
}
示例15: initCuda
void initCuda(){
// Use device with highest Gflops/s
cudaGLSetGLDevice( cutGetMaxGflopsDeviceId() );
initPBO(&pbo);
paraMap = new float[(int)renderCam->resolution.x *(int)renderCam->resolution.y];
effectiveRayMap =new int[(int)renderCam->resolution.x *(int)renderCam->resolution.y];
initialRayMap = new ray[(int)renderCam->resolution.x * (int)renderCam->resolution.y];
generateRayMap(renderCam, targetFrame);
// Clean up on program exit
atexit(cleanupCuda);
runCuda();
}