ml-explore / mlx-c Goto Github PK
View Code? Open in Web Editor NEWC API for MLX
Home Page: https://ml-explore.github.io/mlx-c
License: MIT License
C API for MLX
Home Page: https://ml-explore.github.io/mlx-c
License: MIT License
I noticed that these are missing from ops.h:
/**
* Extract the number of elements along some axes as a scalar array. Used to
* allow shape dependent shapeless compilation (pun intended).
*/
array number_of_elements(
const array& a,
std::vector<int> axes,
bool inverted,
Dtype dtype = int32,
StreamOrDevice s = {});
/** Bitwise and. */
array bitwise_and(const array& a, const array& b, StreamOrDevice s = {});
array operator&(const array& a, const array& b);
/** Bitwise inclusive or. */
array bitwise_or(const array& a, const array& b, StreamOrDevice s = {});
array operator|(const array& a, const array& b);
/** Bitwise exclusive or. */
array bitwise_xor(const array& a, const array& b, StreamOrDevice s = {});
array operator^(const array& a, const array& b);
/** Shift bits to the left. */
array left_shift(const array& a, const array& b, StreamOrDevice s = {});
array operator<<(const array& a, const array& b);
/** Shift bits to the right. */
array right_shift(const array& a, const array& b, StreamOrDevice s = {});
array operator>>(const array& a, const array& b);
I am not sure about number_of_elements()
but the bitwise and arithmetic shift functions should be added.
MLXArrayIndexingTests.testSliceWithBroadcast()
& UpsampleTests.testNearest()
are both failing. Good news is that all other tests pass.
Both are failing with "vector[] index out of bounds"
at different locations in collapse_contiguous_dims
.
testSliceWithBroadcast()
utils.h:76
out_strides[j].push_back(st[to_collapse[i - 1]]);
testNearest()
utils.h:51
if (st[i] * shape[i] != st[i - 1]) {
Here is reproduce code snippet:
#include <stdio.h>
#include <stdlib.h>
#include "mlx/c/mlx.h"
mlx_array inc_fun(mlx_array in) {
mlx_array y = mlx_array_from_float(1.0);
mlx_array res = mlx_add(in, y, MLX_GPU_STREAM);
mlx_free(y);
return res;
}
int main() {
mlx_closure cls = mlx_closure_new_unary(inc_fun);
// jvp
{
mlx_enable_compile();
printf("start compile:\n");
mlx_compile(cls, true);
printf("end compile:\n");
}
return 0;
}
result:
libc++abi: terminating due to uncaught exception of type std::invalid_argument: [compile] Cannot compile a non-addressable function.
this is where it throws exception
Because the rust runtime cannot capture c++ exceptions, we are trying to perform checks before crossing the FFI boundary. One thing that the c++ code checks in the sort
function is whether the device is set to GPU and the array size on the requested axis is larger than 2M. However, the current c wrapper doesn't provide a way to check the device type of a mlx_stream
. Would it be possible to add this?
Specifically:
bool cache_enabled(void);
void set_cache_enabled(bool enabled);
This is useful in controlling memory use in resource constrained environments.
I'm working on some bindings that make use of mlx-c
but I'm finding that if I run tests that create arrays right after having previously ran tests i'm getting an error:
libc++abi: terminating due to uncaught exception of type std::__1::system_error: condition_variable wait failed: Invalid argument
My guess is some kind of threadpool issue, is there a way to specify limits? Could this be an error in mlx-c
?
While going back and catching older mlx functions that got missed while building, I ran across
array tensordot(
const array& a,
const array& b,
const std::pair<std::vector<int>, std::vector<int>>& dims,
StreamOrDevice s /* = {} */
The unusual signature isn't in mlx-c (the normal one with a single int is present).
What is the planned release cadence for mlx-c? Will mlx-c follow the weekly release cadence of mlx?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.