| 175 | } |
| 176 | |
| 177 | virtgpu * create_virtgpu() { |
| 178 | virtgpu * gpu = new virtgpu(); |
| 179 | |
| 180 | gpu->use_apir_capset = getenv("GGML_REMOTING_USE_APIR_CAPSET") != nullptr; |
| 181 | util_sparse_array_init(&gpu->shmem_array, sizeof(virtgpu_shmem), 1024); |
| 182 | |
| 183 | // Initialize mutex to protect shared data_shmem buffer |
| 184 | if (mtx_init(&gpu->data_shmem_mutex, mtx_plain) != thrd_success) { |
| 185 | delete gpu; |
| 186 | GGML_ABORT(GGML_VIRTGPU "%s: failed to initialize data_shmem mutex", __func__); |
| 187 | return NULL; |
| 188 | } |
| 189 | |
| 190 | if (virtgpu_open(gpu) != APIR_SUCCESS) { |
| 191 | GGML_LOG_ERROR(GGML_VIRTGPU "%s: failed to open the virtgpu device\n", __func__); |
| 192 | return NULL; |
| 193 | } |
| 194 | |
| 195 | if (virtgpu_init_capset(gpu) != APIR_SUCCESS) { |
| 196 | if (gpu->use_apir_capset) { |
| 197 | GGML_ABORT(GGML_VIRTGPU |
| 198 | "%s: failed to initialize the virtgpu APIR capset. Make sure that the virglrenderer library " |
| 199 | "supports it.", |
| 200 | __func__); |
| 201 | } else { |
| 202 | GGML_ABORT(GGML_VIRTGPU "%s: failed to initialize the virtgpu Venus capset", __func__); |
| 203 | } |
| 204 | return NULL; |
| 205 | } |
| 206 | |
| 207 | if (virtgpu_init_context(gpu) != APIR_SUCCESS) { |
| 208 | GGML_ABORT(GGML_VIRTGPU "%s: failed to initialize the GPU context", __func__); |
| 209 | return NULL; |
| 210 | } |
| 211 | |
| 212 | if (virtgpu_shmem_create(gpu, SHMEM_REPLY_SIZE, &gpu->reply_shmem)) { |
| 213 | GGML_ABORT(GGML_VIRTGPU "%s: failed to create the shared reply memory pages", __func__); |
| 214 | return NULL; |
| 215 | } |
| 216 | |
| 217 | if (virtgpu_shmem_create(gpu, SHMEM_DATA_SIZE, &gpu->data_shmem)) { |
| 218 | GGML_ABORT(GGML_VIRTGPU "%s: failed to create the shared data memory pages", __func__); |
| 219 | return NULL; |
| 220 | } |
| 221 | |
| 222 | if (virtgpu_handshake(gpu)) { |
| 223 | GGML_ABORT(GGML_VIRTGPU "%s: failed to handshake with the virglrenderer library", __func__); |
| 224 | return NULL; |
| 225 | } |
| 226 | |
| 227 | if (virtgpu_load_library(gpu) != APIR_LOAD_LIBRARY_SUCCESS) { |
| 228 | GGML_ABORT(GGML_VIRTGPU "%s: failed to load the backend library", __func__); |
| 229 | return NULL; |
| 230 | } |
| 231 | |
| 232 | return gpu; |
| 233 | } |
| 234 |
no test coverage detected