-
Notifications
You must be signed in to change notification settings - Fork 16
PTX Backend #18
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
Open
WillTrojak
wants to merge
22
commits into
PyFR:master
Choose a base branch
from
WillTrojak:feature/ptx
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
PTX Backend #18
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
0cd7485
[wip] added ptx generator for bstream
626c2f5
Addtional sparse and dense work
WillTrojak bbbb8ef
Dense and sparse optimisation
WillTrojak 393b409
Added warp specialised dense kernel
WillTrojak 67d1beb
Performance tuning and cleanup
WillTrojak e2a818b
Whitespace
WillTrojak 7d7299a
Cleanups, formating and addressign comments
WillTrojak 1d405c3
General cleanups and moved smem to pyfr
WillTrojak 0e86053
Fixed missing import
WillTrojak 1f62b5f
Fixed additional args
WillTrojak 79f41cb
Cleanup and added PTX Version to handle older drivers.
WillTrojak 7b59ca4
Further cleanup
WillTrojak 577208a
Moved the PTX backend to use tuned kernel profiles for different CCs
WillTrojak e7d4252
Added grid stridded kernel and cleanup
WillTrojak d4e1216
msplit dmma
WillTrojak b9ac47c
Refactored arg setup
WillTrojak 66e3796
Updated Blackwell profile
WillTrojak 010d13c
updated sm100 config
WillTrojak 1e6e55d
Cleanups and added default config.
WillTrojak 1acb3b5
FP32 configs and kernels
WillTrojak 4bf8c91
Refactoring and cleanup
WillTrojak 308c8c2
Addressing comments
WillTrojak File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,8 @@ | ||
| # -*- coding: utf-8 -*- | ||
|
|
||
| import itertools as it | ||
| import json | ||
| from pathlib import Path | ||
| import pkgutil | ||
| import re | ||
|
|
||
|
|
@@ -54,6 +56,7 @@ def _chunk(l, chunksz): | |
|
|
||
| class MatMul: | ||
| platform = None | ||
| _float_suffix = 'f' | ||
|
|
||
| def __init__(self, A, beta=0.0, aligne=None, n=None, ldb=None, ldc=None): | ||
| self.A = A | ||
|
|
@@ -90,6 +93,9 @@ def __init__(self, A, beta=0.0, aligne=None, n=None, ldb=None, ldc=None): | |
| self.bix = np.nonzero(np.any(A != 0, axis=0))[0] | ||
| self.bix = {kx: k for k, kx in enumerate(self.bix)} | ||
|
|
||
| # Create config cache | ||
| self._config_cache = {} | ||
|
|
||
| def kernels(self, dtype, kname='gimmik_mm', **kwargs): | ||
| basemeta = self.basemeta | ||
|
|
||
|
|
@@ -103,14 +109,7 @@ def kernels(self, dtype, kname='gimmik_mm', **kwargs): | |
| raise ValueError('Invalid floating point data type') | ||
|
|
||
| # Common template arguments | ||
| baseargs = { | ||
| 'dtype': dtype, 'kname': kname, | ||
| 'A': self.A, 'beta': self.beta, 'width': 1, | ||
| 'm': self.m, 'n': self.n, 'k': self.k, | ||
| 'ldb': self.ldb, 'ldc': self.ldc, | ||
| 'afix': self.afix, 'alix': self.alix, 'bix': self.bix, | ||
| 'dot': _dot, 'partition': _partition, 'chunk': _chunk | ||
| } | ||
| baseargs = self._base_template_args(dtype, kname) | ||
|
|
||
| # Incrementally generate and render the kernels | ||
| gen = self._kernel_generators(dtype, dsize, **kwargs) | ||
|
|
@@ -136,17 +135,75 @@ def kernels(self, dtype, kname='gimmik_mm', **kwargs): | |
| except StopIteration: | ||
| pass | ||
|
|
||
| def _base_template_args(self, dtype, kname): | ||
| return { | ||
| 'dtype': dtype, 'kname': kname, | ||
| 'A': self.A, 'beta': self.beta, 'width': 1, | ||
| 'm': self.m, 'n': self.n, 'k': self.k, | ||
| 'ldb': self.ldb, 'ldc': self.ldc, | ||
| 'afix': self.afix, 'alix': self.alix, 'bix': self.bix, | ||
| 'dot': _dot, 'partition': _partition, 'chunk': _chunk | ||
| } | ||
|
|
||
| def _process_meta(self, meta): | ||
| pass | ||
|
|
||
| def _get_config(self, key): | ||
| try: | ||
| return self._config_cache[key] | ||
| except KeyError: | ||
| cfgdir = Path('configs') / self.platform | ||
| cfgdata = pkgutil.get_data('gimmik', str(cfgdir / f'{key}.json')) | ||
| self._config_cache[key] = json.loads(cfgdata.decode('utf-8')) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. .decode() is fine. |
||
| return self._config_cache[key] | ||
|
|
||
| def _eval_condition(self, condition, stats): | ||
| if 'all' in condition: | ||
| return all(self._eval_condition(c, stats) | ||
| for c in condition['all']) | ||
| if 'any' in condition: | ||
| return any(self._eval_condition(c, stats) | ||
| for c in condition['any']) | ||
| if 'not' in condition: | ||
| return not self._eval_condition(condition['not'], stats) | ||
|
|
||
| value = stats[condition['field']] | ||
| op = next(k for k in condition if k != 'field') | ||
| expected = condition[op] | ||
|
|
||
| match op: | ||
| case 'eq': | ||
| return value == expected | ||
| case 'ne': | ||
| return value != expected | ||
| case 'lt': | ||
| return value is not None and value < expected | ||
| case 'lte': | ||
| return value is not None and value <= expected | ||
| case 'gt': | ||
| return value is not None and value > expected | ||
| case 'gte': | ||
| return value is not None and value >= expected | ||
| case 'in': | ||
| return value in expected | ||
| case 'is_null': | ||
| return value is None | ||
| case 'is_not': | ||
| return value is not None | ||
| case 'divisible_by': | ||
| return value is not None and value % expected == 0 | ||
| case 'is_null_or_divisible_by': | ||
| return (value is None or value % expected == 0) | ||
| case _: | ||
| raise ValueError(f'op `{op}` not supported') | ||
|
|
||
| def _render_kernel(self, dtype, tplname, tplargs): | ||
| tpl = _PlatformTemplateLookup(self.platform).get_template(tplname) | ||
| src = tpl.render(**tplargs) | ||
|
|
||
| # At single precision suffix all floating point constants by 'f' | ||
| if dtype == 'float': | ||
| if dtype == 'float' and self._float_suffix: | ||
| src = re.sub(r'(?=\d*[.eE])(?=\.?\d)\d*\.?\d*(?:[eE][+-]?\d+)?', | ||
| r'\g<0>f', src) | ||
| rf'\g<0>{self._float_suffix}', src) | ||
|
|
||
| # Cleanup | ||
| src = re.sub(r'^\w+\n$', '', src.strip()) | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| { | ||
| "schema": 1, | ||
| "cc": [7, 0], | ||
| "ptx": [7, 0], | ||
| "kernels": [ | ||
| { | ||
| "template": "cstream", | ||
| "family": "sparse", | ||
| "block": [128, 1, 1], | ||
| "width": 1, | ||
| "descriptor": "cstream/x128" | ||
| }, | ||
| { | ||
| "template": "bstream", | ||
| "family": "sparse", | ||
| "block": [128, 1, 1], | ||
| "width": 1, | ||
| "descriptor": "bstream/x128" | ||
| }, | ||
| { | ||
| "template": "bstream-msplit", | ||
| "family": "sparse", | ||
| "block": [32, 4, 1], | ||
| "width": 1, | ||
| "params": { | ||
| "bsz": 24 | ||
| }, | ||
| "descriptor": "bstream-msplit/m4-b24-x32" | ||
| }, | ||
| { | ||
| "template": "cstream-ksplit", | ||
| "family": "sparse", | ||
| "block": [32, 2, 1], | ||
| "width": 1, | ||
| "params": { | ||
| "csz": 24 | ||
| }, | ||
| "descriptor": "cstream-ksplit/k2-c24-x32" | ||
| } | ||
| ] | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| { | ||
| "schema": 1, | ||
| "cc": [7, 0], | ||
| "ptx": [7, 0], | ||
| "kernels": [ | ||
| { | ||
| "template": "cstream", | ||
| "family": "sparse", | ||
| "block": [128, 1, 1], | ||
| "width": 1, | ||
| "descriptor": "cstream/x128" | ||
| }, | ||
| { | ||
| "template": "bstream", | ||
| "family": "sparse", | ||
| "block": [128, 1, 1], | ||
| "width": 1, | ||
| "descriptor": "bstream/x128" | ||
| }, | ||
| { | ||
| "template": "bstream-msplit", | ||
| "family": "sparse", | ||
| "block": [32, 4, 1], | ||
| "width": 1, | ||
| "params": { | ||
| "bsz": 24 | ||
| }, | ||
| "descriptor": "bstream-msplit/m4-b24-x32" | ||
| }, | ||
| { | ||
| "template": "cstream-ksplit", | ||
| "family": "sparse", | ||
| "block": [32, 2, 1], | ||
| "width": 1, | ||
| "params": { | ||
| "csz": 24 | ||
| }, | ||
| "descriptor": "cstream-ksplit/k2-c24-x32" | ||
| } | ||
| ] | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the newer importlib API might accept paths.