-
Notifications
You must be signed in to change notification settings - Fork 29
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
Update Documentation #729
Update Documentation #729
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #729 +/- ##
=======================================
Coverage 88.00% 88.00%
=======================================
Files 86 86
Lines 20965 20965
=======================================
Hits 18450 18450
Misses 2515 2515 ☔ View full report in Codecov by Sentry. |
8fdd8fd
to
ccbbfdf
Compare
|
||
- Generates the code that calls the external function, ensuring proper casting to the primitive type. | ||
|
||
##### `globl(self, prim_type)` |
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.
Mention that this globl function is called for each unique prim_type.
By the way, this is better left for a different PR, but this means many externs don't work reliably if we mix precisions due to C name collisions. For example
@proc
def foo_sigmoid(xo : f32, yo : f64, xi : f32, yi : f64):
xo = sigmoid(xi)
yo = sigmoid(yi)
generates a C file that starts with
#include <math.h>
double sigmoid(double x) {
return 1 / (1 + exp(-x));
}
#include <math.h>
float sigmoid(float x) {
return 1 / (1 + exp(-x));
}
which is invalid (C does not support function overloading).
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.
Good catch! Yeah this is a bug, I filed it here: #737 737
docs/externs.md
Outdated
|
||
Externs can be used as expressions on the RHS of assignment and reduction statements. This allows you to incorporate external functions seamlessly into your Exo computations. | ||
|
||
Note that externs (and Exo procedures) do not allow aliasing in their arguments. This restriction is in place to prevent externs from having side effects on the input arguments. |
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.
Isn't this restriction because externs can have side effects on their arguments, and thus we need the aliasing restriction for the same reason extended C++ has restrict
?
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.
No, Exo procedures can modify their arguments (like put output in the out
buffer), but externs should not be able to modify their arguments. Externs return the expression instead.
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.
Also, externs actually allow aliasing.
@proc
def foo(xo : f32, yo : f64, xi : f32, yi : f64):
xo = select(xi, xi, xi, xi)
gets compiled into
float _select_float(float x,float v,float y,float z) {
if (x < v) return y;
else return z;
}
// foo(
// xo : f32 @DRAM,
// yo : f64 @DRAM,
// xi : f32 @DRAM,
// yi : f64 @DRAM
// )
void foo( void *ctxt, float* xo, const double* yo, const float* xi, const double* yi ) {
*xo = _select_float((float)*xi, (float)*xi, (float)*xi, (float)*xi);
}
@@ -0,0 +1,50 @@ | |||
# External Inspection Functions |
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.
Good new documentation, thanks.
Add documentation for design, imports, system overview, externs, inspection, instructions, memories, and object code. Also add the Cursor example in examples/cursors.