Skip to content

CUDA: Add CUDA 11.8 / Hopper support and required fixes - #8579

Merged
esc merged 5 commits into
numba:mainfrom
gmarkall:nvvm-fixes-2
Dec 3, 2022
Merged

esc merged 5 commits into
numba:mainfrom
gmarkall:nvvm-fixes-2

Conversation

@gmarkall

@gmarkall gmarkall commented Nov 4, 2022

Copy link
Copy Markdown
Member

See individual commit messages for full descriptions. The required fixes consist of:

  • Correcting the logic for determining supported compute capabilities, which was completely broken on main.
  • Using the correct NVVM IR version in all tests.

The logic for determining the supported compute capabilities was
completely wrong, and needed updating in a complicated way for each new
toolkit. This replaces the incorrect logic with a simpler mechanism:

- We have a list of compute capabilities that we're aware of.
- We have the minimum and maximum supported CC for each toolkit.
- We generate the list of supported CCs as the range of known CCs within
  the min/max for the current toolkit.

For unknown toolkits, all we can do is assume that it supports all the
toolkits that we know about that aren't deprecated upstream (i.e. those
from 5.3 onwards).

This should be much easier to update - for each new toolkit, we just add
a new entry in the mapping from toolkit versions to min/max supported CC
versions. If we drop support for a toolkit, we can just delete it from
the mapping.
The NVVM IR version for IR given to NVVM should always match the version
that it supports - some versions of NVVM can reject IR where the version
doesn't match.

When the version isn't specified, it is implicitly 1.0, which is why
this commit mostly consists of additions that add the IR version to
modules.
@gmarkall

gmarkall commented Nov 4, 2022

Copy link
Copy Markdown
Member Author

gpuci run tests

@gmarkall gmarkall added 2 - In Progress CUDA CUDA related issue/PR Effort - medium Medium size effort needed 3 - Ready for Review and removed 2 - In Progress labels Nov 4, 2022

@stuartarchibald stuartarchibald left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the patch. This largely looks good, just a few queries to resolve inline. Thanks again!

Comment thread numba/cuda/cudadrv/nvvm.py Outdated
(9, 0)
)

# Maps CTK version -> (min supported cc, max supported cc)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are the bounds inclusive/exclusive, should this be clarified?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now clarified.

