Giter Club home page Giter Club logo

Comments (2)

rjodinchr avatar rjodinchr commented on September 21, 2024

This one is quite complicated

TL;DR: https://godbolt.org/z/zj9zedzf8

  • Memory is in the global address space, thus the cast to (struct S*) should be (global Struct *)
  • Because Memory is just used to be casted to long, we need to compile with -cl-kernel-arg-info to help clspv figure out Memory type. Note that clvk compiles by default with this option.
  • As you are doing pointer arithmetic, you definitively need to use physical addressing (compile with -physical-storage-buffers -arch=spir64). We have a LogicalPointerToIntPass but it does not support this case. It should be able to be implemented, but that would require some work.

With all that, this example is compiled correctly.

from clspv.

BukeBeyond avatar BukeBeyond commented on September 21, 2024

Thank you for looking into this Mr. Jodin.

The interesting thing is, in CLC++ mode, Clspv infers address spaces when memcpy is not involved, as you can see below. Clspv just converts remaining generic address spaces to global in the LowerAddrSpaceCastPass for simple loads and stores. However, there seems to be some difficulty doing this for memcpy.

When looking at Clang's IR from CLC++ you will see it extensively emits the generic addrspace(4), even when No function calls or generics are used! Because the programmer has no control of these, Clspv handling the generic spaces with memcpy is probably essential for stability. Here are some additional observations at #1179

Here the (int*) inference is working. Also when using external Clang compilation with optimizations, S* inference works too, because it has been reduced to a single int i1.

struct S { int i1; };

kernel void Kernel(global void* Memory)
{
    long a = (long) Memory;

    * (int*) a = 0; // OK, address space inferred
    // * (S*) a = {}; // Fails, address space not inferred. OK if externally optimized
    // * (global S*) a = {}; // OK, address space explicit
}

https://godbolt.org/z/qj4WhbMG1

Isn't it nice to have the modern syntax! :-)

from clspv.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.