Skip to content
Open
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
10 changes: 9 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -422,4 +422,12 @@ out/

datasets/

ext/
ext/

# macOS Ignores
.DS_Store

# CLion Ignores
.idea
cmake-build*

4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,9 @@ set_property(GLOBAL PROPERTY USE_FOLDERS ON)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

add_compile_definitions(FMT_CONSTEVAL=constexpr)

set(CMAKE_POLICY_VERSION_MINIMUM 3.10)

add_subdirectory(external)
add_subdirectory("src")
25 changes: 24 additions & 1 deletion include/rtm/bvh.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,19 @@

namespace rtm {

#if defined __aarch64__
inline uint64_t _pdep_u64_sw(uint64_t data, uint64_t mask)
{
uint64_t result = 0;
for (uint64_t bit = 1; mask; bit <<= 1) {
if (data & bit)
result |= mask & (-mask);
mask &= mask - 1;
}
return result;
}
#endif

union BVHPtr
{
struct
Expand Down Expand Up @@ -241,10 +254,16 @@ class BVH
rtm::vec3 centroid(build_object.aabb.centroid() - aabb.min);
centroid = centroid * scale * max;

build_object.morton_code =
build_object.morton_code =
#if defined __aarch64__
_pdep_u64_sw((uint32_t)centroid.x, 0b0001001001001001001001001001001001001001001001001001001001001001ull) |
_pdep_u64_sw((uint32_t)centroid.y, 0b0010010010010010010010010010010010010010010010010010010010010010ull) |
_pdep_u64_sw((uint32_t)centroid.z, 0b0100100100100100100100100100100100100100100100100100100100100100ull);
#else
_pdep_u64((uint32_t)centroid.x, 0b0001001001001001001001001001001001001001001001001001001001001001ull) |
_pdep_u64((uint32_t)centroid.y, 0b0010010010010010010010010010010010010010010010010010010010010010ull) |
_pdep_u64((uint32_t)centroid.z, 0b0100100100100100100100100100100100100100100100100100100100100100ull);
#endif
}
}

Expand Down Expand Up @@ -300,7 +319,11 @@ class BVH
for(uint i = start; i < end; ++i)
mask |= bld_objs[i].morton_code ^ bld_objs[start].morton_code;

#if defined __aarch64__
uint64_t prefix = mask ? __builtin_clzll(mask) : 64;
#else
uint64_t prefix = _lzcnt_u64(mask);
#endif
if(prefix == 64)
return (start + end) / 2;

Expand Down
14 changes: 13 additions & 1 deletion include/rtm/float.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@
#include <cmath>
#if defined BUILD_PLATFORM_WINDOWS
#include <intrin.h>
#elif defined __aarch64__
#include <arm_neon.h>
#elif defined BUILD_PLATFORM_LINUX
#include <immintrin.h>
#endif
#include <cfenv>
#endif

