Skip to content

ram: simplification of word slice creation#9690

Draft
braydenlouie wants to merge 8 commits intoThe-OpenROAD-Project:masterfrom
braydenlouie:simplification
Draft

ram: simplification of word slice creation#9690
braydenlouie wants to merge 8 commits intoThe-OpenROAD-Project:masterfrom
braydenlouie:simplification

Conversation

@braydenlouie
Copy link
Contributor

Changes in RAM creation order

  • Switched to building out each word slice out (row by row)
  • For simplifying all the indices used in the current implementation for readability

Signed-off-by: braydenl9988 <braydenl9988@gmail.com>
Signed-off-by: Brayden Louie <braydenl9988@gmail.com>
Signed-off-by: Brayden Louie <braydenl9988@gmail.com>
Signed-off-by: braydenlouie <braydenl9988@gmail.com>
Signed-off-by: braydenlouie <braydenl9988@gmail.com>
Signed-off-by: Brayden Louie <braydenl9988@gmail.com>
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request refactors the RAM generation logic to build word slices row by row, which improves code readability and simplifies indexing. The changes are generally good and achieve the stated goal. I've found one bug in the layout generation logic that could lead to incorrect behavior, and a couple of minor issues related to code clarity and consistency. Once these are addressed, the changes will be a solid improvement.

Note: Security Review did not run due to the size of the PR.

Comment on lines +243 to +249
for (int size = layouts_.size(); size <= tracks; ++size) {
if (orientation_ == odb::horizontal) {
layouts_.push_back(std::make_unique<Layout>(odb::vertical));
} else {
layouts_.push_back(std::make_unique<Layout>(odb::horizontal));
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

There is an off-by-one error in this loop condition. The loop for (int size = layouts_.size(); size <= tracks; ++size) will execute one more time than intended, creating an extra Layout object. For example, if layouts_ is empty and tracks is 10, this loop will run for size from 0 to 10 inclusive, creating 11 layouts instead of 10. The condition should be size < tracks to create the correct number of layouts.

Suggested change
for (int size = layouts_.size(); size <= tracks; ++size) {
if (orientation_ == odb::horizontal) {
layouts_.push_back(std::make_unique<Layout>(odb::vertical));
} else {
layouts_.push_back(std::make_unique<Layout>(odb::horizontal));
}
}
for (int size = layouts_.size(); size < tracks; ++size) {
if (orientation_ == odb::horizontal) {
layouts_.push_back(std::make_unique<Layout>(odb::vertical));
} else {
layouts_.push_back(std::make_unique<Layout>(odb::horizontal));
}
}

Comment on lines +122 to +123
void makeCellByte(int start_idx,
int row_idx,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The first parameter of makeCellByte is named start_idx here in the header, but it's named byte_idx in the implementation file (src/ram/src/ram.cpp). Using byte_idx is more descriptive as it represents the index of the byte within a word. For consistency and clarity, it would be best to use the same name in both the declaration and definition.

Suggested change
void makeCellByte(int start_idx,
int row_idx,
void makeCellByte(int byte_idx,
int row_idx,

Comment on lines +217 to +218
int start_idx
= byte * bits_per_byte; // eventually replace with bits per byte
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The comment // eventually replace with bits per byte is confusing because the variable bits_per_byte is already being used in the expression on the same line. This appears to be a stale comment from a previous stage of refactoring and should be removed to avoid confusion.

    int start_idx = byte * bits_per_byte;

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-tidy made some suggestions

int byte_number,
const std::string& prefix,
int read_ports,
void makeCellByte(int start_idx,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: function 'ram::RamGen::makeCellByte' has a definition with different parameter names [readability-inconsistent-declaration-parameter-name]

  void makeCellByte(int start_idx,
       ^
Additional context

src/ram/src/ram.cpp:139: the definition seen here

void RamGen::makeCellByte(const int byte_idx,
             ^

src/ram/include/ram/ram.h:121: differing parameters are named here: ('start_idx'), in definition: ('byte_idx')

  void makeCellByte(int start_idx,
       ^

const std::vector<std::vector<odb::dbBTerm*>>& data_output);

void makeWordSlice(
const int bytes_per_word,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: parameter 'bytes_per_word' is const-qualified in the function declaration; const-qualification of parameters only has an effect in function definitions [readability-avoid-const-params-in-decls]

Suggested change
const int bytes_per_word,
int bytes_per_word,


void makeWordSlice(
const int bytes_per_word,
const int row_idx,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: parameter 'row_idx' is const-qualified in the function declaration; const-qualification of parameters only has an effect in function definitions [readability-avoid-const-params-in-decls]

Suggested change
const int row_idx,
int row_idx,

void makeWordSlice(
const int bytes_per_word,
const int row_idx,
const int read_ports,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: parameter 'read_ports' is const-qualified in the function declaration; const-qualification of parameters only has an effect in function definitions [readability-avoid-const-params-in-decls]

Suggested change
const int read_ports,
int read_ports,

vector<vector<dbBTerm*>> byte_outputs(read_ports,
vector<dbBTerm*>(bits_per_byte));
for (int port = 0; port < read_ports; ++port) {
std::copy_n(data_output[port].begin() + start_idx,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: no header providing "std::copy_n" is directly included [misc-include-cleaner]

src/ram/src/ram.cpp:5:

- #include <array>
+ #include <algorithm>
+ #include <array>

Signed-off-by: Brayden Louie <braydenl9988@gmail.com>
@braydenlouie
Copy link
Contributor Author

@rovinski Here are the code simplification changes. At the moment the ok files are still not lining up, even when I tested it with the cmake build so still need to look into that. The differences are related to two of the pins and I believe some routing. I don't know if that's an issue with the changes I made or if they are a product of any changes to the other tools. The rest of the source files should be fixed barring linting and formatting changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant