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

First phase of SpGEMM TPL refactor #1582

Merged
merged 3 commits into from
Nov 2, 2022

Conversation

brian-kelley
Copy link
Contributor

@brian-kelley brian-kelley commented Nov 1, 2022

  • Add support for SpGEMM in cuSPARSE versions 11.0-11.3. With this, all versions 10.x and 11.x are supported.
  • Cleanup: remove cuSPARSE handle and matrix descriptor from CrsMatrix, since these were not used by any TPL wrappers. The cuSPARSE general handle definitely doesn't belong in the matrix, since the singleton handle (lazily created by Controls) can be used for all cuSPARSE calls. The matrix descriptor also doesn't need to be in the matrix, since it takes about 1us to create in both cuSPARSE and rocSPARSE, so caching it doesn't really provide noticeable savings even for fast-running kernels like SpMV.

Note: we can always add the matrix descriptor back into CrsMatrix, but we would need to fix several things:

  • Need to have not only the cusparseMatDescr_t, but also the cusparseSpMatDescr_t if on CUDA 11.x. The former just contains things like general vs. symmetric, unit diagonal vs not, etc, but the latter actually has pointers and extents of rowptrs, entries and values.
  • Instead of shallow copying the descriptor in the CrsMatrix copy constructors, we need to recreate it for each matrix. Otherwise ownership is ambiguous.
  • The descriptor should also be destroyed it in the CrsMatrix destructor. In the existing code it was leaked (not sure if it actually allocates any resources, but if cusparseDestroyMatDescr exists we should use it).
  • Need to make rowptrs/entries/values views const somehow, so that the user can't just replace a view (leaving a stale descriptor). Or provide setters that refresh the descriptor.

Because of this I would prefer to just not cache these things.

It reuses less than the interfaces of 11.4+ or 10.x
(having to call the full compute in symbolic to get C_nnz) but is still
an improvement over SPGEMM_KK.
@brian-kelley brian-kelley added enhancement Cleanup Code maintenance that isn't a bugfix or new feature labels Nov 1, 2022
@brian-kelley brian-kelley self-assigned this Nov 1, 2022
Copy link
Contributor

@lucbv lucbv left a comment

Choose a reason for hiding this comment

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

Looks good to me, at some point we will want to go over the documentation and make sure that we explain what the users are supposed to do with the handle/control object if they want reuse, etc... also we probably want to explain that they need to create a handle per matrix.

Copy link
Contributor

@e10harvey e10harvey left a comment

Choose a reason for hiding this comment

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

Thanks, @brian-kelley !