#ifdef BUILD_PLATFORM_LINUX
#if defined BUILD_PLATFORM_LINUX && !defined __aarch64__
// Declarations of intrinsics used that are defined but not declared in immintrin
extern __m128 _mm_cos_ps(__m128 __A);
extern __m128 _mm_sin_ps(__m128 __A);
Expand Down Expand Up @@ -51,6 +53,8 @@ inline float sqrt(float input)
float output;
asm volatile ("fsqrt.s %0, %1\n\t" : "=f" (output) : "f" (input));
return output;
#elif defined __aarch64__
return std::sqrt(input);
#else
return _mm_cvtss_f32(_mm_sqrt_ss(_mm_set_ps1(input)));
#endif
Expand All @@ -62,6 +66,8 @@ inline float rsqrt(float input)
float output;
asm volatile ("frsqrt.s %0, %1\n\t" : "=f" (output) : "f" (input));
return output;
#elif defined __aarch64__
return 1.0f / std::sqrt(input);
#else
return _mm_cvtss_f32(_mm_rsqrt_ss(_mm_set_ps1(input)));
#endif
Expand All @@ -73,6 +79,8 @@ inline float rcp(float input)
float output;
asm volatile ("frcp.s %0, %1\n\t" : "=f" (output) : "f" (input));
return output;
#elif defined __aarch64__
return 1.0f / input;
#else
return _mm_cvtss_f32(_mm_rcp_ss(_mm_set_ps1(input)));
#endif
Expand Down Expand Up @@ -124,6 +132,8 @@ inline float cos(float input)
{
#ifdef __riscv
return cos_32(input);
#elif defined __aarch64__
return std::cos(input);
#else
return _mm_cvtss_f32(_mm_cos_ps(_mm_set_ps1(input)));
#endif
Expand All @@ -133,6 +143,8 @@ inline float sin(float input)
{
#ifdef __riscv
return sin_32(input);
#elif defined __aarch64__
return std::sin(input);
#else
return _mm_cvtss_f32(_mm_sin_ps(_mm_set_ps1(input)));
#endif
Expand Down
6 changes: 6 additions & 0 deletions include/rtm/ftb.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,15 @@ inline bool compress(uint prim_idx, uint prim_cnt, const Mesh& mesh, FTB* block
}

uint max_pfx = 0;
#if defined __aarch64__
uint px = min((uint)(mask_x ? __builtin_clz(mask_x) : 32), max_pfx);
uint py = min((uint)(mask_y ? __builtin_clz(mask_y) : 32), max_pfx);
uint pz = min((uint)(mask_z ? __builtin_clz(mask_z) : 32), max_pfx);
#else
uint px = min(_lzcnt_u32(mask_x), max_pfx);
uint py = min(_lzcnt_u32(mask_y), max_pfx);
uint pz = min(_lzcnt_u32(mask_z), max_pfx);
#endif
uint nx = 32 - px;
uint ny = 32 - py;
uint nz = 32 - pz;
Expand Down
7 changes: 7 additions & 0 deletions include/rtm/macros.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,24 @@

#if defined __x86_64__ || defined _M_X64
#define __x86
#elif defined __aarch64__ || defined _M_ARM64
#define __aarch64
#endif

#if defined _WIN16 || defined WIN32 || defined _WIN32 || defined WIN64 || defined _WIN64 || defined __WIN32__ || defined __TOS_WIN__ || defined __WINDOWS__
#define BUILD_PLATFORM_WINDOWS
#elif defined __APPLE__
#define BUILD_PLATFORM_MACOS
#elif defined __linux__
#define BUILD_PLATFORM_LINUX
#endif

//To add breakpoints for debugging at runtime
#if defined BUILD_PLATFORM_WINDOWS
#define add_breakpoint() __debugbreak()
#elif defined BUILD_PLATFORM_MACOS
#include <signal.h>
#define add_breakpoint() raise(SIGTRAP)
#elif defined BUILD_PLATFORM_LINUX
#include <signal.h>
#define add_breakpoint() raise(SIGINT)
Expand Down
2 changes: 1 addition & 1 deletion include/rtm/mesh.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ class Mesh
vertex_indices.emplace_back(0);
tex_coord_indices.emplace_back(~0x0u);
normal_indices.emplace_back(~0x0u);
material_indices.emplace_back(material_names.size() - 1u);
material_indices.emplace_back(material_names.empty() ? 0u : (uint)(material_names.size() - 1u));
read_face(line + data_start_index, vertex_indices.back(), tex_coord_indices.back(), normal_indices.back());
break;

Expand Down
6 changes: 6 additions & 0 deletions include/rtm/qtb.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,15 @@ inline bool compress(const uint* prim_ids, uint num_tris, const Mesh& mesh, QTB&
}

uint max_pfx = 24;
#if defined __aarch64__
uint px = min((uint)((mask_x << 8) ? __builtin_clz(mask_x << 8) : 32), max_pfx);
uint py = min((uint)((mask_y << 8) ? __builtin_clz(mask_y << 8) : 32), max_pfx);
uint pz = min((uint)((mask_z << 8) ? __builtin_clz(mask_z << 8) : 32), max_pfx);
#else
uint px = min(_lzcnt_u32(mask_x << 8), max_pfx);
uint py = min(_lzcnt_u32(mask_y << 8), max_pfx);
uint pz = min(_lzcnt_u32(mask_z << 8), max_pfx);
#endif
uint nx = 24 - px;
uint ny = 24 - py;
uint nz = 24 - pz;
Expand Down
5 changes: 3 additions & 2 deletions include/rtm/texture.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,9 @@ class Texture2D

rtm::vec2 get_fract_uv(const rtm::vec2& uv) const
{
rtm::vec2 fuv = uv * rtm::vec2(width, height);
return (fuv - rtm::vec2((int32_t)fuv[0], (int32_t)fuv[1]));
rtm::vec2 wrapped_uv(uv[0] - floorf(uv[0]), uv[1] - floorf(uv[1]));
rtm::vec2 fuv = wrapped_uv * rtm::vec2(width, height);
return rtm::vec2(fuv[0] - floorf(fuv[0]), fuv[1] - floorf(fuv[1]));
}

Texel* get_texel_addr(const rtm::uvec2& iuv) const
Expand Down
10 changes: 9 additions & 1 deletion src/arches-v2/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ add_compile_definitions(UNICODE _UNICODE)

set(PROJECT_NAME "arches-v2")

if(LINUX)
if(LINUX AND NOT APPLE)
# enable intrinsics like _lzcnt_u64
add_compile_options(-march=native)
endif()
Expand Down Expand Up @@ -61,10 +61,18 @@ set_target_properties(${PROJECT_NAME} PROPERTIES OUTPUT_NAME ${PROJECT_NAME})
if(WINDOWS)
target_link_directories(${PROJECT_NAME} PUBLIC ${PROJECT_SOURCE_DIR}/libraries/tbb)
target_link_libraries(${PROJECT_NAME} PRIVATE tbb12.lib)
elseif(APPLE)
execute_process(COMMAND brew --prefix tbb OUTPUT_VARIABLE TBB_BREW_PREFIX OUTPUT_STRIP_TRAILING_WHITESPACE)
target_include_directories(${PROJECT_NAME} PUBLIC ${TBB_BREW_PREFIX}/include)
target_link_directories(${PROJECT_NAME} PUBLIC ${TBB_BREW_PREFIX}/lib)
target_link_libraries(${PROJECT_NAME} PRIVATE tbb)
elseif(LINUX)
target_link_libraries(${PROJECT_NAME} PRIVATE tbb)
endif()
target_link_libraries(${PROJECT_NAME} PRIVATE Ramulator)
target_compile_definitions(${PROJECT_NAME} PRIVATE
ARCHES_SOURCE_DIR="${CMAKE_SOURCE_DIR}/"
ARCHES_BINARY_DIR="${CMAKE_CURRENT_BINARY_DIR}/")
#set_target_properties(${PROJECT_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CMAKE_CURRENT_BINARY_DIR})
#set_target_properties(${PROJECT_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CMAKE_CURRENT_BINARY_DIR})
set_target_properties(${PROJECT_NAME} PROPERTIES FOLDER ${PROJECT_NAME})
Expand Down
19 changes: 18 additions & 1 deletion src/arches-v2/isa/registers.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "registers.hpp"

#include <cfenv>

namespace Arches { namespace ISA { namespace RISCV {

Expand All @@ -19,6 +19,22 @@ FloatingPointRegisterFile::FloatingPointRegisterFile()
{
fcsr.data = 0u;
//Make rounding mode match simulator rounding mode
#if defined BUILD_ARCH_aarch64
switch (fegetround()) {
case FE_TONEAREST:
fcsr.frm = 0b000;
break;
case FE_DOWNWARD:
fcsr.frm = 0b010;
break;
case FE_UPWARD:
fcsr.frm = 0b011;
break;
case FE_TOWARDZERO:
fcsr.frm = 0b001;
break;
}
#else
switch ((_mm_getcsr() >> 13) & 0b11) {
case 0b00: //nearest (even)
fcsr.frm = 0b000;
Expand All @@ -33,6 +49,7 @@ FloatingPointRegisterFile::FloatingPointRegisterFile()
fcsr.frm = 0b001;
break;
}
#endif

for (int i = 0; i < sizeof(valid); ++i) valid[i] = true;
}
Expand Down
14 changes: 14 additions & 0 deletions src/arches-v2/isa/riscv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

#if defined BUILD_PLATFORM_WINDOWS
#include <intrin.h>
#elif defined __aarch64__
#include <cmath>
#elif defined BUILD_PLATFORM_LINUX
#include <immintrin.h>
#endif
Expand Down Expand Up @@ -695,15 +697,27 @@ InstructionInfo const isa_OP_FP[32] = //r.funct5
InstructionInfo(0b010'10, IMPL_NONE),
InstructionInfo(0b010'11, "fsqrt.s", InstrType::FSQRT, Encoding::R, RegFile::FLOAT, EXEC_DECL
{
#if defined __aarch64__
unit->float_regs->registers[instr.r.rd].f32 = std::sqrt(unit->float_regs->registers[instr.r.rs1].f32);
#else
unit->float_regs->registers[instr.r.rd].f32 = _mm_cvtss_f32(_mm_sqrt_ss(_mm_set_ps1(unit->float_regs->registers[instr.r.rs1].f32)));
#endif
}),
InstructionInfo(0b011'00, "fisqrt.s", InstrType::FSQRT, Encoding::R, RegFile::FLOAT, EXEC_DECL
{
#if defined __aarch64__
unit->float_regs->registers[instr.r.rd].f32 = 1.0f / std::sqrt(unit->float_regs->registers[instr.r.rs1].f32);
#else
unit->float_regs->registers[instr.r.rd].f32 = _mm_cvtss_f32(_mm_rsqrt_ps(_mm_set_ps1(unit->float_regs->registers[instr.r.rs1].f32)));
#endif
}),
InstructionInfo(0b011'01, "frcp.s", InstrType::FRCP, Encoding::R, RegFile::FLOAT, EXEC_DECL
{
#if defined __aarch64__
unit->float_regs->registers[instr.r.rd].f32 = 1.0f / unit->float_regs->registers[instr.r.rs1].f32;
#else
unit->float_regs->registers[instr.r.rd].f32 = _mm_cvtss_f32(_mm_rcp_ss(_mm_set_ps1(unit->float_regs->registers[instr.r.rs1].f32)));
#endif
}),
InstructionInfo(0b011'10, IMPL_NONE),
InstructionInfo(0b011'11, IMPL_NONE),
Expand Down
11 changes: 6 additions & 5 deletions src/arches-v2/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,14 +219,15 @@ static TRaXKernelArgs initilize_buffers(Units::UnitMainMemoryBase** drams, const
for(uint32_t i = 0; i < mesh.materials.size(); ++i)
mesh.materials[i].albedo_texture.texels = nullptr; // to not free device memory textures

size_t temp = TRAX_KERNEL_ARGS_ADDRESS;
paddr_t temp = TRAX_KERNEL_ARGS_ADDRESS;
write_array(drams, xbar, 256, (uint8_t*)&args, sizeof(TRaXKernelArgs), temp);
return args;
}

static void run_sim_trax(SimulationConfig& sim_config)
{
std::string project_folder_path = get_project_folder_path();
std::string project_binary_path = get_project_binary_path();

#if 0 //RTX 4090 ish
//Compute
Expand All @@ -244,7 +245,7 @@ static void run_sim_trax(SimulationConfig& sim_config)

//DRAM
UnitDRAM::Configuration dram_config;
dram_config.config_path = project_folder_path + "build\\src\\arches-v2\\config-files\\gddr6x_21000_config.yaml";
dram_config.config_path = project_binary_path + "config-files/gddr6x_21000_config.yaml";
dram_config.size = 1ull << 30; //1GB per partition
dram_config.clock_ratio = dram_clock / core_clock;
dram_config.latency = 254;
Expand Down Expand Up @@ -305,7 +306,7 @@ static void run_sim_trax(SimulationConfig& sim_config)

//DRAM
UnitDRAM::Configuration dram_config;
dram_config.config_path = project_folder_path + "build\\src\\arches-v2\\config-files\\gddr6_14000_config.yaml";
dram_config.config_path = project_binary_path + "config-files/gddr6_14000_config.yaml";
dram_config.size = 1ull << 30; //1GB per partition
dram_config.clock_ratio = dram_clock / core_clock;
dram_config.latency = 254;
Expand Down Expand Up @@ -375,7 +376,7 @@ static void run_sim_trax(SimulationConfig& sim_config)

//DRAM
UnitDRAM::Configuration dram_config;
dram_config.config_path = project_folder_path + "build/src/arches-v2/config-files/gddr6_14000_config.yaml";
dram_config.config_path = project_binary_path + "config-files/gddr6_14000_config.yaml";
dram_config.size = 1ull << 30; //1GB
dram_config.clock_ratio = dram_clock / core_clock;
dram_config.latency = 92;
Expand Down Expand Up @@ -433,7 +434,7 @@ static void run_sim_trax(SimulationConfig& sim_config)

//DRAM
UnitDRAM::Configuration dram_config;
dram_config.config_path = project_folder_path + "build\\src\\arches-v2\\config-files\\gddr6_pch_config.yaml";
dram_config.config_path = project_binary_path + "config-files/gddr6_pch_config.yaml";
dram_config.size = 1ull << 30; //1GB
dram_config.clock_ratio = dram_clock / core_clock;
dram_config.latency = 1;
Expand Down
13 changes: 9 additions & 4 deletions src/arches-v2/shared-utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
#if defined BUILD_PLATFORM_WINDOWS
#include <Windows.h>
#define MAX_FILENAME_LENGTH MAX_PATH
#elif defined BUILD_PLATFORM_MACOS
#include <climits>
#define MAX_FILENAME_LENGTH PATH_MAX
#elif defined BUILD_PLATFORM_LINUX
#include <linux/limits.h>
#define MAX_FILENAME_LENGTH FILENAME_MAX
Expand All @@ -33,10 +36,12 @@ void set_full_exe_name(const char *name) {

std::string get_project_folder_path()
{
// CHAR path[MAX_PATH];
// GetModuleFileNameA(NULL, path, MAX_PATH);
std::string executable_path(full_exe_name);
return executable_path.substr(0, executable_path.rfind("build"));
return ARCHES_SOURCE_DIR;
}

std::string get_project_binary_path()
{
return ARCHES_BINARY_DIR;
}

template <typename T>
Expand Down
Loading