Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
cmucl-copy
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Richard M Kreuter
cmucl-copy
Commits
06121692
Commit
06121692
authored
22 years ago
by
toy
Browse files
Options
Downloads
Patches
Plain Diff
Correct typos in the dotprod example. Adjust text a bit too.
parent
05068cde
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
docs/cmu-user/aliens.tex
+19
-14
19 additions, 14 deletions
docs/cmu-user/aliens.tex
with
19 additions
and
14 deletions
docs/cmu-user/aliens.tex
+
19
−
14
View file @
06121692
...
...
@@ -848,6 +848,7 @@ Assume we have the C function below that we wish to use:
for (k = 0; k < n; ++k)
\{
sum += x[k] * y[k];
\}
return sum;
\}
\end{example}
...
...
@@ -857,25 +858,29 @@ possible using \code{malloc} or \code{make-alien} since we need about
16 MB of memory to hold the two arrays.
\begin{example}
(def-alien-routine "dotprod" double
(
alien:
def-alien-routine "dotprod"
c-call:
double
(x (* double-float) :in)
(y (* double-float) :in)
(n int :in))
(n
c-call:
int :in))
(let ((x (make-array 1000000 :element-type 'double-float))
(y (make-array 1000000 :element-type 'double-float)))
;; Initialize X and Y somehow
(let ((x-addr (system:int-sap (array-data-address x)))
(y-addr (system:int-sap (array-data-address y))))
(dotprod x-addr y-addr 1000000)))
(defun test-dotprod ()
(let ((x (make-array 10000 :element-type 'double-float :initial-element 2d0))
(y (make-array 10000 :element-type 'double-float :initial-element 10d0)))
(sys:without-gcing
(let ((x-addr (sys:vector-sap x))
(y-addr (sys:vector-sap y)))
(dotprod x-addr y-addr 10000)))))
\end{example}
In this example, it may be useful to wrap the inner
\code
{
let
}
expression in an
\code
{
unwind-protect
}
that first turns off garbage
collection and then turns garbage collection on afterwards. This will
prevent garbage collection from moving
\code
{
x
}
and
\code
{
y
}
after we
have obtained the (now erroneous) addresses but before the call to
\code
{
dotprod
}
is made.
In this example, we have used
\code
{
sys:vector-sap
}
instead of
\code
{
array-data-address
}
, but we could have used
\code
{
(sys:int-sap
(array-data-address x))
}
as well.
Also, we have wrapped the inner
\code
{
let
}
expression in a
\code
{
sys:without-gcing
}
that disables garbage collection for the
duration of the body. This will prevent garbage collection from
moving
\code
{
x
}
and
\code
{
y
}
arrays after we have obtained the (now
erroneous) addresses but before the call to
\code
{
dotprod
}
is made.
\section
{
Step-by-Step Alien Example
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment