Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions source-code/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,5 @@ Sample code for performing computations on a GPU.
## What is it?

1. `pycuda`: directory illustrating pyCUDA.
1. `scikit_cuda`: code illustrating linear algebra on a GPU device. This is an
older library and has been at least partially superceded by CuPy.
1. `numba`: code illustrating using numba for GPU computing.
1. `cupy`: Jupyter notebook illustrating some aspects of the `cupy` package.
67 changes: 40 additions & 27 deletions source-code/cupy/cupy.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
},
{
"cell_type": "code",
"execution_count": 15,
"execution_count": 1,
"id": "c5430b2b-a033-4d85-a76a-eb9c958eb66d",
"metadata": {},
"outputs": [],
Expand Down Expand Up @@ -67,8 +67,8 @@
"name": "stdout",
"output_type": "stream",
"text": [
"CPU times: user 975 ms, sys: 1.03 s, total: 2.01 s\n",
"Wall time: 127 ms\n"
"CPU times: user 1.93 s, sys: 211 ms, total: 2.14 s\n",
"Wall time: 136 ms\n"
]
}
],
Expand All @@ -87,8 +87,8 @@
"name": "stdout",
"output_type": "stream",
"text": [
"CPU times: user 427 ms, sys: 2.04 s, total: 2.47 s\n",
"Wall time: 1.26 s\n"
"CPU times: user 1.55 s, sys: 293 ms, total: 1.84 s\n",
"Wall time: 1.79 s\n"
]
}
],
Expand Down Expand Up @@ -116,8 +116,8 @@
"name": "stdout",
"output_type": "stream",
"text": [
"CPU times: user 964 ms, sys: 2.58 s, total: 3.55 s\n",
"Wall time: 3.67 s\n"
"CPU times: user 113 ms, sys: 79.7 ms, total: 193 ms\n",
"Wall time: 195 ms\n"
]
}
],
Expand All @@ -136,8 +136,8 @@
"name": "stdout",
"output_type": "stream",
"text": [
"CPU times: user 2.44 ms, sys: 37 µs, total: 2.48 ms\n",
"Wall time: 2.05 ms\n"
"CPU times: user 3.14 ms, sys: 400 μs, total: 3.54 ms\n",
"Wall time: 2.58 ms\n"
]
}
],
Expand All @@ -164,8 +164,8 @@
"name": "stdout",
"output_type": "stream",
"text": [
"CPU times: user 360 ms, sys: 15 ms, total: 375 ms\n",
"Wall time: 378 ms\n"
"CPU times: user 197 ms, sys: 29.6 ms, total: 227 ms\n",
"Wall time: 227 ms\n"
]
}
],
Expand All @@ -185,8 +185,8 @@
"name": "stdout",
"output_type": "stream",
"text": [
"CPU times: user 432 µs, sys: 1.49 ms, total: 1.92 ms\n",
"Wall time: 1.08 ms\n"
"CPU times: user 2.03 ms, sys: 259 μs, total: 2.29 ms\n",
"Wall time: 1.72 ms\n"
]
}
],
Expand All @@ -203,6 +203,14 @@
"## Matrix power"
]
},
{
"cell_type": "markdown",
"id": "8f38d6ea-b522-4eb6-930b-0f577c3a4277",
"metadata": {},
"source": [
"Since there seems to be an issue with `%%timeit` in combination with `cp.linalg.matrix_power` `%%time` is used in this section."
]
},
{
"cell_type": "code",
"execution_count": 10,
Expand All @@ -223,17 +231,19 @@
"name": "stdout",
"output_type": "stream",
"text": [
"30.3 ms ± 5.26 ms per loop (mean ± std. dev. of 7 runs, 10 loops each)\n"
"CPU times: user 1.5 s, sys: 424 ms, total: 1.93 s\n",
"Wall time: 130 ms\n"
]
}
],
"source": [
"%timeit np.linalg.matrix_power(D, 10)"
"%%time\n",
"p = np.linalg.matrix_power(D, 10);"
]
},
{
"cell_type": "code",
"execution_count": 21,
"execution_count": 12,
"id": "2cca5817-c795-4240-8a56-6361aade49cf",
"metadata": {},
"outputs": [],
Expand All @@ -251,12 +261,14 @@
"name": "stdout",
"output_type": "stream",
"text": [
"43.7 ms ± 2.55 µs per loop (mean ± std. dev. of 7 runs, 1,000 loops each)\n"
"CPU times: user 143 ms, sys: 10.6 ms, total: 153 ms\n",
"Wall time: 7.04 ms\n"
]
}
],
"source": [
"%timeit cp.linalg.matrix_power(D_dev, 10)"
"%%time\n",
"p_dev = cp.linalg.matrix_power(D_dev, 10);"
]
},
{
Expand All @@ -269,15 +281,15 @@
},
{
"cell_type": "code",
"execution_count": 16,
"execution_count": 14,
"id": "dbae0849-7d44-4d8e-8a2a-104d08e63016",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"261 ms ± 81.5 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)\n"
"497 ms ± 89.1 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)\n"
]
}
],
Expand All @@ -288,15 +300,15 @@
},
{
"cell_type": "code",
"execution_count": 22,
"execution_count": 15,
"id": "33e09563-e5a0-47ca-b860-7b0581d7a11d",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"728 ms ± 16.7 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)\n"
"554 ms ± 18.3 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)\n"
]
}
],
Expand All @@ -307,15 +319,15 @@
},
{
"cell_type": "code",
"execution_count": 17,
"execution_count": 16,
"id": "2552a033-b7b0-423f-a162-ad559d696821",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"49.8 ms ± 4.96 ms per loop (mean ± std. dev. of 7 runs, 10 loops each)\n"
"132 ms ± 22.4 ms per loop (mean ± std. dev. of 7 runs, 10 loops each)\n"
]
}
],
Expand All @@ -326,15 +338,16 @@
},
{
"cell_type": "code",
"execution_count": 23,
"execution_count": 17,
"id": "b74986ef-b699-40db-ae50-c759b5c5a9f7",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"34 ms ± 36.5 µs per loop (mean ± std. dev. of 7 runs, 10 loops each)\n"
"The slowest run took 16.34 times longer than the fastest. This could mean that an intermediate result is being cached.\n",
"14.5 ms ± 16 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)\n"
]
}
],
Expand All @@ -360,7 +373,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.6"
"version": "3.12.8"
}
},
"nbformat": 4,
Expand Down
12 changes: 6 additions & 6 deletions source-code/pycuda/curand.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
},
{
"cell_type": "code",
"execution_count": 48,
"execution_count": 2,
"id": "122a78d1-9d07-4484-8f30-a01ed58a9715",
"metadata": {},
"outputs": [],
Expand Down Expand Up @@ -96,7 +96,7 @@
},
{
"cell_type": "code",
"execution_count": 44,
"execution_count": 3,
"id": "71134a08-5195-4205-ae1c-51c7298704e7",
"metadata": {},
"outputs": [],
Expand All @@ -118,7 +118,7 @@
},
{
"cell_type": "code",
"execution_count": 45,
"execution_count": 4,
"id": "a872e28c-9256-4d50-b46c-f8381131eda1",
"metadata": {},
"outputs": [],
Expand All @@ -128,7 +128,7 @@
},
{
"cell_type": "code",
"execution_count": 46,
"execution_count": 5,
"id": "53ddbb43-0f22-427e-83a6-c6d0264e958e",
"metadata": {},
"outputs": [],
Expand All @@ -146,7 +146,7 @@
},
{
"cell_type": "code",
"execution_count": 47,
"execution_count": 6,
"id": "f86f0258-64c8-44a0-b8b3-5a6f5d24e362",
"metadata": {},
"outputs": [
Expand Down Expand Up @@ -191,7 +191,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.7"
"version": "3.12.8"
}
},
"nbformat": 4,
Expand Down
Loading