Skip to content

Commit 1f8dd79

Browse files
bmhowe23bettinaheim
andcommitted
Publishing fixes for single-GPU runner (#1672)
Co-authored-by: Bettina Heim <[email protected]>
1 parent 1926eea commit 1f8dd79

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

docs/sphinx/examples/python/tutorials/executing_circuits.ipynb

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,9 +150,14 @@
150150
" mz(qvector)\n",
151151
"\n",
152152
"\n",
153-
"# Asynchronous execution on multiple qpus via nvidia gpus.\n",
154-
"result_1 = cudaq.sample_async(kernel_1, qubit_count, shots_count=1000, qpu_id=0)\n",
155-
"result_2 = cudaq.sample_async(kernel_2, qubit_count, shots_count=1000, qpu_id=1)\n",
153+
"if cudaq.num_available_gpus() > 1:\n",
154+
" # Asynchronous execution on multiple virtual QPUs, each simulated by an NVIDIA GPU.\n",
155+
" result_1 = cudaq.sample_async(kernel_1, qubit_count, shots_count=1000, qpu_id=0)\n",
156+
" result_2 = cudaq.sample_async(kernel_2, qubit_count, shots_count=1000, qpu_id=1)\n",
157+
"else:\n",
158+
" # Schedule for execution on the same virtual QPU.\n",
159+
" result_1 = cudaq.sample_async(kernel_1, qubit_count, shots_count=1000, qpu_id=0)\n",
160+
" result_2 = cudaq.sample_async(kernel_2, qubit_count, shots_count=1000, qpu_id=0)\n",
156161
"\n",
157162
"print(result_1.get())\n",
158163
"print(result_2.get())"

docs/sphinx/examples/python/tutorials/multi_gpu_workflows.ipynb

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -339,15 +339,20 @@
339339
],
340340
"source": [
341341
"%%timeit\n",
342-
"\n",
343-
"# Timing the execution on a single GPU vs 4 GPUs, users will see a 4x performance improvement\n",
342+
"\n",
343+
"# Timing the execution on a single GPU vs 4 GPUs,\n",
344+
"# one will see a 4x performance improvement if 4 GPUs are available.\n",
344345
"\n",
345346
"asyncresults = []\n",
347+
"num_gpus = cudaq.num_available_gpus()\n",
346348
"\n",
347349
"for i in range(len(xi)):\n",
348350
" for j in range(xi[i].shape[0]):\n",
351+
" qpu_id = i * num_gpus // len(xi)\n",
349352
" asyncresults.append(\n",
350-
" cudaq.observe_async(kernel, h, xi[i][j, :], qpu_id=i))"
353+
" cudaq.observe_async(kernel, h, xi[i][j, :], qpu_id=qpu_id))\n",
354+
"\n",
355+
"result = [res.get() for res in asyncresults]"
351356
]
352357
}
353358
],

0 commit comments

Comments
 (0)