Skip to content

Commit

Permalink
Fix for failing to build on GCC-14 (#17906)
Browse files Browse the repository at this point in the history
### Ticket
#17905 

### Problem description
Latest tt-metal can't build correctly on GCC-14

### What's changed

Base on
https://stackoverflow.com/questions/76867698/what-does-ignoring-attributes-on-template-argument-mean-in-this-context
the error is due to the attribute being lost when casting to function
pointer. The simply workaround is to write a class and pass that around.
This also has the benefit of not needing the `unique_ptr` to store 2
pointers.

Please help run CI and merge the patch.

### Checklist
- [x] [All post
commit](https://github.com/tenstorrent/tt-metal/actions/runs/13384193646)
CI passes
  • Loading branch information
marty1885 authored Feb 18, 2025
1 parent 899b181 commit 2551839
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions ttnn/cpp/ttnn/tensor/serialization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@ using MeshDevice = distributed::MeshDevice;

namespace {

struct FileCloser {
void operator()(FILE* file) const {
if (file) {
TT_ASSERT(fclose(file) == 0, "Failed to close file");
}
}
};

struct Padding {
enum class PadValue { Any, Zero, Infinity, NegativeInfinity };
struct PadDimension {
Expand Down Expand Up @@ -393,7 +401,7 @@ Tensor load_tensor_helper(const std::string& file_name, T device) {
if (not input_file) {
TT_THROW("Cannot open \"{}\"", file_name);
}
std::unique_ptr<FILE, decltype(&fclose)> file_guard(input_file, &fclose);
std::unique_ptr<FILE, FileCloser> file_guard(input_file);

std::size_t read_sentinel;
safe_fread(&read_sentinel, sizeof(read_sentinel), 1, input_file);
Expand Down Expand Up @@ -435,7 +443,7 @@ void dump_tensor(
if (not output_file) {
TT_THROW("Cannot open \"{}\"", file_name);
}
std::unique_ptr<FILE, decltype(&fclose)> file_guard(output_file, &fclose);
std::unique_ptr<FILE, FileCloser> file_guard(output_file);

safe_fwrite(&SENTINEL_VALUE, sizeof(SENTINEL_VALUE), 1, output_file);
safe_fwrite(&VERSION_ID, sizeof(VERSION_ID), 1, output_file);
Expand Down Expand Up @@ -495,7 +503,7 @@ void dump_memory_config(const std::string& file_name, const MemoryConfig& memory
if (not output_file) {
TT_THROW("Cannot open \"{}\"", file_name);
}
std::unique_ptr<FILE, decltype(&fclose)> file_guard(output_file, &fclose);
std::unique_ptr<FILE, FileCloser> file_guard(output_file);
dump_memory_config(output_file, memory_config);
}

Expand Down Expand Up @@ -533,7 +541,7 @@ MemoryConfig load_memory_config(const std::string& file_name) {
if (not input_file) {
TT_THROW("Cannot open \"{}\"", file_name);
}
std::unique_ptr<FILE, decltype(&fclose)> file_guard(input_file, &fclose);
std::unique_ptr<FILE, FileCloser> file_guard(input_file);
return load_memory_config(input_file);
}

Expand Down

0 comments on commit 2551839

Please sign in to comment.