Giter Club home page Giter Club logo

Comments (6)

dpvanbalen avatar dpvanbalen commented on July 3, 2024

As far as I can see (but it's late, I'll check again tomorrow) this behaviour can't be supported by Accelerate. You can 'compose' Acc programs using run and use, but you can't use such a "lifted" function within Accelerate-level control flow (such as acond or awhile), I think. The cleanest way to avoid doing so, is to really divide your program such that each part is a single Accelerate program, using only 1 call to 'run'.
We could certainly do a better job reporting this; "Cyclic definition of a value of type 'Acc'" hints in the right direction but the first error is really meant as an internal sharing recovery error.

from accelerate.

justinlovinger avatar justinlovinger commented on July 3, 2024

@dpvanbalen I don't see a good way to separate objective functions from optimizers in this situation. Different optimizers call objective functions in different ways, and some may call an objective function multiple times or an indeterminate number of times.

Maybe I don't understand something about Accelerate, but couldn't a function like liftAcc wrap a non-Acc function so that it takes an Acc value, evaluates it if necessary, loads it into host memory, runs the given function, and loads the result back into device memory? I understand if you can't implement this liftAcc in terms of run and use, but is it possible for Accelerate to support such functionality?

from accelerate.

tmcdonell avatar tmcdonell commented on July 3, 2024

It sounds like your liftAcc is foreignAcc: call some foreign code and return the result back into accelerate?

from accelerate.

justinlovinger avatar justinlovinger commented on July 3, 2024

@tmcdonell That looks close to what I'm looking for. My liftAcc would look something like

liftAcc :: (Arrays as, Arrays bs) => (as -> bs) -> Acc as -> Acc bs

Unlike foreignAcc, it would not depend on choice of backend or have a fallback written in Acc.

from accelerate.

tmcdonell avatar tmcdonell commented on July 3, 2024

The fallback choice allows you to chain multiple implementations, presumably ending with one written in pure accelerate (or, error). I don't think we can really entirely remove the dependency on the particular backend, however, because e.g. a GPU needs to copy the results back to the host, but the CPU does not.

from accelerate.

justinlovinger avatar justinlovinger commented on July 3, 2024

@tmcdonell It sounds like you could implement liftAcc with a chain of foreignAcc, one for each backend, followed by an error. The main downside I see is you would need to update liftAcc for every new backend. It would be nice if this functionality lived in the accelerate package.

P.S. One of my motivations for wanting a function like liftAcc is convenience for users of my library that don't know Accelerate, so they can use it without learning Accelerate.

from accelerate.

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.