Skip to content

[SYCL][CUDA][HIP] Guidance for __launch_bounds__ in SYCL  #8080

Description

@abagusetty

Is there a way to get/mention an equivalent functionality of __launch_bounds__() in SYCL.

Porting an optimized CUDA kernel to SYCL which preserves similar launch configuration (<<<....>>>) parameters, but without the functionality of __launch_bounds__() in SYCL leads to the following error because of the kernel launch specifies too many threads for the kernel's register count

Any suggestions: (a) One solution is to tweak with the global and local iteration space for the nd_range but wasn`t sure if this would be portable & performance approach when switching to other devices (i.e., PVC, MI250x, etc).

Error:

PI CUDA ERROR:
	Value:           701
	Name:            CUDA_ERROR_LAUNCH_OUT_OF_RESOURCES
	Description:     too many resources requested for launch
	Function:        cuda_piEnqueueKernelLaunch
	Source Location: ..../llvm_sycl/sycl/plugins/cuda/pi_cuda.cpp:3214

terminate called after throwing an instance of 'sycl::_V1::runtime_error'
  what():  Native API failed. Native API returns: -5 (PI_ERROR_OUT_OF_RESOURCES) -5 (PI_ERROR_OUT_OF_RESOURCES)

Activity

  1. abagusetty commented on Jan 23, 2023

    @abagusetty
    ContributorAuthor
  2. zjin-lcf commented on Jan 23, 2023

    @zjin-lcf
    Contributor

    __launch_bounds__() is seen in GPU programs written by researchers https://userweb.cs.txstate.edu/~burtscher/publications.html

  3. abagusetty commented on Jan 23, 2023

    @abagusetty
    ContributorAuthor

    __launch_bounds__() is seen in GPU programs written by researchers https://userweb.cs.txstate.edu/~burtscher/publications.html

    Thanks, Can you please point me the relevant publications among the above that makes use of launch_bounds() in SYCL

  4. zjin-lcf commented on Jan 23, 2023

    @zjin-lcf
    Contributor

    They make use of it in CUDA programs. Sorry for the confusion.

  5. npmiller commented on Jan 26, 2023

    @npmiller
    Contributor

    Unfortunately this is not something we currently support in DPC++, we'll have to look into enabling this attribute for SYCL.

    In the meantime, I haven't tested it carefully but it might be possible to tweak the register usage by using the ptxas flag --maxrregcount instead. You can pass it down through clang++ with the arguments: -Xcuda-ptxas --maxrregcount=<number>, for example:

    clang++ -fsycl -fsycl-targets=nvptx64-nvidia-cuda -Xsycl-target-backend --cuda-gpu-arch=sm_60 cr.cpp -o cr \
                  -Xcuda-ptxas --maxrregcount=32

    Note that ptxas is used during the linking stages in clang, so if you pass this when building with -c it will say the argument is unused.

  6. abagusetty commented on Jan 27, 2023

    @abagusetty
    ContributorAuthor

    @npmiller Thanks for the pointers. We had used -Xcuda-ptxas --maxrregcount=128 (for A100) as a possible work around. We came across 2 issues:

    1. (Major) It was still giving us the above error
    2. (Minor) The regcount is applied to all the kernels which might be detrimental. Since we have used __launch_bounds__() with varied values for individual kernels.
  7. zjin-lcf commented on Jan 27, 2023

    @zjin-lcf
    Contributor

    I hope there will be some links to the CUDA and SYCL programs in the future for studying the effect of "launch bounds" on the kernel characteristics.

  8. abagusetty commented on Feb 2, 2023

    @abagusetty
    ContributorAuthor

    Closing this.

  9. hdelan commented on Feb 9, 2023

    @hdelan
    Contributor

    Hi @abagusetty , this sounds like it may be a problem with index flipping. In CUDA the max dimensions of a Grid are for example:

      Max dimension size of a grid size    (x,y,z): (2147483647, 65535, 65535)
    

    In CUDA threads with globalIdx (0,0,0), (1,0,0) are adjacent.

    Whereas since the SYCL API wants work items to be arranged in a row major fashion, meaning the work items with globalIdx (0,0,0), (0,0,1) are adjacent. Since SYCL performs this index flipping, the corresponding max global range in SYCL would be:

      Max dimension size of a grid size    (x,y,z): (65535, 65535, 2147483647)
    

    Sometimes when applications are ported from CUDA to SYCL the dpct does not perform this index flipping, which can cause kernel launch failures. Let me know if this is what is happening. We have some documentation about this here:
    https://codeplay.com/portal/blogs/2019/11/18/computecpp-v1-1-6-changes-to-work-item-mapping-optimization.html

  10. jchlanda commented on Sep 15, 2023

    @jchlanda
    Contributor

    @abagusetty you might be interested to know that it is possible to express CUDA's:

    __launch_bounds__(maxThreadsPerBlock, minBlocksPerMultiprocessor, maxBlocksPerCluster)

    with the use of following attributes:

    • intel::max_work_group_size,
    • intel::min_work_groups_per_cu,
    • intel::max_work_groups_per_mp.

    For example:

    cgh.single_task<class T3>(
             [=]() [[intel::max_work_group_size(1, 1, 256),
                    intel::min_work_groups_per_cu(2),
                    intel::max_work_groups_per_mp(8)]] {
        ...
    }

    Subject to merging the PR: #11192

  11. jchlanda commented on Nov 10, 2023

    @jchlanda
    Contributor

    #11192 is now in, closing now.

    Please feel free to reopen, create a new ticket if there are any issues with launch bounds.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    cudaCUDA back-endenhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions