Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion include/fusilli/attributes/pointwise_attributes.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ namespace fusilli {
OP(MIN_OP) \
OP(MUL) \
OP(NEG) \
/* OP(RECIPROCAL) */ \
OP(RECIPROCAL) \
/* OP(RELU_BWD) */ \
OP(RELU_FWD) \
/* OP(RSQRT) */ \
Expand Down Expand Up @@ -146,6 +146,7 @@ inline const std::unordered_map<PointwiseAttr::Mode, int>
{PointwiseAttr::Mode::MIN_OP, 2},
{PointwiseAttr::Mode::MUL, 2},
{PointwiseAttr::Mode::NEG, 1},
{PointwiseAttr::Mode::RECIPROCAL, 1},
{PointwiseAttr::Mode::RELU_FWD, 1},
{PointwiseAttr::Mode::SIGMOID_FWD, 1},
{PointwiseAttr::Mode::SUB, 2},
Expand Down
1 change: 1 addition & 0 deletions include/fusilli/support/asm_emitter.h
Original file line number Diff line number Diff line change
Expand Up @@ -1780,6 +1780,7 @@ inline ErrorOr<std::string> PointwiseNode::emitNodePreAsm() const {
FUSILLI_DECLARE_BINARY_TORCH_EMITTER(MIN_OP, torch.aten.minimum)
FUSILLI_DECLARE_BINARY_TORCH_EMITTER(MUL, torch.aten.mul.Tensor)
FUSILLI_DECLARE_UNARY_TORCH_EMITTER(NEG, torch.aten.neg)
FUSILLI_DECLARE_UNARY_TORCH_EMITTER(RECIPROCAL, torch.aten.reciprocal)
FUSILLI_DECLARE_UNARY_TORCH_EMITTER(RELU_FWD, torch.aten.relu)
FUSILLI_DECLARE_UNARY_TORCH_EMITTER(SIGMOID_FWD, torch.aten.sigmoid)
FUSILLI_DECLARE_UNARY_TORCH_EMITTER(TANH_FWD, torch.aten.tanh)
Expand Down
41 changes: 39 additions & 2 deletions samples/pointwise/pointwise_unary_ops.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,35 @@ static std::string generateName(PointwiseAttr::Mode mode, DataType type,
TEST_CASE("Pointwise unary ops", "[pointwise][graph]") {
const auto dim = std::vector<int64_t>{2, 16, 64, 64};

auto supportsInteger = [](PointwiseAttr::Mode m) {
switch (m) {
case PointwiseAttr::Mode::ABS:
case PointwiseAttr::Mode::NEG:
case PointwiseAttr::Mode::RELU_FWD:
return true;
default:
return false;
}
};

auto supportsFloat = [](PointwiseAttr::Mode m) {
switch (m) {
case PointwiseAttr::Mode::ABS:
case PointwiseAttr::Mode::CEIL:
case PointwiseAttr::Mode::ERF:
case PointwiseAttr::Mode::EXP:
case PointwiseAttr::Mode::FLOOR:
case PointwiseAttr::Mode::NEG:
case PointwiseAttr::Mode::RECIPROCAL:
case PointwiseAttr::Mode::RELU_FWD:
case PointwiseAttr::Mode::SIGMOID_FWD:
case PointwiseAttr::Mode::TANH_FWD:
return true;
default:
return false;
}
};

// clang-format off
const auto mode = GENERATE(
PointwiseAttr::Mode::ABS,
Expand All @@ -47,6 +76,7 @@ TEST_CASE("Pointwise unary ops", "[pointwise][graph]") {
PointwiseAttr::Mode::EXP,
PointwiseAttr::Mode::FLOOR,
PointwiseAttr::Mode::NEG,
PointwiseAttr::Mode::RECIPROCAL,
PointwiseAttr::Mode::RELU_FWD,
PointwiseAttr::Mode::SIGMOID_FWD,
PointwiseAttr::Mode::TANH_FWD);
Expand Down Expand Up @@ -148,6 +178,11 @@ TEST_CASE("Pointwise unary ops", "[pointwise][graph]") {
y = -x;
break;
}
case PointwiseAttr::Mode::RECIPROCAL: {
double xD = static_cast<double>(x);
y = 1.0 / xD;
break;
}
default:
FAIL(
"Unsupported pointwise mode: " << PointwiseAttr::kModeToStr.at(mode));
Expand Down Expand Up @@ -185,7 +220,9 @@ TEST_CASE("Pointwise unary ops", "[pointwise][graph]") {
FUSILLI_REQUIRE_ASSIGN(Handle handle, Handle::create(kDefaultBackend));

// int32
execute(handle, DataType::Int32, int(-128));
if (supportsInteger(mode))
execute(handle, DataType::Int32, int(-128));
// fp16
execute(handle, DataType::Half, half(3.14));
if (supportsFloat(mode))
execute(handle, DataType::Half, half(3.14));
}
1 change: 1 addition & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ add_fusilli_lit_tests(
lit/test_pointwise_asm_emitter_mul.cpp
lit/test_pointwise_asm_emitter_mul_scalar.cpp
lit/test_pointwise_asm_emitter_neg.cpp
lit/test_pointwise_asm_emitter_reciprocal.cpp
lit/test_pointwise_asm_emitter_sigmoid.cpp
lit/test_pointwise_asm_emitter_tanh.cpp
lit/test_pointwise_asm_emitter_sub.cpp
Expand Down
60 changes: 60 additions & 0 deletions tests/lit/test_pointwise_asm_emitter_reciprocal.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// Copyright 2026 Advanced Micro Devices, Inc.
//
// Licensed under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

// RUN: %{TEST_EXE} | iree-opt --verify-roundtrip
// RUN: %{TEST_EXE} | FileCheck %s --check-prefix=TORCH-CHECK
// RUN: %{TEST_EXE} stats | FileCheck %s --check-prefix=%{BACKEND}-STATS-CHECK

// clang-format off
//
// TORCH-CHECK: module @module {
// TORCH-CHECK: func.func @main(%[[RESULT0:.+]]: !torch.tensor<[16,256,64,32],f32>, %[[ARG0:.+]]: !torch.vtensor<[16,256,64,32],f32>) attributes {torch.assume_strict_symbolic_shapes} {
// TORCH-CHECK: %[[PERM0_0:.+]] = torch.constant.int 0
// TORCH-CHECK: %[[PERM0_1:.+]] = torch.constant.int 1
// TORCH-CHECK: %[[PERM0_2:.+]] = torch.constant.int 2
// TORCH-CHECK: %[[PERM0_3:.+]] = torch.constant.int 3
// TORCH-CHECK: %[[PERM0_LIST:.+]] = torch.prim.ListConstruct %[[PERM0_0]], %[[PERM0_1]], %[[PERM0_2]], %[[PERM0_3]] : (!torch.int, !torch.int, !torch.int, !torch.int) -> !torch.list<int>
// TORCH-CHECK: %[[PERMUTE0:.+]] = torch.aten.permute %[[ARG0]], %[[PERM0_LIST]] : !torch.vtensor<[16,256,64,32],f32>, !torch.list<int> -> !torch.vtensor<[16,256,64,32],f32>
// TORCH-CHECK: %[[RECIPROCAL:.+]] = torch.aten.reciprocal %[[PERMUTE0]] : !torch.vtensor<[16,256,64,32],f32> -> !torch.vtensor<[16,256,64,32],f32>
// TORCH-CHECK: %[[PERM_OUT_0:.+]] = torch.constant.int 0
// TORCH-CHECK: %[[PERM_OUT_1:.+]] = torch.constant.int 1
// TORCH-CHECK: %[[PERM_OUT_2:.+]] = torch.constant.int 2
// TORCH-CHECK: %[[PERM_OUT_3:.+]] = torch.constant.int 3
// TORCH-CHECK: %[[PERM_OUT_LIST:.+]] = torch.prim.ListConstruct %[[PERM_OUT_0]], %[[PERM_OUT_1]], %[[PERM_OUT_2]], %[[PERM_OUT_3]] : (!torch.int, !torch.int, !torch.int, !torch.int) -> !torch.list<int>
// TORCH-CHECK: %[[PERM_OUT:.+]] = torch.aten.permute %[[RECIPROCAL]], %[[PERM_OUT_LIST]] : !torch.vtensor<[16,256,64,32],f32>, !torch.list<int> -> !torch.vtensor<[16,256,64,32],f32>
// TORCH-CHECK: torch.overwrite.tensor.contents %[[PERM_OUT]] overwrites %[[RESULT0]] : !torch.vtensor<[16,256,64,32],f32>, !torch.tensor<[16,256,64,32],f32>
// TORCH-CHECK: return
// TORCH-CHECK: }
// TORCH-CHECK: }
//
// AMDGPU-STATS-CHECK: "transient-memory-size": 0
// AMDGPU-STATS-CHECK: "dispatch-count": 1
// CPU-STATS-CHECK: "transient-memory-size": 0
// CPU-STATS-CHECK: "dispatch-count": 1
//
// clang-format on

#include <fusilli.h>

#include "utils.h"

#include <iostream>
#include <string>

using namespace fusilli;

int main(int argc, char **argv) {
std::string mode = (argc > 1) ? argv[1] : "default";

auto status = testUnaryPointwiseAsmEmitter(
"pointwise_asm_emitter_reciprocal", "reciprocal", mode,
PointwiseAttr::Mode::RECIPROCAL, {16, 256, 64, 32});
if (isError(status)) {
std::cerr << "Test failed: " << status << std::endl;
return 1;
}
return 0;
}
Loading