Skip to content

Commit

Permalink
Add support for Gaudi2
Browse files Browse the repository at this point in the history
Add the support for running TPC kernels on Gaudi2 device.
Gaudi2 support was first added to the Linux kernel in kernel 5.7.

Signed-off-by: Guy Malinovitch <[email protected]>
Reviewed-by: Oded Gabbay <[email protected]>
Signed-off-by: Oded Gabbay <[email protected]>
  • Loading branch information
Guy Malinovitch authored and ogabbay committed Nov 27, 2022
1 parent 266a395 commit 5fe9e24
Show file tree
Hide file tree
Showing 107 changed files with 80,520 additions and 884 deletions.
13 changes: 11 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
build
*.so
*.cmake
Makefile
CMakeFiles
CMakeCache.txt
tests/*_test
build/
.cproject
.project
.settings
.settings/
.vscode/
.gdbinit
.cache
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ project(synapse_core)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -Werror -Wno-sign-compare -fno-strict-aliasing")

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pipe")
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 8.0)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-attributes")
Expand Down
16 changes: 15 additions & 1 deletion build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,19 @@ set -e
# then you need to define EXTRA_CMAKE_FLAGS as:
# EXTRA_CMAKE_FLAGS=-DDRIVER_INCLUDE_PATH=$HOME/habanalabs/include/uapi

SECONDS=0;
SRCDIR=`dirname $0`
BUILDDIR="$SRCDIR/build"
build_type="Release"

while [ -n "$1" ]; do
case $1 in
-debug)
build_type="Debug"
;;
esac;
shift;
done

if [ -d $BUILDDIR ]; then
rm -rf $BUILDDIR
Expand All @@ -41,5 +52,8 @@ fi

cd "$BUILDDIR"

$CMAKE -DCMAKE_BUILD_TYPE="Release" ${EXTRA_CMAKE_FLAGS:-} ..
$CMAKE -DCMAKE_BUILD_TYPE=${build_type} ${EXTRA_CMAKE_FLAGS:-} ..
make -j8

printf "\nElapsed time: %02u:%02u:%02u \n\n" $(($SECONDS / 3600)) $((($SECONDS / 60) % 60)) $(($SECONDS % 60));

7 changes: 7 additions & 0 deletions external_includes/SpecialFuncCoefficients.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,10 @@ namespace tpc_gaudi {
uint8_t *getLUTStartAddressFromFuncID(uint32_t funcID, uint8_t* baseAddr);
uint32_t getCoefAddrFromOffset(uint8_t offset, bool isLOOKUP, uint32_t elementSize);
}

namespace tpc_gaudi2
{
void buildSpecialFunctionCoefficients(std::vector<std::vector<uint8_t>>& specialFunctionCoefficients);
uint8_t* getLUTStartAddressFromFuncID(uint32_t funcID, uint8_t* baseAddr);
uint32_t getCoefAddrFromOffset(uint8_t offset, bool isLOOKUP, uint32_t elementSize);
} // namespace tpc_gaudi2
31 changes: 26 additions & 5 deletions external_includes/TensorDescriptor.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#pragma once

#include "synapse_common_types.h"
#include <stdint.h>
#include <cassert>

Expand Down Expand Up @@ -42,7 +43,7 @@ DEF_PACK(

typedef struct _TensorDescriptorBase TensorDescriptorBase;

struct TensorDescriptorGaudi : public TensorDescriptorBase
struct TensorDescriptor : public TensorDescriptorBase
{
/* for Gaudi:
TENSOR_0_BASE_ADDR_LOW +0x00 32 0 Read/Write bits 31 to 0 of the base address no no no
Expand Down Expand Up @@ -84,20 +85,40 @@ typedef enum TensorDataType_
uint32_t gen2_TensorDescriptorElementSizeType(uint32_t configuration);
uint32_t gen2_TensorDescriptorValidDimMask(uint32_t configuration);
uint32_t gen2_TensorDescriptorLastDim(uint32_t configuration);
uint32_t gen6_TensorDescriptorElementSizeType(uint32_t configuration);
uint32_t gen6_TensorDescriptorValidDimMask(uint32_t configuration);
uint32_t gen6_TensorDescriptorLastDim(uint32_t configuration);

namespace tpc_gaudi {
inline uint32_t get_TensorDescriptorLastDim(uint32_t configuration)
{
return gen2_TensorDescriptorLastDim(configuration);
}
inline uint32_t get_TensorDescriptorElementSizeType(uint32_t configuration)
{
return gen2_TensorDescriptorElementSizeType(configuration);
inline uint32_t get_TensorDescriptorElementSizeType(uint32_t configuration)
{
return gen2_TensorDescriptorElementSizeType(configuration);
}
inline uint32_t get_TensorDescriptorValidDimMask(uint32_t configuration)
{
{
return gen2_TensorDescriptorValidDimMask(configuration);
}
uint32_t TensorDescriptorConfiguration(uint32_t dataType, uint32_t validDimMask, uint32_t lastDim, uint32_t rmwSel, uint32_t rmwOp);
uint32_t get_ElementSizeInBytesFromDataType(TensorDataType DataType);
}

namespace tpc_gaudi2 {
inline uint32_t get_TensorDescriptorLastDim(uint32_t configuration)
{
return gen6_TensorDescriptorLastDim(configuration);
}
inline uint32_t get_TensorDescriptorElementSizeType(uint32_t configuration)
{
return gen6_TensorDescriptorElementSizeType(configuration);
}
inline uint32_t get_TensorDescriptorValidDimMask(uint32_t configuration)
{
return gen6_TensorDescriptorValidDimMask(configuration);
}
uint32_t TensorDescriptorConfiguration(uint32_t dataType, uint32_t validDimMask, uint32_t lastDim, uint32_t rmwSel, uint32_t rmwOp);
uint32_t get_ElementSizeInBytesFromDataType(TensorDataType DataType);
}
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
#include <stdint.h>

#pragma pack(push, 1)

namespace gaudi
{
namespace dma_core {
/*
CFG_0
Expand Down Expand Up @@ -1039,6 +1040,6 @@ const offsetVal block_dma_core_defaults[]
{ 0x130 , 0x1 , 1 }, // wr_awuser_31_11
{ 0x230 , 0x178 , 1 }, // dbg_sts
};

} // namespace gaudi
#pragma pack(pop)
#endif /* ASIC_REG_STRUCTS_DMA_CORE_H_ */
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,15 @@

