[PATCH] D77777: [nvptx] Add `nvvm.texsurf.handle` internalizer.
Artem Belevich via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri Apr 10 23:09:43 PDT 2020
tra added a comment.
In D77777#1975628 <https://reviews.llvm.org/D77777#1975628>, @hliao wrote:
> In D77777#1975440 <https://reviews.llvm.org/D77777#1975440>, @tra wrote:
>
> > Also, if I read PTX docs correctly, it should be OK to pass texture handle address via an intermediate variable:
> > https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#texture-sampler-and-surface-types
> >
> > > Creating pointers to opaque variables using mov, e.g., mov.u64 reg, opaque_var;. The resulting pointer may be stored to and loaded from memory, passed as a parameter to functions, and de-referenced by texture and surface load, store, and query instructions
> >
> > We may not need the tokens and should be able to use regular pointer.
>
>
> That handle is the output of `texsurf.handle` intrinsic instead of its input. Internally within NVTPX backend, it needs to keep track of which global variable needs to be a `texref` or `surfref` and requires the operand of `texsurf.handle` must be a global variable. Check `NVPTXReplaceImageHandles.cpp` line 167 - 175.
That's the point I'm trying to make -- existing code may not be the best way to implement this and should be improved. If we are serious about supporting textures & surfaces, then it may be worth making it work properly, as opposed to adding more hacks to get the old and till-now largely unused bits of LLVM do what we want.
We could do something like this:
- class instances with the texref attribute are lowered in a way that produces a global handle. It could be a handle-only, or the handle may be produced in addition to the object itself.
- intrinsics accept texref pointers and follow standard LLVM rules/assumptions.
- => code is subject to regular LLVM optimizations
- => no need to have special passes to tweak IR just so. At worst, we may keep something similar to NVPTXReplaceImageHandles which would replace object references with handle references. We may not even need to do that. As far as LLVM is concerned texture handle is just a pointer, and the objects with texref attribute are lowered as a .texref global in PTX. It's user's responsibility to pass the right pointer to the intrinsic.
On a side note, the lowering of texture/surface instructions and intrinsics could use a major overhaul, too. It's currently excessively redundant and could be reduced to a much more concise tablegen-driven implementation.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D77777/new/
https://reviews.llvm.org/D77777
More information about the cfe-commits
mailing list