[all-commits] [llvm/llvm-project] 6a9ad5: [cuda][hip] Add CUDA builtin surface/texture refer...

darkbuck via All-commits all-commits at lists.llvm.org
Thu Mar 26 11:44:58 PDT 2020


  Branch: refs/heads/master
  Home:   https://github.com/llvm/llvm-project
  Commit: 6a9ad5f3f4ac66f0cae592e911f4baeb6ee5eca6
      https://github.com/llvm/llvm-project/commit/6a9ad5f3f4ac66f0cae592e911f4baeb6ee5eca6
  Author: Michael Liao <michael.hliao at gmail.com>
  Date:   2020-03-26 (Thu, 26 Mar 2020)

  Changed paths:
    M clang/include/clang/AST/Type.h
    M clang/include/clang/Basic/Attr.td
    M clang/include/clang/Basic/AttrDocs.td
    M clang/include/clang/Basic/DiagnosticSemaKinds.td
    M clang/lib/AST/Type.cpp
    M clang/lib/CodeGen/CGCUDANV.cpp
    M clang/lib/CodeGen/CGCUDARuntime.h
    M clang/lib/CodeGen/CGExprAgg.cpp
    M clang/lib/CodeGen/CodeGenModule.cpp
    M clang/lib/CodeGen/CodeGenTypes.cpp
    M clang/lib/CodeGen/TargetInfo.cpp
    M clang/lib/CodeGen/TargetInfo.h
    M clang/lib/Headers/__clang_cuda_runtime_wrapper.h
    M clang/lib/Sema/SemaDeclAttr.cpp
    M clang/lib/Sema/SemaDeclCXX.cpp
    A clang/test/CodeGenCUDA/surface.cu
    A clang/test/CodeGenCUDA/texture.cu
    M clang/test/Misc/pragma-attribute-supported-attributes-list.test
    M clang/test/SemaCUDA/attr-declspec.cu
    M clang/test/SemaCUDA/attributes-on-non-cuda.cu
    M clang/test/SemaCUDA/bad-attributes.cu
    M llvm/include/llvm/IR/Operator.h

  Log Message:
  -----------
  [cuda][hip] Add CUDA builtin surface/texture reference support.

Summary:
- Even though the bindless surface/texture interfaces are promoted,
  there are still code using surface/texture references. For example,
  [PR#26400](https://bugs.llvm.org/show_bug.cgi?id=26400) reports the
  compilation issue for code using `tex2D` with texture references. For
  better compatibility, this patch proposes the support of
  surface/texture references.
- Due to the absent documentation and magic headers, it's believed that
  `nvcc` does use builtins for texture support. From the limited NVVM
  documentation[^nvvm] and NVPTX backend texture/surface related
  tests[^test], it's believed that surface/texture references are
  supported by replacing their reference types, which are annotated with
  `device_builtin_surface_type`/`device_builtin_texture_type`, with the
  corresponding handle-like object types, `cudaSurfaceObject_t` or
  `cudaTextureObject_t`, in the device-side compilation. On the host
  side, that global handle variables are registered and will be
  established and updated later when corresponding binding/unbinding
  APIs are called[^bind]. Surface/texture references are most like
  device global variables but represented in different types on the host
  and device sides.
- In this patch, the following changes are proposed to support that
  behavior:
  + Refine `device_builtin_surface_type` and
    `device_builtin_texture_type` attributes to be applied on `Type`
    decl only to check whether a variable is of the surface/texture
    reference type.
  + Add hooks in code generation to replace that reference types with
    the correponding object types as well as all accesses to them. In
    particular, `nvvm.texsurf.handle.internal` should be used to load
    object handles from global reference variables[^texsurf] as well as
    metadata annotations.
  + Generate host-side registration with proper template argument
    parsing.

---
[^nvvm]: https://docs.nvidia.com/cuda/pdf/NVVM_IR_Specification.pdf
[^test]: https://raw.githubusercontent.com/llvm/llvm-project/master/llvm/test/CodeGen/NVPTX/tex-read-cuda.ll
[^bind]: See section 3.2.11.1.2 ``Texture reference API` in [CUDA C Programming Guide](https://docs.nvidia.com/cuda/pdf/CUDA_C_Programming_Guide.pdf).
[^texsurf]: According to NVVM IR, `nvvm.texsurf.handle` should be used.  But, the current backend doesn't have that supported. We may revise that later.

Reviewers: tra, rjmccall, yaxunl, a.sidorin

Subscribers: cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D76365




More information about the All-commits mailing list