Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the options data class to program #237

Merged
merged 73 commits into from
Jan 19, 2025
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
73 commits
Select commit Hold shift + click to select a range
6d789cb
commit squash: add ProgramOptions to Program
ksimpson-work Nov 27, 2024
66ceb85
remove stream from commit
ksimpson-work Nov 27, 2024
37a945c
modify doc source
ksimpson-work Nov 27, 2024
3555e2e
modify doc source
ksimpson-work Nov 27, 2024
1fc1189
Merge branch 'main' into ksimpson/add_program_options
ksimpson-work Dec 18, 2024
a9ac448
integrate program options into the tests
ksimpson-work Dec 18, 2024
944bc1a
Merge branch 'main' into ksimpson/add_program_options
leofang Dec 18, 2024
d490af2
Merge branch 'main' into ksimpson/add_program_options
ksimpson-work Dec 19, 2024
0394877
Merge branch 'main' into ksimpson/add_program_options
ksimpson-work Dec 27, 2024
b6e3eac
Merge remote-tracking branch 'origin/main' into ksimpson/add_program_…
ksimpson-work Dec 30, 2024
6790c83
update the attribute names for consistency across linker and program
ksimpson-work Dec 30, 2024
a8f8e3a
Merge remote-tracking branch 'origin/main' into ksimpson/add_program_…
ksimpson-work Dec 30, 2024
401ab75
Merge remote-tracking branch 'origin/ksimpson/add_program_options' in…
ksimpson-work Dec 30, 2024
7d5b894
fix module test
ksimpson-work Dec 31, 2024
1789a84
update the tests
ksimpson-work Dec 31, 2024
2285fac
update the tests
ksimpson-work Jan 1, 2025
bb62048
move ProgramOptions ctor into pytest raises
ksimpson-work Jan 2, 2025
d43500f
Merge branch 'main' into ksimpson/add_program_options
ksimpson-work Jan 2, 2025
0f0ca9b
only import nvjitlink if its available
ksimpson-work Jan 2, 2025
47c416d
Merge remote-tracking branch 'origin/ksimpson/add_program_options' in…
ksimpson-work Jan 2, 2025
c41821f
Merge branch 'main' into ksimpson/add_program_options
ksimpson-work Jan 2, 2025
53b8198
Merge branch 'main' into ksimpson/add_program_options
ksimpson-work Jan 2, 2025
58f2b09
Update cuda_core/examples/saxpy.py
ksimpson-work Jan 3, 2025
7afe54e
Update cuda_core/cuda/core/experimental/_program.py
ksimpson-work Jan 3, 2025
653a3e1
Update cuda_core/cuda/core/experimental/_program.py
ksimpson-work Jan 3, 2025
5161a43
Update cuda_core/cuda/core/experimental/_program.py
ksimpson-work Jan 3, 2025
dfd894e
Merge branch 'main' into ksimpson/add_program_options
ksimpson-work Jan 3, 2025
f461eec
tweak doc source
ksimpson-work Jan 3, 2025
236db71
tweak docs
ksimpson-work Jan 3, 2025
2f74ca3
tweak fix
ksimpson-work Jan 3, 2025
710d8e7
Merge branch 'main' into ksimpson/add_program_options
leofang Jan 5, 2025
9c88ba7
Update cuda_core/cuda/core/experimental/_linker.py
ksimpson-work Jan 6, 2025
133f6aa
Update cuda_core/docs/source/release.rst
ksimpson-work Jan 6, 2025
cb06afc
Update cuda_core/docs/source/release/0.1.0-notes.rst
ksimpson-work Jan 6, 2025
3578f94
fix tests
ksimpson-work Jan 6, 2025
261588c
fix quotes
ksimpson-work Jan 6, 2025
2b9e94a
Merge remote-tracking branch 'origin/ksimpson/add_program_options' in…
ksimpson-work Jan 6, 2025
1abc9f6
remove print
ksimpson-work Jan 6, 2025
d20dcfa
Update cuda_core/cuda/core/experimental/_utils.py
ksimpson-work Jan 6, 2025
79fad7a
fix titles
ksimpson-work Jan 6, 2025
b87044b
Merge remote-tracking branch 'origin/ksimpson/add_program_options' in…
ksimpson-work Jan 6, 2025
6959689
Merge branch 'main' into ksimpson/add_program_options
ksimpson-work Jan 6, 2025
ec9fac1
remove some options
ksimpson-work Jan 6, 2025
f55dcdc
add TODO
ksimpson-work Jan 6, 2025
dfe194f
Merge remote-tracking branch 'origin/ksimpson/add_program_options' in…
ksimpson-work Jan 6, 2025
b41d119
remove option
ksimpson-work Jan 6, 2025
de588de
remove options, should pass.
ksimpson-work Jan 6, 2025
2fbca70
add issue tracking info
ksimpson-work Jan 6, 2025
b79dccc
fix include path argument
ksimpson-work Jan 6, 2025
d1e4e09
Merge branch 'main' into ksimpson/add_program_options
ksimpson-work Jan 8, 2025
bf32370
fix the rest format
ksimpson-work Jan 8, 2025
85c0e47
Merge remote-tracking branch 'origin/ksimpson/add_program_options' in…
ksimpson-work Jan 8, 2025
34c8780
handle nested tuples within lists and tuples, and fix the handling of…
ksimpson-work Jan 8, 2025
cc25960
change from sequence to list or tuple
ksimpson-work Jan 8, 2025
e4786b2
Update cuda_core/cuda/core/experimental/_program.py
ksimpson-work Jan 8, 2025
d913e0a
fix quotes
ksimpson-work Jan 8, 2025
06c68b4
fix quotes
ksimpson-work Jan 8, 2025
3a747f6
swap api order
ksimpson-work Jan 8, 2025
b1345f8
Merge branch 'main' into ksimpson/add_program_options
ksimpson-work Jan 9, 2025
5dc8c87
Merge branch 'main' into ksimpson/add_program_options
ksimpson-work Jan 11, 2025
446b5af
Merge branch 'main' into ksimpson/add_program_options
ksimpson-work Jan 13, 2025
9ca2f40
switch the order fo comparisons to use sequence instead of list / tuple
ksimpson-work Jan 13, 2025
a710b45
fix order and debug code
ksimpson-work Jan 13, 2025
3736541
Merge branch 'main' into ksimpson/add_program_options
ksimpson-work Jan 14, 2025
1a04c76
merge main
ksimpson-work Jan 15, 2025
5599afe
Merge branch 'main' into ksimpson/add_program_options
ksimpson-work Jan 15, 2025
f4b0f0a
fix ruff
ksimpson-work Jan 15, 2025
0e1bb93
Merge branch 'main' into ksimpson/add_program_options
ksimpson-work Jan 16, 2025
9238d64
Merge branch 'main' into ksimpson/add_program_options
leofang Jan 16, 2025
1687e0e
Merge branch 'main' into ksimpson/add_program_options
ksimpson-work Jan 17, 2025
459cbdb
lint the merge
ksimpson-work Jan 17, 2025
9ef4821
nits
leofang Jan 19, 2025
c7cb7eb
Merge branch 'main' into ksimpson/add_program_options
leofang Jan 19, 2025
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: 1 addition & 1 deletion cuda_core/cuda/core/experimental/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
from cuda.core.experimental._device import Device
from cuda.core.experimental._event import EventOptions
from cuda.core.experimental._launcher import LaunchConfig, launch
from cuda.core.experimental._program import Program
from cuda.core.experimental._program import Program, ProgramOptions
from cuda.core.experimental._stream import Stream, StreamOptions
371 changes: 359 additions & 12 deletions cuda_core/cuda/core/experimental/_program.py

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions cuda_core/cuda/core/experimental/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,13 @@ def check_or_create_options(cls, options, options_description, *, keep_none=Fals
return options


def _handle_boolean_option(option: bool) -> str:
"""
Convert a boolean option to a string representation.
"""
return str(option).lower()
ksimpson-work marked this conversation as resolved.
Show resolved Hide resolved


def precondition(checker: Callable[..., None], what: str = "") -> Callable:
"""
A decorator that adds checks to ensure any preconditions are met.
Expand Down
4 changes: 4 additions & 0 deletions cuda_core/docs/source/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,7 @@ CUDA compilation toolchain
:toctree: generated/

Program

:template: dataclass.rst

ProgramOptions
1 change: 1 addition & 0 deletions cuda_core/docs/source/release.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ maxdepth: 3
---

0.1.0 <release/0.1.0-notes>
0.2.0 <release/0.2.0-notes>
```
12 changes: 12 additions & 0 deletions cuda_core/docs/source/release/0.2.0-notes.md
leofang marked this conversation as resolved.
Show resolved Hide resolved
ksimpson-work marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# `cuda.core` Release notes

Released on <TODO>, 2024

## Hightlights
- Add ProgramOptions to facilitate the passing of runtime compile options to `Program`

## Limitations
-<TODO>

## Breaking Changes
- The `Program.Compile` method no longer accepts an options argument. Instead, you can optionally pass an instance of `ProgramOptions` to the constructor of `Program`.
9 changes: 3 additions & 6 deletions cuda_core/examples/saxpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import cupy as cp

from cuda.core.experimental import Device, LaunchConfig, Program, launch
from cuda.core.experimental import Device, LaunchConfig, Program, ProgramOptions, launch

# compute out = a * x + y
code = """
Expand All @@ -29,13 +29,10 @@
s = dev.create_stream()

# prepare program
prog = Program(code, code_type="c++")
program_options = ProgramOptions(std="c++11", gpu_architecture="sm_" + "".join(f"{i}" for i in dev.compute_capability))
prog = Program(code, code_type="c++", options=program_options)
mod = prog.compile(
"cubin",
options=(
"-std=c++11",
"-arch=sm_" + "".join(f"{i}" for i in dev.compute_capability),
),
logs=sys.stdout,
name_expressions=("saxpy<float>", "saxpy<double>"),
)
Expand Down
14 changes: 4 additions & 10 deletions cuda_core/examples/vector_add.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import cupy as cp

from cuda.core.experimental import Device, LaunchConfig, Program, launch
from cuda.core.experimental import Device, LaunchConfig, Program, ProgramOptions, launch

# compute c = a + b
code = """
Expand All @@ -26,15 +26,9 @@
s = dev.create_stream()

# prepare program
prog = Program(code, code_type="c++")
mod = prog.compile(
"cubin",
options=(
"-std=c++17",
"-arch=sm_" + "".join(f"{i}" for i in dev.compute_capability),
),
name_expressions=("vector_add<float>",),
)
program_options = ProgramOptions(std="c++17", gpu_architecture="sm_" + "".join(f"{i}" for i in dev.compute_capability))
prog = Program(code, code_type="c++", options=program_options)
mod = prog.compile("cubin", name_expressions=("vector_add<float>",))

# run in single precision
ker = mod.get_kernel("vector_add<float>")
Expand Down
39 changes: 38 additions & 1 deletion cuda_core/tests/test_program.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,45 @@

import pytest

from cuda.core.experimental import Program
from cuda.core.experimental._module import Kernel, ObjectCode
from cuda.core.experimental._program import Program, ProgramOptions


def test_program_with_various_options(init_cuda):
code = 'extern "C" __global__ void my_kernel() {}'

options_list = [
ProgramOptions(ptxas_options="-v"),
ProgramOptions(ptxas_options=["-v", "-O3"]),
ProgramOptions(device_optimize=True, device_debug=True),
ProgramOptions(relocatable_device_code=True, maxrregcount=32),
ProgramOptions(ftz=True, prec_sqrt=False, prec_div=False),
ProgramOptions(fmad=False, use_fast_math=True),
ProgramOptions(extra_device_vectorization=True),
ProgramOptions(dlink_time_opt=True, gen_opt_lto=True),
ProgramOptions(define_macro="MY_MACRO"),
ProgramOptions(define_macro=("MY_MACRO", "99")),
ProgramOptions(define_macro=[("MY_MACRO", "99")]),
ProgramOptions(define_macro=[("MY_MACRO", "99"), ("MY_OTHER_MACRO", "100")]),
ProgramOptions(undefine_macro=["MY_MACRO", "MY_OTHER_MACRO"]),
ProgramOptions(undefine_macro="MY_MACRO", include_path="/usr/local/include"),
ProgramOptions(pre_include="my_header.h", no_source_include=True),
ProgramOptions(builtin_initializer_list=False, disable_warnings=True),
ProgramOptions(restrict=True, device_as_default_execution_space=True),
ProgramOptions(device_int128=True, optimization_info="inline"),
ProgramOptions(no_display_error_number=True),
ProgramOptions(diag_error="1234", diag_suppress="5678"),
ProgramOptions(diag_warn="91011", brief_diagnostics=True),
ProgramOptions(time="compile_time.csv", split_compile=4),
ProgramOptions(fdevice_syntax_only=True, minimal=True),
]

# TODO compile the program once the CI is set up
for options in options_list:
program = Program(code, "c++", options)
assert program.backend == "nvrtc"
program.close()
assert program.handle is None


def test_program_init_valid_code_type():
Expand Down