Skip to content

Commit

Permalink
#13499: Split runtime_args_data into header and implementation (#13915)
Browse files Browse the repository at this point in the history
  • Loading branch information
blozano-tt authored Oct 20, 2024
1 parent 1f6829b commit 571ba98
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 30 deletions.
1 change: 1 addition & 0 deletions tt_metal/impl/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ set(IMPL_SRC
${CMAKE_CURRENT_SOURCE_DIR}/buffers/circular_buffer.cpp
${CMAKE_CURRENT_SOURCE_DIR}/buffers/semaphore.cpp
${CMAKE_CURRENT_SOURCE_DIR}/kernels/kernel.cpp
${CMAKE_CURRENT_SOURCE_DIR}/kernels/runtime_args_data.cpp
${CMAKE_CURRENT_SOURCE_DIR}/allocator/algorithms/free_list.cpp
${CMAKE_CURRENT_SOURCE_DIR}/allocator/allocator.cpp
${CMAKE_CURRENT_SOURCE_DIR}/allocator/basic_allocator.cpp
Expand Down
44 changes: 44 additions & 0 deletions tt_metal/impl/kernels/runtime_args_data.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// SPDX-FileCopyrightText: © 2024 Tenstorrent Inc.
//
// SPDX-License-Identifier: Apache-2.0

#include "tt_metal/impl/kernels/runtime_args_data.hpp" // Public API Header

#include "tt_metal/common/assert.hpp"

namespace tt::tt_metal {

std::uint32_t & RuntimeArgsData::operator[](std::size_t index) {
TT_ASSERT(index < rt_args_count, "Index specified is larger than runtime args size");
return this->rt_args_data[index];
}

const std::uint32_t & RuntimeArgsData::operator[](std::size_t index) const {
TT_ASSERT(index < rt_args_count, "Index specified is larger than runtime args size");
return this->rt_args_data[index];
}

std::uint32_t & RuntimeArgsData::at(std::size_t index) {
TT_FATAL(index < rt_args_count, "Index specified is larger than runtime args size");
return this->rt_args_data[index];
}

const std::uint32_t & RuntimeArgsData::at(std::size_t index) const {
TT_FATAL(index < rt_args_count, "Index specified is larger than runtime args size");
return this->rt_args_data[index];
}

std::uint32_t * RuntimeArgsData::data() noexcept {
return rt_args_data;
}

const std::uint32_t * RuntimeArgsData::data() const noexcept {
return rt_args_data;
}

std::size_t RuntimeArgsData::size() const noexcept {
return rt_args_count;
}

}

49 changes: 19 additions & 30 deletions tt_metal/impl/kernels/runtime_args_data.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,42 +4,31 @@

#pragma once

#include "tt_metal/common/assert.hpp"
#include <cstddef>
#include <cstdint>

namespace tt::tt_metal {
// RuntimeArgsData provides an indirection to the runtime args
// Prior to generating the cq cmds for the device, this points into a vector within the kernel
// After generation, this points into the cq cmds so that runtime args API calls
// update the data directly in the command
struct RuntimeArgsData {
uint32_t * rt_args_data;
size_t rt_args_count;

inline uint32_t & operator[](size_t index) {
TT_ASSERT(index < rt_args_count, "Index specified is larger than runtime args size");
return this->rt_args_data[index];
}
inline const uint32_t& operator[](size_t index) const {
TT_ASSERT(index < rt_args_count, "Index specified is larger than runtime args size");
return this->rt_args_data[index];
}
inline uint32_t & at(size_t index) {
TT_FATAL(index < rt_args_count, "Index specified is larger than runtime args size");
return this->rt_args_data[index];
}
inline const uint32_t& at(size_t index) const {
TT_FATAL(index < rt_args_count, "Index specified is larger than runtime args size");
return this->rt_args_data[index];
}
inline uint32_t * data() noexcept {
return rt_args_data;
}
inline const uint32_t * data() const noexcept {
return rt_args_data;
}
inline size_t size() const noexcept{
return rt_args_count;
}
};
std::uint32_t * rt_args_data;
std::size_t rt_args_count;

std::uint32_t & operator[](std::size_t index);

const std::uint32_t& operator[](std::size_t index) const;

std::uint32_t & at(std::size_t index);

const std::uint32_t& at(std::size_t index) const;

std::uint32_t * data() noexcept;

const std::uint32_t * data() const noexcept;

std::size_t size() const noexcept;
};

}

0 comments on commit 571ba98

Please sign in to comment.