Skip to content
Merged
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
1 change: 1 addition & 0 deletions plugins/tenstorrent/tt_buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class TTBuffer : public nxs::rt::Buffer {

nxs_ulong size() const { return getSizeBytes(); }
nxs_uint *getAddress() { return &address; }
ttmd::MeshBuffer *getMeshBuffer() { return buffer.get(); }

template <typename T>
nxs_status tilizeAndCopyToDevice(T *data_ptr, bool blocking);
Expand Down
9 changes: 9 additions & 0 deletions plugins/tenstorrent/tt_command.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <rt_buffer.h>

#include <tt-metalium/bfloat16.hpp>
#include <tt-metalium/tensor_accessor_args.hpp>

#include <algorithm>

Expand Down Expand Up @@ -50,6 +51,14 @@ nxs_status TTCommand::runCommand(TTDevice *device, nxs_int stream, ttmd::MeshWor
}
}

for (TTBuffer *buffer: buffers) {
if (buffer) {
NXSLOG_INFO("TensorAccessor Buffer: {}", (intptr_t)buffer);
ttm::TensorAccessorArgs(buffer->getMeshBuffer()).append_to(ctas);
}
}

NXSLOG_INFO("Add semaphores: {}", ctas.size());
ctas.push_back(ttm::CreateSemaphore(program, cores, 0));
ctas.push_back(ttm::CreateSemaphore(program, cores, 0));

Expand Down
8 changes: 8 additions & 0 deletions plugins/tenstorrent/tt_command.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@
#include <rt_command.h>
#include <tt_library.h>
#include <tt_device.h>
#include <tt_buffer.h>

class TTRuntime;

class TTCommand : public nxs::rt::Command<TTKernel *, nxs_int, nxs_int> {
TTRuntime *rt;
std::array<TTBuffer*, NXS_KERNEL_MAX_ARGS> buffers;

public:
TTCommand(TTRuntime *rt = nullptr, TTKernel *kernel = nullptr,
Expand All @@ -23,6 +25,12 @@ class TTCommand : public nxs::rt::Command<TTKernel *, nxs_int, nxs_int> {

~TTCommand() = default;

void setBufferArgument(nxs_int argument_index, TTBuffer *buffer) {
if (argument_index < 0 || argument_index >= NXS_KERNEL_MAX_ARGS) return;
NXSLOG_INFO("Set buffer argument: {} -> {}", argument_index, (intptr_t)buffer);
buffers[argument_index] = buffer;
}

nxs_status runCommand(nxs_int stream) override { assert(0); return NXS_Success; }
nxs_status runCommand(TTDevice *device, nxs_int stream, ttmd::MeshWorkload &workload,
ttmd::MeshCoordinateRange &dev_range,
Expand Down
1 change: 1 addition & 0 deletions plugins/tenstorrent/tt_runtime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,7 @@ extern "C" nxs_status NXS_API_CALL nxsSetCommandArgument(nxs_int command_id,
auto buffer = rt->get<TTBuffer>(buffer_id);
if (!buffer) return NXS_InvalidBuffer;

command->setBufferArgument(argument_index, buffer);
return command->setScalar(argument_index, buffer->getAddress(), "Buffer", argument_settings);
}

Expand Down
8 changes: 4 additions & 4 deletions python/src/system.cc
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ static DevPtr getPointer(PyObject *obj) {
result.device_id = 0;
}
Py_DECREF(device_m);
if (result.runtime_name == "knexus") {
if (result.runtime_name == "nexus") {
return result;
}
}
Expand Down Expand Up @@ -159,9 +159,9 @@ static Buffer make_buffer(py::object tensor, Device device = Device(),
}

auto data_ptr = getPointer(tensor.ptr());
if (data_ptr.runtime_name == "knexus") {
// call torch.knexus.get_knexus_buffer(obj)
auto get_knexus_buffer = import_from("torch.knexus", "get_knexus_buffer");
if (data_ptr.runtime_name == "nexus") {
// call torch.nexus.get_nexus_buffer(obj)
auto get_knexus_buffer = import_from("torch.nexus", "get_nexus_buffer");
PyObject *get_knexus_buffer_ret = PyObject_CallFunctionObjArgs(get_knexus_buffer, tensor.ptr(), NULL);
Py_DECREF(get_knexus_buffer);
if (!get_knexus_buffer_ret) {
Expand Down
Loading