Comment thread numba/cuda/cudadrv/nvvm.py Outdated
Comment on lines +384 to +385
def get_supported_ccs():
# Attempt to return cached list

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If there's an in-process cache need, should something like functools.cache be used opposed to module globals?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would be way better than the current bodge!

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually it doesn't even need to be cached, this just makes no sense. The supported CCs is a property of the NVVM version, so I'm going to just make supported_ccs a property of the NVVM instance, because that just makes more sense anyway (and implicitly "caches" the values too because it's a singleton).

I think there could be an argument for the logic in get_supported_ccs() and its callees to be part of the NVVM class, but I think that functionality will also be common with NVPTX so I don't want to hoist the code into NVVM for now.

Comment thread numba/cuda/cudadrv/nvvm.py Outdated
Comment on lines +400 to +404
if cudart_version < (11, 0):
_supported_cc = ()
ctk_ver = f"{cudart_version[0]}.{cudart_version[1]}"
unsupported_ver = (f"CUDA Toolkit {ctk_ver} is unsupported by Numba - "
"11.0 is the minimum required version.")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should the minimum version be specified as a constant somewhere (maybe a module global, or perhaps even all this encoding of supported CCs etc ought to go into it's own module or YAML file?) and then code be updated in terms of that constant?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think instead of hardcoding the minimum CTK required, it can be derived from the dict of supported CCs, then it doesn't need to be stored separately anywhere. Additionally, I'm going to use NUMBA_CUDA_DEFAULT_PTX_CC for the default minimum for unrecognised toolkits instead of hardcoding (5, 3) above. This will be more robust in that a constant doesn't need updating in two places, and if there's some future toolkit that doesn't even support 5.3, the user can workaround it by setting the environment variable NUMBA_CUDA_DEFAULT_PTX_CC=6.1 (or whatever) to match the minimum for their toolkit.

The CC support matrix for NVPTX will differ, so I think keeping this encoding of supported CCs in nvvm.py is logical, and keeps complexity to a minimum instead of adding additional logic / dependencies.

Comment on lines +17 to +18
versions = NVVM().get_ir_version()
metadata = metadata_nvvm70 % versions

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps update to use .format() or an f-string?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I decided against that because it makes the IR less legible due to the presence of { and }.

Comment on lines 33 to +35
m = ir.Module("test_nvvm_from_llvm")
m.triple = 'nvptx64-nvidia-cuda'
nvvm.add_ir_version(m)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this 3 line "setup" for a CUDA-target-LLVM-module sufficiently common to make it worth creating a utility function? The main concern here is that the m.triple specification is likely always necessary whereas the nvvm.add_ir_version(m) appears not to be? I suppose the underlying question is "what is the need driving the addition of the add_ir_version()" call?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does happen for new modules created by the JITCUDACodegen, but I didn't use that here because it's part of the compiler / "cudapy", rather than the driver, which is under test in these cases.

@stuartarchibald stuartarchibald added 4 - Waiting on author Waiting for author to respond to review and removed 3 - Ready for Review labels Nov 7, 2022
@stuartarchibald stuartarchibald self-assigned this Nov 7, 2022
@stuartarchibald stuartarchibald added this to the Numba 0.57 RC milestone Nov 7, 2022
It makes more logical sense to keep them on the NVVM instance as a
property instead.
The minimum toolkit version can be derived from the support matrix, and
the minimum CC for unrecognised toolkits can be derived from
`config.CUDA_DEFAULT_PTX_CC`, which can also be overridden by the user
if necessary - for example, if a user has a toolkit that in future has
dropped even support for 5.3.
@gmarkall

Copy link
Copy Markdown
Member Author

gpuci run tests

@gmarkall

Copy link
Copy Markdown
Member Author

@stuartarchibald Many thanks for the review - I've addressed / responded to all comments.

@gmarkall gmarkall added 4 - Waiting on reviewer Waiting for reviewer to respond to author and removed 4 - Waiting on author Waiting for author to respond to review labels Nov 14, 2022

@stuartarchibald stuartarchibald left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gmarkall Thanks for the fixes! I agree with the comments you left in response to review, thanks for answering/addressing them.

@stuartarchibald stuartarchibald added Pending BuildFarm For PRs that have been reviewed but pending a push through our buildfarm 4 - Waiting on CI Review etc done, waiting for CI to finish and removed 4 - Waiting on reviewer Waiting for reviewer to respond to author labels Nov 14, 2022
@stuartarchibald

Copy link
Copy Markdown
Contributor

Buildfarm ID: numba_smoketest_cuda_yaml_172.

@gmarkall

Copy link
Copy Markdown
Member Author

Any news on the buildfarm?

@esc

esc commented Dec 1, 2022

Copy link
Copy Markdown
Member

@gmarkall @stuartarchibald apologies again for the delay here. Some hardware on the buildfram had to be replaced, hence the delay here. I have scheduled a fresh run for this PR at:

Build numba_smoketest_cuda_yaml_176 has started

@esc

esc commented Dec 3, 2022

Copy link
Copy Markdown
Member

@gmarkall @stuartarchibald apologies again for the delay here. Some hardware on the buildfram had to be replaced, hence the delay here. I have scheduled a fresh run for this PR at:

Build numba_smoketest_cuda_yaml_176 has started

With #8636 merged to main, this was finally all green. 🍏

@esc esc removed the Pending BuildFarm For PRs that have been reviewed but pending a push through our buildfarm label Dec 3, 2022
@esc esc added BuildFarm Passed For PRs that have been through the buildfarm and passed 5 - Ready to merge Review and testing done, is ready to merge and removed 4 - Waiting on CI Review etc done, waiting for CI to finish labels Dec 3, 2022
@esc
esc merged commit 0bc5357 into numba:main Dec 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

5 - Ready to merge Review and testing done, is ready to merge BuildFarm Passed For PRs that have been through the buildfarm and passed CUDA CUDA related issue/PR Effort - medium Medium size effort needed highpriority

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants