Skip to content

Commit

Permalink
ReLU with tracing (Xilinx#1204)
Browse files Browse the repository at this point in the history
ReLU example with tracing

Co-authored-by: pjr <pjr@xilinx.com>
Co-authored-by: Joseph Melber <jgmelber@gmail.com>
  • Loading branch information
3 people authored and fifield committed Apr 12, 2024
1 parent ca82c22 commit b9701f6
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions aie_kernels/relu.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
//===- scale.cc -------------------------------------------------*- C++ -*-===//
//
// This file is 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
//
// Copyright (C) 2023, Advanced Micro Devices, Inc.
//
//===----------------------------------------------------------------------===//

#define __AIENGINE__ 2
#define NOCPP
#define __AIEARCH__ 20

#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <type_traits>

#include <aie_api/aie.hpp>

void relu(bfloat16 *restrict a, bfloat16 *restrict c, const int TILE_SIZE) {
const int v_factor = 32;
v32bfloat16 zeroes = broadcast_zero_bfloat16();

event0();
for (size_t i = 0; i < TILE_SIZE; i += v_factor)
chess_prepare_for_pipelining chess_loop_range(32, 32) {
v32bfloat16 input = *(v32bfloat16 *)(a + i);
v32bfloat16 output = max(input, zeroes);
*(v32bfloat16 *)(c + i) = output;
}
event1();
return;
}

extern "C" {

void bf16_relu(bfloat16 *a_in, bfloat16 *c_out) { relu(a_in, c_out, 1024); }

} // extern "C"

0 comments on commit b9701f6

Please sign in to comment.