Android-cuttlefish cvd tool
cuda_loader.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2026 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#pragma once
18
19#include <cuda.h>
20
22
23namespace cuttlefish {
24
25// CUDA Driver API function pointers, loaded at runtime via dlopen.
26// Versioned symbol names (e.g., cuCtxPushCurrent_v2) match the
27// CUDA Driver ABI.
29 CUresult (*cuInit)(unsigned int);
30 CUresult (*cuDeviceGet)(CUdevice*, int);
31 CUresult (*cuDeviceGetName)(char*, int, CUdevice);
32 CUresult (*cuDevicePrimaryCtxRetain)(CUcontext*, CUdevice);
33 CUresult (*cuDevicePrimaryCtxRelease)(CUdevice);
34 CUresult (*cuCtxPushCurrent)(CUcontext);
35 CUresult (*cuCtxPopCurrent)(CUcontext*);
36 CUresult (*cuStreamCreate)(CUstream*, unsigned int);
37 CUresult (*cuStreamDestroy)(CUstream);
38 CUresult (*cuStreamSynchronize)(CUstream);
39 CUresult (*cuMemAllocPitch)(CUdeviceptr*, size_t*, size_t, size_t,
40 unsigned int);
41 CUresult (*cuMemFree)(CUdeviceptr);
42 CUresult (*cuMemcpy2DAsync)(const CUDA_MEMCPY2D*, CUstream);
43 CUresult (*cuGetErrorString)(CUresult, const char**);
44};
45
46// Returns the CUDA function table. Thread-safe; loads once.
48
49} // namespace cuttlefish
Definition: alloc_driver.h:20
tl::expected< T, StackTraceError > Result
Definition: result_type.h:30
Result< const CudaFunctions * > TryLoadCuda()
Definition: cuda_loader.cpp:84
Definition: cuda_loader.h:28
CUresult(* cuDevicePrimaryCtxRelease)(CUdevice)
Definition: cuda_loader.h:33
CUresult(* cuCtxPushCurrent)(CUcontext)
Definition: cuda_loader.h:34
CUresult(* cuGetErrorString)(CUresult, const char **)
Definition: cuda_loader.h:43
CUresult(* cuStreamDestroy)(CUstream)
Definition: cuda_loader.h:37
CUresult(* cuMemAllocPitch)(CUdeviceptr *, size_t *, size_t, size_t, unsigned int)
Definition: cuda_loader.h:39
CUresult(* cuCtxPopCurrent)(CUcontext *)
Definition: cuda_loader.h:35
CUresult(* cuMemFree)(CUdeviceptr)
Definition: cuda_loader.h:41
CUresult(* cuStreamSynchronize)(CUstream)
Definition: cuda_loader.h:38
CUresult(* cuDeviceGetName)(char *, int, CUdevice)
Definition: cuda_loader.h:31
CUresult(* cuInit)(unsigned int)
Definition: cuda_loader.h:29
CUresult(* cuDevicePrimaryCtxRetain)(CUcontext *, CUdevice)
Definition: cuda_loader.h:32
CUresult(* cuDeviceGet)(CUdevice *, int)
Definition: cuda_loader.h:30
CUresult(* cuMemcpy2DAsync)(const CUDA_MEMCPY2D *, CUstream)
Definition: cuda_loader.h:42
CUresult(* cuStreamCreate)(CUstream *, unsigned int)
Definition: cuda_loader.h:36