Skip to content

Conversation

@wonjoo-wj
Copy link
Collaborator

@wonjoo-wj wonjoo-wj commented May 12, 2022

Codegen acos and acosh


Generated XLANativeFunctions.cpp:

    at::Tensor XLANativeFunctions::acos(const at::Tensor & self) {
        
        XLA_FN_COUNTER("xla::");
        auto common_device = torch_xla::bridge::GetXlaDevice(self);
        TORCH_INTERNAL_ASSERT(common_device);
        
        torch_xla::XLATensorPtr lazy_self = torch_xla::bridge::GetXlaTensorOrCreateForWrappedNumber(self, *common_device);
        auto out_meta = at::meta::acos(self);
        std::vector<torch::lazy::Shape> shapes{
        torch::lazy::Shape(out_meta.scalar_type(), out_meta.sizes().vec())};
        TORCH_INTERNAL_ASSERT(shapes.size() == 1);
        if(torch::lazy::symbolicShapeEnabled()){
            std::vector<torch::jit::IValue> inputs = { self };
            char* schema_str = "aten::acos(Tensor self) -> Tensor";
            applySymbolicShapesOnLT(schema_str, inputs, shapes);
        }
        
        auto node = torch::lazy::MakeNode<Acos>(lazy_self->GetIrValue(),
                                                                                      std::move(shapes));
        auto result = torch_xla::bridge::AtenFromXlaTensor(
                torch_xla::XLATensor::Create(std::move(node), *common_device));
        return result;
    };

    
    at::Tensor XLANativeFunctions::acosh(const at::Tensor & self) {
        
        XLA_FN_COUNTER("xla::");
        auto common_device = torch_xla::bridge::GetXlaDevice(self);
        TORCH_INTERNAL_ASSERT(common_device);
        
        torch_xla::XLATensorPtr lazy_self = torch_xla::bridge::GetXlaTensorOrCreateForWrappedNumber(self, *common_device);
        auto out_meta = at::meta::acosh(self);
        std::vector<torch::lazy::Shape> shapes{
        torch::lazy::Shape(out_meta.scalar_type(), out_meta.sizes().vec())};
        TORCH_INTERNAL_ASSERT(shapes.size() == 1);
        if(torch::lazy::symbolicShapeEnabled()){
            std::vector<torch::jit::IValue> inputs = { self };
            char* schema_str = "aten::acosh(Tensor self) -> Tensor";
            applySymbolicShapesOnLT(schema_str, inputs, shapes);
        }
        
        auto node = torch::lazy::MakeNode<Acosh>(lazy_self->GetIrValue(),
                                                                                      std::move(shapes));
        auto result = torch_xla::bridge::AtenFromXlaTensor(
                torch_xla::XLATensor::Create(std::move(node), *common_device));
        return result;
    };

Generated LazyIr.h:

class Acos : public XlaNode {
 public:
  static torch::lazy::OpKind ClassOpKind() {
    return torch::lazy::OpKind(at::aten::acos);
  }

  Acos(const torch_xla::XlaValue& self, std::vector<torch::lazy::Shape>&& shapes)

      : XlaNode(torch::lazy::OpKind(at::aten::acos),
              {self}, std::move(shapes),
              [&]() { return AcosOutputShape(self); },
              /* num_outputs */ 1,
              torch::lazy::MHash())
        

  {
    
  }

  std::string ToString() const override {
    std::stringstream ss;
    ss << XlaNode::ToString();
    
    return ss.str();
  }

  torch_xla::XlaOpVector Lower(LoweringContext* loctx) const override;

  
  

};

class Acosh : public XlaNode {
 public:
  static torch::lazy::OpKind ClassOpKind() {
    return torch::lazy::OpKind(at::aten::acosh);
  }

  Acosh(const torch_xla::XlaValue& self, std::vector<torch::lazy::Shape>&& shapes)

      : XlaNode(torch::lazy::OpKind(at::aten::acosh),
              {self}, std::move(shapes),
              [&]() { return AcoshOutputShape(self); },
              /* num_outputs */ 1,
              torch::lazy::MHash())
        

  {
    
  }

  std::string ToString() const override {
    std::stringstream ss;
    ss << XlaNode::ToString();
    
    return ss.str();
  }

  torch_xla::XlaOpVector Lower(LoweringContext* loctx) const override;

  
  

};

@wonjoo-wj wonjoo-wj self-assigned this May 12, 2022
torch_xla/csrc/RegisterAutogradXLA.cpp

# Directory autogenerated by full_codegen
torch_xla/csrc/generated/
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed the new generated directory getting tracked by git, so I've added to the ignore list. Let me know if this is okay.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@wonjoo-wj wonjoo-wj force-pushed the codegen-acos-acosh branch from bd6ffcf to df078ed Compare May 12, 2022 18:29
@JackCaoG
Copy link
Collaborator

@wonjoolee95 Can you also posted the generated XLANativeFunction.cpp and LazyIr.h only for the acos and acosh part. I think this will make review a bit easier.

@wonjoo-wj
Copy link
Collaborator Author

@wonjoolee95 Can you also posted the generated XLANativeFunction.cpp and LazyIr.h only for the acos and acosh part. I think this will make review a bit easier.

@JackCaoG Good point! Updated the PR summary on top with the two generated files.

@wonjoo-wj wonjoo-wj requested a review from JackCaoG May 12, 2022 22:57
@JackCaoG
Copy link
Collaborator

Thanks Wonjoo!

@JackCaoG JackCaoG merged commit 2cc13c0 into master May 12, 2022
@JackCaoG JackCaoG deleted the codegen-acos-acosh branch May 12, 2022 23:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants