-
Notifications
You must be signed in to change notification settings - Fork 100
float16 support #788
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
float16 support #788
Conversation
d86ea08 to
c168c70
Compare
|
Thank you for picking this up, @igarnier! Some general early feedback: it would be good to avoid as much conditional compilation as possible. We currently don't depend on the OCaml version anywhere in the source code, so I'm not keen to introduce that kind of dependency for this feature. Is it viable to expose |
|
After tinkering a bit I think it's possible to remove most of the conditional compilation directives, with the function |
0ccecc8 to
8c3b6d6
Compare
|
The latest version eschews most of the conditional compilation. Here are the remaining bits:
I removed the tests for now. |
| { | ||
| switch (typeinfo) | ||
| { | ||
| #if FLOAT16_AVAILABLE |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another place where we use the preprocessor. Not sure how to avoid this one.
| #define STRINGIFY1(x) #x | ||
| #define STRINGIFY(x) STRINGIFY1(x) | ||
| #ifdef FLT16_MAX |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note: we reuse the same detection method as in ctypes_float16_availability . These should be kept in sync
|
|
||
| (* Adapted from the OCaml stdlib. This is for compatibility with OCaml 4.03 where | ||
| [String.split_on_char] is not available. *) | ||
| let split_on_char sep s = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copied some code from the stdlib, hope that's ok license-wise. Otherwise I'll hack something else.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's better not to copy the code. Perhaps something like the following would do:
let split_on_char c s = Str.(split (regexp (String.make 1 c))) sThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Works with Str.regexp_string instead of Str.regexp. Pushed a fix.
cf49809 to
e7e73ec
Compare
e7e73ec to
308425f
Compare
|
Just squashed history. Coming back to the code after a few weeks, I'm not super satisfied with the compile-time generation of the function |
Hi! This is a WIP PR adding float16 support to ctypes (see issue). Happy to have early feedback on the general direction. For now it uses a vendored copy of https://github.com/Leonidas-from-XIV/mucppo for preprocessing.
So far only (lightly) tested only on ocaml 5.2, on x86-64.
edit: also tested on 4.8
TODOs