Skip to content

Commit

Permalink
Improve error messages when failing to fetch buffer
Browse files Browse the repository at this point in the history
  • Loading branch information
josevalim committed Aug 27, 2024
1 parent 1784b0d commit 9aae105
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions exla/c_src/exla/exla.cc
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ ERL_NIF_TERM get_buffer_device_pointer(ErlNifEnv* env, int argc, const ERL_NIF_T
return exla::nif::error(env, "Unable to get client.");
}
if (!exla::nif::get<exla::ExlaBuffer*>(env, argv[1], buffer)) {
return exla::nif::error(env, "Unable to get buffer.");
return exla::nif::error(env, "Unable to get buffer (it may belong to another node or have been garbage collected, consider using Nx.backend_transfer/1).");
}
if (!exla::nif::get_atom(env, argv[2], pointer_kind)) {
return exla::nif::error(env, "Unable to get device pointer kind.");
Expand Down Expand Up @@ -537,7 +537,7 @@ ERL_NIF_TERM read_device_mem(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[]
exla::int64 size;

if (!exla::nif::get<exla::ExlaBuffer*>(env, argv[0], buffer)) {
return exla::nif::error(env, "Unable to get buffer.");
return exla::nif::error(env, "Unable to get buffer (it may belong to another node or have been garbage collected, consider using Nx.backend_transfer/1).");
}
if (!exla::nif::get(env, argv[1], &size)) {
return exla::nif::error(env, "Unable to get size.");
Expand All @@ -556,7 +556,7 @@ ERL_NIF_TERM deallocate_device_mem(ErlNifEnv* env, int argc, const ERL_NIF_TERM
exla::ExlaBuffer** buffer;

if (!exla::nif::get<exla::ExlaBuffer*>(env, argv[0], buffer)) {
return exla::nif::error(env, "Unable to get buffer.");
return exla::nif::error(env, "Unable to get buffer (it may belong to another node or have been garbage collected, consider using Nx.backend_transfer/1).");
}

xla::Status dealloc_status = (*buffer)->Deallocate();
Expand Down Expand Up @@ -683,7 +683,7 @@ ERL_NIF_TERM copy_buffer_to_device(ErlNifEnv* env, int argc, const ERL_NIF_TERM
return exla::nif::error(env, "Unable to get client.");
}
if (!exla::nif::get<exla::ExlaBuffer*>(env, argv[1], buffer)) {
return exla::nif::error(env, "Unable to get buffer.");
return exla::nif::error(env, "Unable to get buffer (it may belong to another node or have been garbage collected, consider using Nx.backend_transfer/1).");
}
if (!exla::nif::get(env, argv[2], &device_id)) {
return exla::nif::error(env, "Unable to get device ID.");
Expand Down

0 comments on commit 9aae105

Please sign in to comment.