#pragma pack(push, 1)

namespace gaudi
{
struct offsetVal
{
uint32_t offset;
uint32_t val;
int copies;
};

} // namespace gaudi
#pragma pack(pop)
#endif /* ASIC_REG_STRUCTS_GAUDI_TYPES_H_ */
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
#include <stdint.h>

#pragma pack(push, 1)

namespace gaudi
{
namespace qman {
/*
GLBL_CFG0
Expand Down Expand Up @@ -1954,7 +1955,10 @@ struct block_qman {
uint32_t _pad3292[9];
struct qman::reg_glbl_mem_init_busy glbl_mem_init_busy;
};
} // namespace gaudi
#include "gaudi_types.h"
namespace gaudi
{
const offsetVal block_qman_defaults[]
{
// offset // value
Expand Down Expand Up @@ -1986,5 +1990,6 @@ const offsetVal block_qman_defaults[]
{ 0xc84 , 0x2000 , 1 }, // local_range_size
};

} //namespace gaudi
#pragma pack(pop)
#endif /* ASIC_REG_STRUCTS_QMAN_H_ */
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
#include <stdint.h>

#pragma pack(push, 1)

namespace gaudi
{
namespace sob_glbl {
/*
SM_SEI_MASK
Expand Down Expand Up @@ -50,5 +51,6 @@ struct block_sob_glbl {
struct sob_glbl::reg_sm_sei_cause sm_sei_cause;
};

} // namespace gaudi
#pragma pack(pop)
#endif /* ASIC_REG_STRUCTS_SOB_GLBL_H_ */
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
#include <stdint.h>

#pragma pack(push, 1)

namespace gaudi
{
namespace sob_objs {
/*
SM_SEC
Expand Down Expand Up @@ -127,5 +128,6 @@ struct block_sob_objs {
struct sob_objs::reg_sm_sec sm_sec[256];
};

} // namespace gaudi
#pragma pack(pop)
#endif /* ASIC_REG_STRUCTS_SOB_OBJS_H_ */
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,14 @@ namespace sync_mngr {
/*
SYNC_MNGR block
*/
namespace gaudi
{
struct block_sync_mngr {
struct block_sob_glbl sync_mngr_glbl;
uint32_t _pad8[1022];
struct block_sob_objs sync_mngr_objs;
};

} // namespace gaudi
#pragma pack(pop)
#endif /* ASIC_REG_STRUCTS_SYNC_MNGR_H_ */
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
#include <stdint.h>

#pragma pack(push, 1)

namespace gaudi
{
namespace sync_object {
/*
MESSAGE
Expand Down Expand Up @@ -47,5 +48,6 @@ struct block_sync_object {
struct sync_object::reg_addr addr;
};

} //namespace gaudi
#pragma pack(pop)
#endif /* ASIC_REG_STRUCTS_SYNC_OBJECT_H_ */
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
#include <stdint.h>

#pragma pack(push, 1)

namespace gaudi
{
namespace tpc_non_tensor_descriptor {
/*
KERNEL_BASE_ADDRESS_LOW
Expand Down Expand Up @@ -222,12 +223,16 @@ struct block_tpc_non_tensor_descriptor {
struct tpc_non_tensor_descriptor::reg_kernel_id kernel_id;
struct tpc_non_tensor_descriptor::reg_srf srf[32];
};
} // namespace gaudi
#include "gaudi_types.h"
namespace gaudi
{
const offsetVal block_tpc_non_tensor_descriptor_defaults[]
{
// offset // value
{ 0x30 , 0x60882 , 1 }, // kernel_config
};

} //namespace gaudi
#pragma pack(pop)
#endif /* ASIC_REG_STRUCTS_TPC_NON_TENSOR_DESCRIPTOR_H_ */
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
#include <stdint.h>

#pragma pack(push, 1)

namespace gaudi
{
namespace tpc {
/*
CFG_BASE_ADDRESS_HIGH
Expand Down Expand Up @@ -705,13 +706,15 @@ struct reg_irq_occoupy_cntr {
};
static_assert((sizeof(struct reg_irq_occoupy_cntr) == 4), "reg_irq_occoupy_cntr size is not 32-bit");
} /* tpc namespace */

} //namespace gaudi
#include "sync_object_regs.h"
#include "tpc_non_tensor_descriptor_regs.h"
#include "tpc_tensor_regs.h"
/*
TPC block
*/
namespace gaudi
{
struct block_tpc {
uint32_t _pad0[256];
struct block_tpc_tensor kernel_tensor_0;
Expand Down Expand Up @@ -807,7 +810,10 @@ struct block_tpc {
struct block_sync_object qm_sync_object;
struct block_tpc_non_tensor_descriptor qm;
};
} // namespace gaudi
#include "gaudi_types.h"
namespace gaudi
{
const offsetVal block_tpc_defaults[]
{
// offset // value
Expand Down Expand Up @@ -863,6 +869,6 @@ const offsetVal block_tpc_defaults[]
{ 0xd54 , 0x50000 , 1 }, // tensor_config
{ 0xdb8 , 0x60882 , 1 }, // kernel_config
};

} // namespace gaudi
#pragma pack(pop)
#endif /* ASIC_REG_STRUCTS_TPC_H_ */
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
#include <stdint.h>

#pragma pack(push, 1)

namespace gaudi
{
namespace tpc_tensor {
/*
BASE_ADDR_LOW
Expand Down Expand Up @@ -222,12 +223,16 @@ struct block_tpc_tensor {
struct tpc_tensor::reg_dim_4_size dim_4_size;
struct tpc_tensor::reg_dim_4_stride dim_4_stride;
};
} // namespace gaudi
#include "gaudi_types.h"
namespace gaudi
{
const offsetVal block_tpc_tensor_defaults[]
{
// offset // value
{ 0xc , 0x50000 , 1 }, // tensor_config
};

} // namespace gaudi
#pragma pack(pop)
#endif /* ASIC_REG_STRUCTS_TPC_TENSOR_H_ */
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

#define PACKET_HEADER_PACKET_ID_SHIFT 56
#define PACKET_HEADER_PACKET_ID_MASK 0x1F00000000000000ull
namespace gaudi
{

enum packet_id {
PACKET_WREG_32 = 0x1,
Expand Down Expand Up @@ -325,4 +327,5 @@ struct packet_cp_dma {
__u64 src_addr;
};

} // namespace gaudi
#endif /* GAUDI_PACKETS_H */
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

#pragma pack(push, 4)

namespace gaudi
{
struct GaudiTpcDesc
{
static const int c_max_tensor_dims = 5;
Expand All @@ -25,5 +27,6 @@ struct GaudiTpcDesc
block_tpc_non_tensor_descriptor m_desc;
};

} // namespace gaudi
#pragma pack(pop)
#endif // _GAUDI_TPC_DESC_H_
Loading

0 comments on commit 5fe9e24

Please sign in to comment.