Giter Club home page Giter Club logo

Comments (2)

marbre avatar marbre commented on August 29, 2024

Hi,

Asking here is perfectly fine. As the EmitC dialect is already upstreamed to MLIR core, it is also fine to ask question on https://llvm.discourse.group/c/mlir/31 or to discuss these on discord in the #mlir channel.

Regarding your question: Right now, we don't have any math implemented in EmitC itself. The only operators that can be applied with emitc.apply are & and *. Everything else need to be done via emitc.call ops. Thus you do more than a single line of C++ code. Instead of adding an example to the repo, let me to give on and comment on it here. For example the snippet

builtin.module  {
  builtin.func @test_add(%arg0: tensor<13x21x3xf32>, %arg1: tensor<13x21x3xf32>) -> tensor<13x21x3xf32> {
    %0 = "tosa.add"(%arg0, %arg1) : (tensor<13x21x3xf32>, tensor<13x21x3xf32>) -> tensor<13x21x3xf32>
    return %0 : tensor<13x21x3xf32>
  }
}

can be converted to

builtin.module  {
  emitc.include "emitc_tosa.h"
  builtin.func @test_add(%arg0: tensor<13x21x3xf32>, %arg1: tensor<13x21x3xf32>) -> tensor<13x21x3xf32> {
    %0 = emitc.call "emitc::tosa::add"(%arg0, %arg1) : (tensor<13x21x3xf32>, tensor<13x21x3xf32>) -> tensor<13x21x3xf32>
    return %0 : tensor<13x21x3xf32>
  }
}

using emitc-opt --tosa-to-emitc-pipeline. This can be translated with emitc-translate --mlir-to-cpp to the C++ source code below:

#include "emitc_tosa.h"
Tensor<float, 13, 21, 3> test_add(Tensor<float, 13, 21, 3> v1, Tensor<float, 13, 21, 3> v2) {
  Tensor<float, 13, 21, 3> v3 = emitc::tosa::add(v1, v2);
  return v3;
}

The called C++ function is a templated one and refers to the standard library:

// AddOp
template <typename Src>
inline Src add(Src x, Src y) {
using ET_Src = typename get_element_type<Src>::type;
auto f = std::plus<ET_Src>{};
return binary<Src>(x, y, f);
}

It is not the aim of EmitC to be an MLIR dialect that represents C++ as complete as possible. However, we are of course willing to evolve the dialect. You might also want to take a look into this discussion.

I hope this answers your question?

from mlir-emitc.

ivangarcia44 avatar ivangarcia44 commented on August 29, 2024

Yes, I have a clearer picture now. Thanks!

from mlir-emitc.

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.