@@ -13,6 +13,10 @@ ERL_NIF_TERM error(ErlNifEnv* env, const char* error) {
1313 return enif_make_tuple2 (env, enif_make_atom (env, " error" ), enif_make_string (env, error, ERL_NIF_LATIN1));
1414}
1515
16+ ERL_NIF_TERM ok (ErlNifEnv* env) {
17+ return enif_make_atom (env, " ok" );
18+ }
19+
1620ERL_NIF_TERM ok (ErlNifEnv* env, ERL_NIF_TERM term) {
1721 return enif_make_tuple2 (env, enif_make_atom (env, " ok" ), term);
1822}
@@ -233,7 +237,8 @@ DECLARE_NIF(list_devices) {
233237 auto ref_term = make<iree_hal_device_t *>(env, device->ref );
234238 auto driver_name_term = enif_make_string (env, device->driver_name .c_str (), ERL_NIF_LATIN1);
235239 auto uri_term = enif_make_string (env, device->uri .c_str (), ERL_NIF_LATIN1);
236- auto tuple = enif_make_tuple3 (env, ref_term, driver_name_term, uri_term);
240+ auto id_term = enif_make_uint64 (env, device->id );
241+ auto tuple = enif_make_tuple4 (env, ref_term, driver_name_term, uri_term, id_term);
237242 device_terms.push_back (tuple);
238243 }
239244
@@ -315,13 +320,13 @@ iree_hal_element_type_t nx_type_to_iree_type(std::string type) {
315320 return type_enum::IREE_HAL_ELEMENT_TYPE_INT_32;
316321 } else if (type == " i64" ) {
317322 return type_enum::IREE_HAL_ELEMENT_TYPE_INT_64;
318- } else if (type == " u8 " ) {
323+ } else if (type == " ui8 " ) {
319324 return type_enum::IREE_HAL_ELEMENT_TYPE_UINT_8;
320- } else if (type == " u16 " ) {
325+ } else if (type == " ui16 " ) {
321326 return type_enum::IREE_HAL_ELEMENT_TYPE_UINT_16;
322- } else if (type == " u32 " ) {
327+ } else if (type == " ui32 " ) {
323328 return type_enum::IREE_HAL_ELEMENT_TYPE_UINT_32;
324- } else if (type == " u64 " ) {
329+ } else if (type == " ui64 " ) {
325330 return type_enum::IREE_HAL_ELEMENT_TYPE_UINT_64;
326331 } else if (type == " bf16" ) {
327332 return type_enum::IREE_HAL_ELEMENT_TYPE_BFLOAT_16;
@@ -355,14 +360,10 @@ DECLARE_NIF(read_buffer_nif) {
355360 return error (env, " invalid num_bytes" );
356361 }
357362
358- std::cout << " num_bytes input: " << num_bytes << std::endl;
359-
360363 if (num_bytes == -1 ) {
361364 num_bytes = (*input)->size ;
362365 }
363366
364- std::cout << " num_bytes actual: " << num_bytes << std::endl;
365-
366367 ErlNifBinary binary;
367368
368369 if (!enif_alloc_binary (num_bytes, &binary)) {
@@ -418,6 +419,22 @@ DECLARE_NIF(allocate_buffer) {
418419 return ok (env, make<iree::runtime::IREETensor*>(env, input));
419420}
420421
422+ DECLARE_NIF (deallocate_buffer) {
423+ if (argc != 1 ) {
424+ return error (env, " invalid number of arguments" );
425+ }
426+
427+ iree::runtime::IREETensor** input;
428+
429+ if (!get<iree::runtime::IREETensor*>(env, argv[0 ], input)) {
430+ return error (env, " invalid input" );
431+ }
432+
433+ (*input)->deallocate ();
434+
435+ return ok (env);
436+ }
437+
421438DECLARE_NIF (serialize_tensor) {
422439 if (argc != 1 ) {
423440 return error (env, " invalid number of arguments" );
@@ -510,6 +527,7 @@ static ErlNifFunc funcs[] = {
510527 {" list_devices" , 1 , list_devices},
511528 {" list_devices" , 2 , list_devices},
512529 {" list_drivers" , 1 , list_drivers},
530+ {" deallocate_buffer" , 1 , deallocate_buffer},
513531 {" allocate_buffer" , 4 , allocate_buffer},
514532 {" serialize_tensor" , 1 , serialize_tensor},
515533 {" deserialize_tensor" , 1 , deserialize_tensor},
0 commit comments