&h->bufferSize4, NULL));
KOKKOS_IMPL_CUDA_SAFE_CALL(cudaMalloc((void **)&h->buffer4, h->bufferSize4));
KOKKOS_CUSPARSE_SAFE_CALL(cusparseSpGEMM_compute(
h->cusparseHandle, h->opA, h->opB, &alpha, h->descr_A, h->descr_B, &beta,
Copy link
Contributor

Choose a reason for hiding this comment

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

Swap with alpha and beta user passes in?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@e10harvey Our SpGEMM interface actually doesn't take alpha or beta, and I wasn't planning on adding them. beta != 0 would mean doing a fused SpGEMM+SpAdd (C := AB + beta*C), which is possible but would be a lot of work and would mean a whole new symbolic and numeric implementation.

Alpha (C := alpha * AB) would be a lot easier to support, but there's also not a KokkosKernels use case for it that I know of. If this was needed, the user could either apply the scaling themselves when C is used, or just do a KokkosBlas::scal on C's values.

@brian-kelley
Copy link
Contributor Author

brian-kelley commented Nov 1, 2022

@lucbv That's the nice thing about not caching this stuff in the matrices, the user doesn't have to worry about it at all. All of that is encapsulated in the spgemm handle, so the user only needs to pass in the KokkosKernelsHandle (like with the native impl) and they get reuse.

Edit: If they want to run cuSPARSE stuff on a different stream, that does happen through the cusparseHandle_t. But SpGEMM doesn't take a Controls object now. Ideally, when all our functions take exec space instances, we just manage the non-singleton cusparse handle internally.

@jczhang07
Copy link
Contributor

The matrix descriptor also doesn't need to be in the matrix, since it takes about 1us to create in both cuSPARSE and rocSPARSE

Why is it fast since I imagine creating a descriptor involves memory allocation (hopefully host memory only)?

@brian-kelley
Copy link
Contributor Author

brian-kelley commented Nov 1, 2022

@jczhang07 Since the descriptor is a totally opaque structure, it's impossible to know exactly what happens during its creation (without talking to Nvidia, anyway). This is just a single data point but I just tried timing malloc(128) and it took only 0.1us, so the descriptor creation could do several small allocations like that and still take just 1us.

The one thing I am sure of is that the descriptor creation isn't doing anything on device with the rowptrs, entries, values you give it, because kernel launch overhead is already more than 1us.

@kokkos-devops-admin
Copy link

Status Flag 'Pre-Test Inspection' - Auto Inspected - Inspection Is Not Necessary for this Pull Request.

@kokkos-devops-admin
Copy link

Status Flag 'Pull Request AutoTester' - Testing Jenkins Projects:

Pull Request Auto Testing STARTING (click to expand)

Build Information

Test Name: KokkosKernels_PullRequest_GCC930_Light_Tpls_GCC930

  • Build Num: 131
  • Status: STARTED

Jenkins Parameters

Parameter Name Value
KOKKOSKERNELS_SOURCE_BRANCH RefactorSpgemm1
KOKKOSKERNELS_SOURCE_REPO https://github.com/brian-kelley/kokkos-kernels
KOKKOSKERNELS_SOURCE_SHA e0d7c05
KOKKOSKERNELS_TARGET_BRANCH develop
KOKKOSKERNELS_TARGET_REPO https://github.com/kokkos/kokkos-kernels
KOKKOSKERNELS_TARGET_SHA 9429243
PR_LABELS enhancement;Cleanup
PULLREQUESTNUM 1582
TEST_REPO_ALIAS KOKKOSKERNELS

Build Information

Test Name: KokkosKernels_PullRequest_CUDA11_CUDA11_LayoutRight

  • Build Num: 139
  • Status: STARTED

Jenkins Parameters

Parameter Name Value
KOKKOSKERNELS_SOURCE_BRANCH RefactorSpgemm1
KOKKOSKERNELS_SOURCE_REPO https://github.com/brian-kelley/kokkos-kernels
KOKKOSKERNELS_SOURCE_SHA e0d7c05
KOKKOSKERNELS_TARGET_BRANCH develop
KOKKOSKERNELS_TARGET_REPO https://github.com/kokkos/kokkos-kernels
KOKKOSKERNELS_TARGET_SHA 9429243
PR_LABELS enhancement;Cleanup
PULLREQUESTNUM 1582
TEST_REPO_ALIAS KOKKOSKERNELS

Build Information

Test Name: KokkosKernels_PullRequest_GCC1020

  • Build Num: 92
  • Status: STARTED

Jenkins Parameters

Parameter Name Value
KOKKOSKERNELS_SOURCE_BRANCH RefactorSpgemm1
KOKKOSKERNELS_SOURCE_REPO https://github.com/brian-kelley/kokkos-kernels
KOKKOSKERNELS_SOURCE_SHA e0d7c05
KOKKOSKERNELS_TARGET_BRANCH develop
KOKKOSKERNELS_TARGET_REPO https://github.com/kokkos/kokkos-kernels
KOKKOSKERNELS_TARGET_SHA 9429243
PR_LABELS enhancement;Cleanup
PULLREQUESTNUM 1582
TEST_REPO_ALIAS KOKKOSKERNELS

Build Information

Test Name: KokkosKernels_PullRequest_GCC1020_Light_LayoutRight

  • Build Num: 91
  • Status: STARTED

Jenkins Parameters

Parameter Name Value
KOKKOSKERNELS_SOURCE_BRANCH RefactorSpgemm1
KOKKOSKERNELS_SOURCE_REPO https://github.com/brian-kelley/kokkos-kernels
KOKKOSKERNELS_SOURCE_SHA e0d7c05
KOKKOSKERNELS_TARGET_BRANCH develop
KOKKOSKERNELS_TARGET_REPO https://github.com/kokkos/kokkos-kernels
KOKKOSKERNELS_TARGET_SHA 9429243
PR_LABELS enhancement;Cleanup
PULLREQUESTNUM 1582
TEST_REPO_ALIAS KOKKOSKERNELS

Build Information

Test Name: KokkosKernels_PullRequest_Tpls_GCC1020

  • Build Num: 54
  • Status: STARTED

Jenkins Parameters

Parameter Name Value
KOKKOSKERNELS_SOURCE_BRANCH RefactorSpgemm1
KOKKOSKERNELS_SOURCE_REPO https://github.com/brian-kelley/kokkos-kernels
KOKKOSKERNELS_SOURCE_SHA e0d7c05
KOKKOSKERNELS_TARGET_BRANCH develop
KOKKOSKERNELS_TARGET_REPO https://github.com/kokkos/kokkos-kernels
KOKKOSKERNELS_TARGET_SHA 9429243
PR_LABELS enhancement;Cleanup
PULLREQUESTNUM 1582
TEST_REPO_ALIAS KOKKOSKERNELS

Build Information

Test Name: KokkosKernels_PullRequest_Tpls_INTEL19

  • Build Num: 141
  • Status: STARTED

Jenkins Parameters

Parameter Name Value
KOKKOSKERNELS_SOURCE_BRANCH RefactorSpgemm1
KOKKOSKERNELS_SOURCE_REPO https://github.com/brian-kelley/kokkos-kernels
KOKKOSKERNELS_SOURCE_SHA e0d7c05
KOKKOSKERNELS_TARGET_BRANCH develop
KOKKOSKERNELS_TARGET_REPO https://github.com/kokkos/kokkos-kernels
KOKKOSKERNELS_TARGET_SHA 9429243
PR_LABELS enhancement;Cleanup
PULLREQUESTNUM 1582
TEST_REPO_ALIAS KOKKOSKERNELS

Build Information

Test Name: KokkosKernels_PullRequest_CLANG1001

  • Build Num: 190
  • Status: STARTED

Jenkins Parameters

Parameter Name Value
KOKKOSKERNELS_SOURCE_BRANCH RefactorSpgemm1
KOKKOSKERNELS_SOURCE_REPO https://github.com/brian-kelley/kokkos-kernels
KOKKOSKERNELS_SOURCE_SHA e0d7c05
KOKKOSKERNELS_TARGET_BRANCH develop
KOKKOSKERNELS_TARGET_REPO https://github.com/kokkos/kokkos-kernels
KOKKOSKERNELS_TARGET_SHA 9429243
PR_LABELS enhancement;Cleanup
PULLREQUESTNUM 1582
TEST_REPO_ALIAS KOKKOSKERNELS

Build Information

Test Name: KokkosKernels_PullRequest_CLANG13CUDA10

  • Build Num: 78
  • Status: STARTED

Jenkins Parameters

Parameter Name Value
KOKKOSKERNELS_SOURCE_BRANCH RefactorSpgemm1
KOKKOSKERNELS_SOURCE_REPO https://github.com/brian-kelley/kokkos-kernels
KOKKOSKERNELS_SOURCE_SHA e0d7c05
KOKKOSKERNELS_TARGET_BRANCH develop
KOKKOSKERNELS_TARGET_REPO https://github.com/kokkos/kokkos-kernels
KOKKOSKERNELS_TARGET_SHA 9429243
PR_LABELS enhancement;Cleanup
PULLREQUESTNUM 1582
TEST_REPO_ALIAS KOKKOSKERNELS

Build Information

Test Name: KokkosKernels_PullRequest_Tpls_ARMPL2110_Tpls_ARMPL2030_GCC1020

  • Build Num: 82
  • Status: STARTED

Jenkins Parameters

Parameter Name Value
KOKKOSKERNELS_SOURCE_BRANCH RefactorSpgemm1
KOKKOSKERNELS_SOURCE_REPO https://github.com/brian-kelley/kokkos-kernels
KOKKOSKERNELS_SOURCE_SHA e0d7c05
KOKKOSKERNELS_TARGET_BRANCH develop
KOKKOSKERNELS_TARGET_REPO https://github.com/kokkos/kokkos-kernels
KOKKOSKERNELS_TARGET_SHA 9429243
PR_LABELS enhancement;Cleanup
PULLREQUESTNUM 1582
TEST_REPO_ALIAS KOKKOSKERNELS

Using Repos:

Repo: KOKKOSKERNELS (brian-kelley/kokkos-kernels)
  • Branch: RefactorSpgemm1
  • SHA: e0d7c05
  • Mode: TEST_REPO

Pull Request Author: brian-kelley

@kokkos-devops-admin
Copy link

Status Flag 'Pull Request AutoTester' - Jenkins Testing: all Jobs PASSED

Pull Request Auto Testing has PASSED (click to expand)

Build Information

Test Name: KokkosKernels_PullRequest_GCC930_Light_Tpls_GCC930

  • Build Num: 131
  • Status: PASSED

Jenkins Parameters

Parameter Name Value
KOKKOSKERNELS_SOURCE_BRANCH RefactorSpgemm1
KOKKOSKERNELS_SOURCE_REPO https://github.com/brian-kelley/kokkos-kernels
KOKKOSKERNELS_SOURCE_SHA e0d7c05
KOKKOSKERNELS_TARGET_BRANCH develop
KOKKOSKERNELS_TARGET_REPO https://github.com/kokkos/kokkos-kernels
KOKKOSKERNELS_TARGET_SHA 9429243
PR_LABELS enhancement;Cleanup
PULLREQUESTNUM 1582
TEST_REPO_ALIAS KOKKOSKERNELS

Build Information

Test Name: KokkosKernels_PullRequest_CUDA11_CUDA11_LayoutRight

  • Build Num: 139
  • Status: PASSED

Jenkins Parameters

Parameter Name Value
KOKKOSKERNELS_SOURCE_BRANCH RefactorSpgemm1
KOKKOSKERNELS_SOURCE_REPO https://github.com/brian-kelley/kokkos-kernels
KOKKOSKERNELS_SOURCE_SHA e0d7c05
KOKKOSKERNELS_TARGET_BRANCH develop
KOKKOSKERNELS_TARGET_REPO https://github.com/kokkos/kokkos-kernels
KOKKOSKERNELS_TARGET_SHA 9429243
PR_LABELS enhancement;Cleanup
PULLREQUESTNUM 1582
TEST_REPO_ALIAS KOKKOSKERNELS

Build Information

Test Name: KokkosKernels_PullRequest_GCC1020

  • Build Num: 92
  • Status: PASSED

Jenkins Parameters

Parameter Name Value
KOKKOSKERNELS_SOURCE_BRANCH RefactorSpgemm1
KOKKOSKERNELS_SOURCE_REPO https://github.com/brian-kelley/kokkos-kernels
KOKKOSKERNELS_SOURCE_SHA e0d7c05
KOKKOSKERNELS_TARGET_BRANCH develop
KOKKOSKERNELS_TARGET_REPO https://github.com/kokkos/kokkos-kernels
KOKKOSKERNELS_TARGET_SHA 9429243
PR_LABELS enhancement;Cleanup
PULLREQUESTNUM 1582
TEST_REPO_ALIAS KOKKOSKERNELS

Build Information

Test Name: KokkosKernels_PullRequest_GCC1020_Light_LayoutRight

  • Build Num: 91
  • Status: PASSED

Jenkins Parameters

Parameter Name Value
KOKKOSKERNELS_SOURCE_BRANCH RefactorSpgemm1
KOKKOSKERNELS_SOURCE_REPO https://github.com/brian-kelley/kokkos-kernels
KOKKOSKERNELS_SOURCE_SHA e0d7c05
KOKKOSKERNELS_TARGET_BRANCH develop
KOKKOSKERNELS_TARGET_REPO https://github.com/kokkos/kokkos-kernels
KOKKOSKERNELS_TARGET_SHA 9429243
PR_LABELS enhancement;Cleanup
PULLREQUESTNUM 1582
TEST_REPO_ALIAS KOKKOSKERNELS

Build Information

Test Name: KokkosKernels_PullRequest_Tpls_GCC1020

  • Build Num: 54
  • Status: PASSED

Jenkins Parameters

Parameter Name Value
KOKKOSKERNELS_SOURCE_BRANCH RefactorSpgemm1
KOKKOSKERNELS_SOURCE_REPO https://github.com/brian-kelley/kokkos-kernels
KOKKOSKERNELS_SOURCE_SHA e0d7c05
KOKKOSKERNELS_TARGET_BRANCH develop
KOKKOSKERNELS_TARGET_REPO https://github.com/kokkos/kokkos-kernels
KOKKOSKERNELS_TARGET_SHA 9429243
PR_LABELS enhancement;Cleanup
PULLREQUESTNUM 1582
TEST_REPO_ALIAS KOKKOSKERNELS

Build Information

Test Name: KokkosKernels_PullRequest_Tpls_INTEL19

  • Build Num: 141
  • Status: PASSED

Jenkins Parameters

Parameter Name Value
KOKKOSKERNELS_SOURCE_BRANCH RefactorSpgemm1
KOKKOSKERNELS_SOURCE_REPO https://github.com/brian-kelley/kokkos-kernels
KOKKOSKERNELS_SOURCE_SHA e0d7c05
KOKKOSKERNELS_TARGET_BRANCH develop
KOKKOSKERNELS_TARGET_REPO https://github.com/kokkos/kokkos-kernels
KOKKOSKERNELS_TARGET_SHA 9429243
PR_LABELS enhancement;Cleanup
PULLREQUESTNUM 1582
TEST_REPO_ALIAS KOKKOSKERNELS

Build Information

Test Name: KokkosKernels_PullRequest_CLANG1001

  • Build Num: 190
  • Status: PASSED

Jenkins Parameters

Parameter Name Value
KOKKOSKERNELS_SOURCE_BRANCH RefactorSpgemm1
KOKKOSKERNELS_SOURCE_REPO https://github.com/brian-kelley/kokkos-kernels
KOKKOSKERNELS_SOURCE_SHA e0d7c05
KOKKOSKERNELS_TARGET_BRANCH develop
KOKKOSKERNELS_TARGET_REPO https://github.com/kokkos/kokkos-kernels
KOKKOSKERNELS_TARGET_SHA 9429243
PR_LABELS enhancement;Cleanup
PULLREQUESTNUM 1582
TEST_REPO_ALIAS KOKKOSKERNELS

Build Information

Test Name: KokkosKernels_PullRequest_CLANG13CUDA10

  • Build Num: 78
  • Status: PASSED

Jenkins Parameters

Parameter Name Value
KOKKOSKERNELS_SOURCE_BRANCH RefactorSpgemm1
KOKKOSKERNELS_SOURCE_REPO https://github.com/brian-kelley/kokkos-kernels
KOKKOSKERNELS_SOURCE_SHA e0d7c05
KOKKOSKERNELS_TARGET_BRANCH develop
KOKKOSKERNELS_TARGET_REPO https://github.com/kokkos/kokkos-kernels
KOKKOSKERNELS_TARGET_SHA 9429243
PR_LABELS enhancement;Cleanup
PULLREQUESTNUM 1582
TEST_REPO_ALIAS KOKKOSKERNELS

Build Information

Test Name: KokkosKernels_PullRequest_Tpls_ARMPL2110_Tpls_ARMPL2030_GCC1020

  • Build Num: 82
  • Status: PASSED

Jenkins Parameters

Parameter Name Value
KOKKOSKERNELS_SOURCE_BRANCH RefactorSpgemm1
KOKKOSKERNELS_SOURCE_REPO https://github.com/brian-kelley/kokkos-kernels
KOKKOSKERNELS_SOURCE_SHA e0d7c05
KOKKOSKERNELS_TARGET_BRANCH develop
KOKKOSKERNELS_TARGET_REPO https://github.com/kokkos/kokkos-kernels
KOKKOSKERNELS_TARGET_SHA 9429243
PR_LABELS enhancement;Cleanup
PULLREQUESTNUM 1582
TEST_REPO_ALIAS KOKKOSKERNELS

@kokkos-devops-admin
Copy link

Status Flag 'Pre-Merge Inspection' - SUCCESS: The last commit to this Pull Request has been INSPECTED AND APPROVED by [ e10harvey lucbv ]!

@kokkos-devops-admin
Copy link

Status Flag 'Pull Request AutoTester' - Pull Request MUST BE MERGED MANUALLY BY Project Team - This Repo does not support Automerge

@brian-kelley brian-kelley merged commit 491fbfb into kokkos:develop Nov 2, 2022
@brian-kelley brian-kelley deleted the RefactorSpgemm1 branch November 2, 2022 01:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Cleanup Code maintenance that isn't a bugfix or new feature enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants