Skip to content

Instantly share code, notes, and snippets.

@flaub
Created June 4, 2020 20:48
Show Gist options
  • Save flaub/c1e11c505812f6e743b88000206636fb to your computer and use it in GitHub Desktop.
Save flaub/c1e11c505812f6e743b88000206636fb to your computer and use it in GitHub Desktop.
EDSL language binding C API
#include "plaidml/edsl/ffi.h"
void ffi_example() {
int64_t dims[4] = {1, 2, 3, 4};
plaidml_error err;
plaidml_edsl_init(&err);
if (err.code) {
// This is an example of how to check for errors and how to report them.
const char* str = plaidml_string_ptr(err.msg);
printf("Error: %s\n", str);
plaidml_string_free(err.msg);
return;
}
plaidml_logical_shape* shape = plaidml_logical_shape_alloc(&err, PLAIDML_DATA_FLOAT32, 4, dims);
plaidml_expr* a_expr = plaidml_expr_placeholder(&err, shape, /*buffer=*/NULL, /*name=*/"A");
plaidml_expr* b_expr = plaidml_expr_placeholder(&err, shape, /*buffer=*/NULL, /*name=*/"B");
plaidml_expr* operands[] = {a_expr, b_expr};
plaidml_expr* c_expr = plaidml_expr_call(&err, "add", /*nargs=*/2, /*args=*/operands);
plaidml_expr* outputs[] = {c_expr};
plaidml_program_args* args;
plaidml_program* program = plaidml_compile(&err,
/*name=*/"example",
/*target=*/"llvm_cpu",
/*noutputs=*/1, outputs,
/*nupdates=*/0,
/*src_updates=*/NULL,
/*dst_updates=*/NULL,
/*floatx=*/PLAIDML_DATA_FLOAT32,
/*intx=*/PLAIDML_DATA_INT32,
/*debug=*/0,
/*args=*/&args);
// From here you can use the `exec` API to execute a program.
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment