void AsyncTimer::TimerGrow( unsigned int timers )
 {
   size_t prevSize = m_entries.size();
   m_entries.resize( prevSize + timers, 0 );
   for ( size_t i = prevSize; i < m_entries.size(); i++ )
   {
     CHECK_CUDA_CALL( cuEventCreate( (CUevent*)&m_entries[i], CU_EVENT_BLOCKING_SYNC ), "Failed to create CUDA event" );
   }
 }
// General initialization call to pick the best CUDA Device
inline CUdevice findCudaDeviceDRV(bool verbose = false)
{
    CUdevice cuDevice;
    int devID = 0;

    // Otherwise pick the device with highest Gflops/s
    char name[100];
    devID = 0;
    CHECK_CUDA_CALL( cuDeviceGet(&cuDevice, devID)
                     , "Couldn't get the device");
    cuDeviceGetName(name, 100, cuDevice);

    if(verbose)
    {
        std::cout << "Using CUDA Device "
                  << devID << ": " << name
                  << std::endl;
    }

    cuDeviceGet(&cuDevice, devID);

    return cuDevice;
}
예제 #3
0
int main(int argc, char ** argv)
{
    size_t grid_size = WIDTH * HEIGHT * sizeof(float);

    // pedir memoria
    float * current;
    float * next;
    float * result;
    CHECK_CUDA_CALL(cudaMalloc(&current, grid_size));
    CHECK_CUDA_CALL(cudaMalloc(&next, grid_size));
    CHECK_CUDA_CALL(cudaMallocHost(&result, grid_size));

    // inicializar con la fuente de calor
    CHECK_CUDA_CALL(cudaMemset(current, 0, grid_size));
    CHECK_CUDA_CALL(cudaMemcpy(&current[idx(HEAT_X, HEAT_Y)], &HEAT_TEMP, sizeof(float), cudaMemcpyHostToDevice));
    CHECK_CUDA_CALL(cudaMemcpy(next, current, grid_size, cudaMemcpyDeviceToDevice));

    // correr las actualizaciones
    for (unsigned int step = 0; step < STEPS; ++step) {
        update_cuda(WIDTH, 1, WIDTH-1, 1, HEIGHT-1, HEAT_X, HEAT_Y, current, next);

        float * swap = current;
        current = next;
        next = swap;
    }
    CHECK_CUDA_CALL(cudaGetLastError());
    CHECK_CUDA_CALL(cudaDeviceSynchronize());

    // copiar el resultado al host para graficar
    CHECK_CUDA_CALL(cudaMemcpy(result, current, grid_size, cudaMemcpyDeviceToHost));

    // graficos
    sdls_init(WIDTH, HEIGHT);
    rgba * gfx = (rgba *) calloc(WIDTH * HEIGHT, sizeof(rgba));
    for (unsigned int y = 0; y < HEIGHT; ++y) {
        for (unsigned int x = 0; x < WIDTH; ++x) {
            gfx[idx(x, y)] = color1(result[idx(x, y)] / HEAT_TEMP);
        }
    }

    sdls_blitrectangle_rgba(0, 0, WIDTH, HEIGHT, gfx);
    sdls_draw();

    printf("Presione ENTER para salir\n");
    getchar();
    sdls_cleanup();

    CHECK_CUDA_CALL(cudaFree(current));
    CHECK_CUDA_CALL(cudaFree(next));
    CHECK_CUDA_CALL(cudaFreeHost(result));
    free(gfx);

    return 0;
}
 void AsyncTimer::TimerSetup( nv_helpers_gl::Profiler::TimerIdx idx )
 {
   //Only use stream 0 for now
   CHECK_CUDA_CALL( cuEventRecord( (CUevent)m_entries[idx], 0 ), "Failed to create CUDA event" );
 }