Giter Club home page Giter Club logo

Comments (3)

cliffburdick avatar cliffburdick commented on June 3, 2024 1

Hi @cenwangumass, it depends on how you allocate the tensor. If t was allocated using the standard way:

auto t = make_tensor<float>({10});

For example, then the default is to use managed memory. Managed memory is available on both host and device with the same pointer. You could them do something like:

std::vector<float> vec(10);
auto t = make_tensor<float>({10});
// Do some work on t
memcpy(vec.data(), t.Data(), t.Bytes());

// Or
for (int i = 0; i < vec.size(); i++) {
   vec(i) = t(i);
}

The same thing applies to an Eigen vector/tensor. Keep in mind that this will only work as above is the tensor is contiguous. If you have strided data (not compact) then you will need to either make a copy into a contiguous tensor first, or manually copy each element. Does that make sense?

from matx.

cliffburdick avatar cliffburdick commented on June 3, 2024 1

Technically you can also create a tensor and point it at vector memory:

std::vector<float> vec(10);
auto t2 = make_tensor<float>(vec.data(), {10});
auto t = make_tensor<float>({10});
(t2 = t).run(matx::HostExecutor{});

This should work too if you prefer that method.

from matx.

cenwangumass avatar cenwangumass commented on June 3, 2024

Thanks! I was already doing that. I was just looking for maybe a function or a method in matx.

from matx.

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.