Skip to content

Commit

Permalink
Add Buffer::is_current_on()
Browse files Browse the repository at this point in the history
This allows querying whether the buffer is current on the given device.
Also add a note that Buffer::current_device() cannot reflect the fact
that all devices may have the current data (e.g., after a pushout).

Also add static ttg::device::Device::host() that returns the host device.


Signed-off-by: Joseph Schuchart <[email protected]>
  • Loading branch information
devreal committed Nov 12, 2024
1 parent 3b68842 commit a125f3b
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
4 changes: 4 additions & 0 deletions ttg/ttg/device/device.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ namespace ttg::device {
bool is_invalid() const {
return (m_space == ttg::ExecutionSpace::Invalid);
}

static Device host() {
return {};
}
};
} // namespace ttg::device

Expand Down
6 changes: 6 additions & 0 deletions ttg/ttg/madness/buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,12 @@ struct Buffer : private Allocator {
/* no-op */
}


bool is_current_on(ttg::device::Device dev) const {
assert(is_valid());
return true;
}

/* Get the owner device ID, i.e., the last updated
* device buffer. */
ttg::device::Device get_owner_device() const {
Expand Down
17 changes: 16 additions & 1 deletion ttg/ttg/parsec/buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,23 @@ struct Buffer : public detail::ttg_parsec_data_wrapper_t
m_data->owner_device = parsec_id;
}

bool is_current_on(ttg::device::Device dev) const {
if (empty()) return true; // empty is current everywhere
int parsec_id = detail::ttg_device_to_parsec_device(dev);
uint32_t max_version = 0;
for (int i = 0; i < parsec_nb_devices; ++i) {
if (nullptr == m_data->device_copies[i]) continue;
max_version = std::max(max_version, m_data->device_copies[i]->version);
}
return (m_data->device_copies[parsec_id] &&
m_data->device_copies[parsec_id]->version == max_version);
}

/* Get the owner device ID, i.e., the last updated
* device buffer. */
* device buffer.
* NOTE: there may be more than one device with the current
* data so the result may not always be what is expected.
* Use is_current_on() to check for a specific device. */
ttg::device::Device get_owner_device() const {
assert(is_valid());
if (empty()) return ttg::device::current_device(); // empty is always valid
Expand Down

0 comments on commit a125f3b

Please sign in to comment.