Coder Social home page Coder Social logo

Comments (9)

funsim avatar funsim commented on July 25, 2024

The branch with the suggested fix is called "issue14".

from firedrake.

dham avatar dham commented on July 25, 2024

You probably want to implement the copy using fnew.assign(f). This will
cause the copy to be implemented in a PyOP2 kernel with the effect that, in
the GPU case, you avoid a spurious copy back to host.

from firedrake.

dham avatar dham commented on July 25, 2024

I don't think that's correct. By just grabbing dat.val and using it as val,
you'll get two Functions which point to the same data space. I think you
want to create the new dat without Val and do the copy after.

from firedrake.

funsim avatar funsim commented on July 25, 2024

Good point.
I extended the test case to check that indeed a deep copy is created:

from firedrake import *

mesh = UnitIntervalMesh(2)
V = FunctionSpace(mesh, "CG", 1)
f = Function(V)
f.interpolate(Expression("1"))
assert (f.dat.vec.array == [1, 1, 1]).all() # Passes

g = Function(f)
print g.dat.vec.array
assert (g.dat.vec.array == [1, 1, 1]).all() # Fails

# Check that g is indeed a deep copy
f.dat.vec[:] = np.array([2, 2, 2])

assert (f.dat.vec.array == [2, 2, 2]).all()
assert (g.dat.vec.array == [1, 1, 1]).all()

Will work on a fix.

from firedrake.

wence- avatar wence- commented on July 25, 2024

FWIW, you should look at data in dats with:

f.dat.data_ro

The vec property is the petsc vector which won't play nicely with GPU implementations at the moment (CUDA doesn't currently use petsc).

Oh, and if you're going to write to things use f.dat.data.

So I'd write the test like:

m = UnitIntervalMesh(2)
V = FunctionSpace(m, 'CG', 1)
f = Function(V)
f.interpolate(Expression("1"))
assert (f.dat.data_ro == 1.0).all()
g = Function(f)
assert (g.dat.data_ro == 1.0).all()
g.interpolate(Expression("2"))
assert (g.dat.data_ro == 2.0).all()
assert (f.dat.data_ro == 1.0).all()

from firedrake.

dham avatar dham commented on July 25, 2024

In general, that's true. But in this case you shouldn't directly access the
data at all, but instead employ a par loop to do the copy.

from firedrake.

wence- avatar wence- commented on July 25, 2024

I meant in terms of the testing part.

from firedrake.

funsim avatar funsim commented on July 25, 2024

ok, will change that.

from firedrake.

wence- avatar wence- commented on July 25, 2024

Closed by 3af7d4b

from firedrake.

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.