Giter Site home page Giter Site logo

Comments (6)

Ruyk avatar Ruyk commented on May 29, 2024

What would be the expected behaviour? According to the POSIX and C standards, malloc of size 0 behavior:

 If the size of the space requested is 0, the behavior is implementation-defined: either a null pointer shall be returned, or the behavior shall be as if the size were some non-zero value, except that the behavior is undefined if the returned pointer is used to access an object

Which is technically what is happening. I am happy to return a nullptr if that makes detecting errors easier...

from computecpp-sdk.

DuncanMcBain avatar DuncanMcBain commented on May 29, 2024

I believe either one of TensorFlow or Eigen relies on size-zero allocations being allowed. In that case, a nullptr would be a problem. However, I think the current behaviour isn't consistent with the second bullet point - shouldn't malloc return unique pointers? Moreover, this means that the PointerMapper will misbehave (what happens when you try to free once, or three times?)

from computecpp-sdk.

r-potter avatar r-potter commented on May 29, 2024

I agree with @DuncanMcBain . Either null or the equivalent of a non-zero allocation would be fine (although I believe there is some Eigen or Tensorflow requirement that prefers non-null). What's problematic is returning the same non-null address. There is actually a much more problematic case:

auto a = SYCLMalloc(0, pMap); // Returns 0x1000
auto b = SYCLMalloc(4096, pMap); // Returns 0x1000 + 0
if (a) {
    SYCLFree(a, pMap); // b gets accidentally freed because it shares an address.
}

This is why POSIX says the equivalent of a non-zero allocation. It ensures allocations get unique addresses, and that free can determine what to actually release without aliasing other allocations.

from computecpp-sdk.

Ruyk avatar Ruyk commented on May 29, 2024

That makes sense to me. I didn't realize at first about the potential double free issue.

Thanks for the pull request from @Rbiessy, this is sorted out now. If you are happy with the solution I think we can close it.

from computecpp-sdk.

r-potter avatar r-potter commented on May 29, 2024

LGTM

from computecpp-sdk.

DuncanMcBain avatar DuncanMcBain commented on May 29, 2024

Thanks, all!

from computecpp-sdk.

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.