Coder Social home page Coder Social logo

Comments (1)

pfultz2 avatar pfultz2 commented on July 26, 2024

Thinkng about this more, we can reuse our memory_coloring pass and then just do some post processing.

So first we would lower the pointwise operators to an inner_pointwise that takes an allocate instruction. The size of allocation can just be the shape of the pointwise instruction(the size of the instruction is not really important as long as each one is the same size).

Then we run memory_coloing and then replace the inner_pointwise with the first load with a pointwise and the other loads we would replace to reference the first pointwise:

std::unordered_map<std::size_t, instruction_ref> load2ins;
for(auto ins:iterator_for(m))
{
    if (ins->name() != "gpu::inner_pointwise")
        continue;
    auto out = ins->inputs().back();
    auto inputs = ins->inputs();
    auto offset = out.to_value()["offset"].to<std::size_t>();
    if(contains(load2ins, offset))
    {
        auto i = load2ins[offset];
        inputs.back() = i;
        m.replace_instruction(ins, ins->get_operator(), inputs, ins->module_inputs());
    }
    else
    {
        load2ins[offset] = ins;
        inputs.pop_back();
        m.replace_instruction(ins, make_op("pointwise"), inputs, ins->module_inputs());
    }
}

We will need to update the codegen to handle aliased variables. So when an instruction aliases, instead of generating a return variable(ie auto zn = f(...)) instead it would generate the statement standalone(ie f(x)) and then update the mapping to refer to the original variable that is aliased.

There is still one issue that would need to be solved. If two inner_pointwise use different data types then we shouldn't reuse the buffers. We could possibly fix this by running memory_coloring multiple times for each type.

from amdmigraphx.

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.