Skip to content

Commit

Permalink
Add prelu support for blackhole
Browse files Browse the repository at this point in the history
  • Loading branch information
mouliraj-mcw committed Nov 15, 2024
1 parent 6f0cf19 commit 34c469d
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@
#include "llk_math_eltwise_unary_sfpu_trigonometry.h"
#include "llk_math_eltwise_unary_sfpu_unary_comp.h"
#include "llk_math_eltwise_unary_sfpu_fill.h"
#include "llk_math_eltwise_unary_sfpu_prelu.h"
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// SPDX-FileCopyrightText: © 2024 Tenstorrent Inc.
//
// SPDX-License-Identifier: Apache-2.0

#pragma once

#include "ckernel.h"
#include "ckernel_defs.h"
#include "noc_nonblocking_api.h"
#include "ckernel_sfpu_converter.h"


using namespace sfpi;

namespace ckernel {
namespace sfpu {

template <bool APPROXIMATION_MODE, int ITERATIONS = 8>
inline void calculate_fill(const uint value) {

// SFPU microcode
Converter c_value;
c_value.u = value;
vFloat fill_val = c_value.f;

#pragma GCC unroll 0
for (int d = 0; d < ITERATIONS; d++)
{
vFloat a = dst_reg[0];
v_if(a < 0.0f) {
a = a * init;
}
v_endif;
dst_reg[0] = a;
dst_reg++;
}
}
} // namespace sfpu
} // namespace ckernel
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// SPDX-FileCopyrightText: © 2024 Tenstorrent Inc.
//
// SPDX-License-Identifier: Apache-2.0

#pragma once

#include "ckernel_sfpu_prelu.h"
#include "llk_math_eltwise_unary_sfpu_params.h"
#include "llk_math_eltwise_unary_sfpu_init.h"

namespace ckernel {

// New LLK SFPU APIs

template <bool APPROXIMATE>
inline void llk_math_eltwise_unary_sfpu_prelu_init() {
llk_math_eltwise_unary_sfpu_init<SfpuType::prelu, APPROXIMATE>();
}

template <bool APPROXIMATE>
inline void llk_math_eltwise_unary_sfpu_prelu(uint dst_index, uint param0, int vector_mode = (int)VectorMode::RC) {
llk_math_eltwise_unary_sfpu_params<APPROXIMATE>(
ckernel::sfpu::calculate_prelu<APPROXIMATE>,
dst_index,
vector_mode,
param0);
}

} // namespace ckernel
Original file line number Diff line number Diff line change
Expand Up @@ -87,5 +87,6 @@ enum SfpuType {
ceil,
unused,
cumsum,
fill
fill,
prelu,
};
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: © 2023 Tenstorrent Inc.
// SPDX-FileCopyrightText: © 2024 Tenstorrent Inc.
//
// SPDX-License-Identifier: Apache-2.0

Expand All @@ -23,7 +23,8 @@ inline void calculate_prelu(uint value) {
c_value.u = value;
vFloat init = c_value.f;

for (int d = 0; d < 8; d++)
#pragma GCC unroll 8
for (int d = 0; d < ITERATIONS; d++)
{
vFloat a = dst_reg[0];
v_if(a < 0.0f) {
Expand Down

0 comments on commit 34c469d

Please sign in to comment.