本文整理汇总了C++中cuInit函数的典型用法代码示例。如果您正苦于以下问题:C++ cuInit函数的具体用法?C++ cuInit怎么用?C++ cuInit使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了cuInit函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: checkError
void CudaModule::staticInit(void)
{
if (s_inited) {
return;
}
s_inited = true;
s_available = false;
checkError("cuInit", cuInit(0));
s_available = true;
s_device = selectDevice();
printDeviceInfo(s_device);
U32 flags = 0;
flags |= CU_CTX_SCHED_SPIN; // use sync() if you want to yield
#if (CUDA_VERSION >= 2030)
if (getDriverVersion() >= 23)
{
// reduce launch overhead with large localmem
flags |= CU_CTX_LMEM_RESIZE_TO_MAX;
}
#endif
// OpenGL & window context must have been initialized !
checkError("cuGLCtxCreate", cuGLCtxCreate( &s_context, flags, s_device));
checkError("cuEventCreate", cuEventCreate(&s_startEvent, 0));
checkError("cuEventCreate", cuEventCreate(&s_endEvent, 0));
}
示例2: main
int main(int argc, char* argv[])
{
cuInit(0);
int devs = 0;
cuDeviceGetCount(&devs);
assert(devs > 0);
CUdevice dev;
CUresult status;
CUcontext ctx = 0;
cuDeviceGet(&dev, 0);
cuCtxCreate(&ctx, 0, dev);
{
size_t f = 0, t = 0;
CUresult r = cuMemGetInfo(&f, &t);
fprintf( stderr, "Do cuMemGetInfo: %d, %zu/%zu\n", r, f, t );
}
__init("\n");
printf("\nPress any key to exit...");
char c;
scanf("%c", &c);
return 0;
}
示例3: nvptx_init
static bool
nvptx_init (void)
{
CUresult r;
int ndevs;
if (instantiated_devices != 0)
return true;
r = cuInit (0);
if (r != CUDA_SUCCESS)
GOMP_PLUGIN_fatal ("cuInit error: %s", cuda_error (r));
ptx_events = NULL;
pthread_mutex_init (&ptx_event_lock, NULL);
r = cuDeviceGetCount (&ndevs);
if (r != CUDA_SUCCESS)
GOMP_PLUGIN_fatal ("cuDeviceGetCount error: %s", cuda_error (r));
ptx_devices = GOMP_PLUGIN_malloc_cleared (sizeof (struct ptx_device *)
* ndevs);
return true;
}
示例4: CUDADevice
CUDADevice(DeviceInfo& info, Stats &stats, bool background_) : Device(stats)
{
background = background_;
cuDevId = info.num;
cuDevice = 0;
cuContext = 0;
/* intialize */
if(cuda_error(cuInit(0)))
return;
/* setup device and context */
if(cuda_error(cuDeviceGet(&cuDevice, cuDevId)))
return;
CUresult result;
if(background) {
result = cuCtxCreate(&cuContext, 0, cuDevice);
}
else {
result = cuGLCtxCreate(&cuContext, 0, cuDevice);
if(result != CUDA_SUCCESS) {
result = cuCtxCreate(&cuContext, 0, cuDevice);
background = true;
}
}
if(cuda_error_(result, "cuCtxCreate"))
return;
cuda_pop_context();
}
示例5: mcopy_gpu_init
int mcopy_gpu_init(struct device_info *device_info)
{
char fname[256];
CUresult res;
/* printf("madd_gpu_init called.\n"); */
/* Initialization */
if ((res = cuInit(0)) != CUDA_SUCCESS) {
printf("cuInit failed: res = %lu\n", (unsigned long)res);
return -1;
}
if ((res = cuDeviceGet(&device_info->dev, 0)) != CUDA_SUCCESS) {
printf("cuDeviceGet failed: res = %lu\n", (unsigned long)res);
return -1;
}
if ((res = cuCtxCreate(&device_info->context, 0, device_info->dev)) !=
CUDA_SUCCESS) {
printf("cuCtxCreate failed: res = %lu\n", (unsigned long)res);
return -1;
}
return 0;
}
示例6: loadVideoSource
void CudaVideoRender::setVideoFile(LPCWSTR a_pVideoFilename)
{
m_sFileName=a_pVideoFilename;
//char* video_file=new char[MAX_PATH];
//WideCharToMultiByte( CP_ACP, 0, a_pVideoFilename, -1, video_file, MAX_PATH, NULL, NULL );
// Find out the video size
m_bIsProgressive = loadVideoSource(a_pVideoFilename,
m_nVideoWidth, m_nVideoHeight,
m_nWindowWidth, m_nWindowHeight );
//delete video_file;
// Initialize CUDA
//TODO: dont init cuda twice??
cuInit(0);
int bTCC = 0;
// If we are using TCC driver, then always turn off interop
if (bTCC) m_bInterop = false;
// Initialize CUDA/D3D9 context and other video memory resources
initCudaResources(m_bInterop, bTCC);
m_pVideoSource->start();
}
示例7: nvptx_get_num_devices
static int
nvptx_get_num_devices (void)
{
int n;
CUresult r;
/* PR libgomp/65099: Currently, we only support offloading in 64-bit
configurations. */
if (sizeof (void *) != 8)
return 0;
/* This function will be called before the plugin has been initialized in
order to enumerate available devices, but CUDA API routines can't be used
until cuInit has been called. Just call it now (but don't yet do any
further initialization). */
if (instantiated_devices == 0)
{
r = cuInit (0);
/* This is not an error: e.g. we may have CUDA libraries installed but
no devices available. */
if (r != CUDA_SUCCESS)
return 0;
}
r = cuDeviceGetCount (&n);
if (r!= CUDA_SUCCESS)
GOMP_PLUGIN_fatal ("cuDeviceGetCount error: %s", cuda_error (r));
return n;
}
示例8: cuda_driver_api_init
CUresult cuda_driver_api_init(CUcontext *pctx, CUmodule *pmod, const char *f)
{
CUresult res;
CUdevice dev;
res = cuInit(0);
if (res != CUDA_SUCCESS) {
printf("cuInit failed: res = %lu\n", (unsigned long)res);
return res;
}
res = cuDeviceGet(&dev, 0);
if (res != CUDA_SUCCESS) {
printf("cuDeviceGet failed: res = %lu\n", (unsigned long)res);
return res;
}
res = cuCtxCreate(pctx, 0, dev);
if (res != CUDA_SUCCESS) {
printf("cuCtxCreate failed: res = %lu\n", (unsigned long)res);
return res;
}
res = cuModuleLoad(pmod, f);
if (res != CUDA_SUCCESS) {
printf("cuModuleLoad() failed\n");
cuCtxDestroy(*pctx);
return res;
}
return CUDA_SUCCESS;
}
示例9: init_cuda_context
int
init_cuda_context (void)
{
#ifdef _ENABLE_CUDA_
CUresult curesult = CUDA_SUCCESS;
CUdevice cuDevice;
int local_rank, dev_count;
int dev_id = 0;
char * str;
if ((str = getenv("LOCAL_RANK")) != NULL) {
cudaGetDeviceCount(&dev_count);
local_rank = atoi(str);
dev_id = local_rank % dev_count;
}
curesult = cuInit(0);
if (curesult != CUDA_SUCCESS) {
return 1;
}
curesult = cuDeviceGet(&cuDevice, dev_id);
if (curesult != CUDA_SUCCESS) {
return 1;
}
curesult = cuCtxCreate(&cuContext, 0, cuDevice);
if (curesult != CUDA_SUCCESS) {
return 1;
}
#endif
return 0;
}
示例10: sarafft_init
extern "C" void sarafft_init() {
printf( "Cuda is about to be initialized!\n" );
fflush ( stdout );
char *OMPI_COMM_WORLD_LOCAL_RANK = getenv( "OMPI_COMM_WORLD_LOCAL_RANK" );
if ( NULL == OMPI_COMM_WORLD_LOCAL_RANK ) {
printf( "OMPI_COMM_WORLD_LOCAL_RANK not set!\n" );
fflush ( stdout );
exit( 80 );
}
int localRank = atoi( OMPI_COMM_WORLD_LOCAL_RANK );
printf( "Local rank is %d\n", localRank );
fflush ( stdout );
if ( CUDA_SUCCESS != cuInit( 0 ) ) {
printf( "cuInit failed!\n" );
fflush ( stdout );
exit( 81 );
}
CUdevice device;
if ( CUDA_SUCCESS != cuDeviceGet( &device, localRank ) ) {
printf( "cuDeviceGet failed!\n" );
fflush ( stdout );
exit( 82 );
}
if ( CUDA_SUCCESS != cuCtxCreate( &cuda_context, CU_CTX_SCHED_YIELD, device ) ) {
printf( "cuCtxCreate failed!\n" );
fflush ( stdout );
exit( 83 );
}
printf( "Cuda was initialized successfully!\n" );
fflush ( stdout );
}
示例11: main
main()
{
/* initialize CUDA */
CUresult res;
res = cuInit(0);
MY_CUDA_CHECK(res, "cuInit()");
/* check GPU is setted or not */
int device_num;
res = cuDeviceGetCount(&device_num);
MY_CUDA_CHECK(res, "cuDeviceGetCount()");
if (device_num == 0) { // no GPU is detected
fprintf(stderr, "no CUDA capable GPU is detected...\n");
exit(1);
}
printf("%d GPUs are detected\n", device_num);
for (int i=0; i<device_num; i++)
{
/* get device handle of GPU No.i */
CUdevice dev;
res = cuDeviceGet(&dev, i);
MY_CUDA_CHECK(res, "cuDeviceGet()");
/* search compute capability of GPU No.i */
int major=0, minor=0;
res = cuDeviceComputeCapability(&major, &minor, dev);
MY_CUDA_CHECK(res, "cuDeviceComputeCapability()");
printf("GPU[%d] : actual compute capability is : %d%d\n", i, major, minor);
}
}
示例12: main
int main() {
int ngpu;
CUdevice cuDevice;
CUcontext cuContext;
cuInit(0);
cuDeviceGetCount(&ngpu);
//printf("ngpu = %d\n", ngpu);
size_t *totals, *frees ;
totals = (size_t *) calloc (ngpu, sizeof(size_t));
frees = (size_t *) calloc (ngpu, sizeof(size_t));
int tid;
omp_set_num_threads(ngpu);
#pragma omp parallel private(tid, cuDevice, cuContext) shared(frees, totals)
{
tid = omp_get_thread_num();
//printf("nthreads = %d, tid = %d\n", omp_get_num_threads(), tid);
cuDeviceGet(&cuDevice, tid);
cuCtxCreate(&cuContext, tid, cuDevice);
cuMemGetInfo((size_t*)&frees[tid], (size_t*)&totals[tid]);
}
printf ("\ttotal\t\tfree\t\tused\n");
for(int i=0; i<ngpu; i++) {
printf("GPU %d\t%lu\t%lu\t%lu\n", i, (size_t)totals[i], (size_t)frees[i], (size_t)totals[i]-(size_t)frees[i]);
}
return 0;
}
示例13: cuda_over_map
Object cuda_over_map(Object self, int nparts, int *argcv,
Object *argv, int flags) {
CUresult error;
cuInit(0);
int deviceCount = 0;
error = cuDeviceGetCount(&deviceCount);
if (deviceCount == 0) {
raiseError("No CUDA devices found");
}
CUdevice cuDevice;
CUcontext cuContext;
CUmodule cuModule;
CUfunction cuFunc;
error = cuDeviceGet(&cuDevice, 0);
error = cuCtxCreate(&cuContext, 0, cuDevice);
CUdeviceptr d_A;
CUdeviceptr d_B;
CUdeviceptr d_res;
errcheck(cuModuleLoad(&cuModule, grcstring(argv[argcv[0]])));
CUdeviceptr dps[argcv[0]];
void *args[argcv[0]+2];
int size = INT_MAX;
for (int i=0; i<argcv[0]; i++) {
struct CudaFloatArray *a = (struct CudaFloatArray *)argv[i];
if (a->size < size)
size = a->size;
errcheck(cuMemAlloc(&dps[i], size * sizeof(float)));
errcheck(cuMemcpyHtoD(dps[i], &a->data, size * sizeof(float)));
args[i+1] = &dps[i];
}
struct CudaFloatArray *r =
(struct CudaFloatArray *)(alloc_CudaFloatArray(size));
int fsize = sizeof(float) * size;
errcheck(cuMemAlloc(&d_res, fsize));
errcheck(cuMemcpyHtoD(d_res, &r->data, fsize));
args[0] = &d_res;
args[argcv[0]+1] = &size;
int threadsPerBlock = 256;
int blocksPerGrid = (size + threadsPerBlock - 1) / threadsPerBlock;
char name[256];
strcpy(name, "block");
strcat(name, grcstring(argv[argcv[0]]) + strlen("_cuda/"));
for (int i=0; name[i] != 0; i++)
if (name[i] == '.') {
name[i] = 0;
break;
}
errcheck(cuModuleGetFunction(&cuFunc, cuModule, name));
errcheck(cuLaunchKernel(cuFunc, blocksPerGrid, 1, 1,
threadsPerBlock, 1, 1,
0,
NULL, args, NULL));
errcheck(cuMemcpyDtoH(&r->data, d_res, fsize));
cuMemFree(d_res);
for (int i=0; i<argcv[0]; i++)
cuMemFree(dps[i]);
return (Object)r;
}
示例14: cuInit
device::device() {
cuInit(0);
cuDeviceGet(&cu_device, 0);
checkCudaError("device::device Init");
//cuCtxCreate(&cu_context, 0, cu_device);
//checkCudaError("device::device Create context");
device_name = props.name;
}
示例15: init
void init(){
if(!isNotInitialized)
return;
cuInit(0);
isNotInitialized = false;
}