Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
arrayzy
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
Model registry
Operate
Environments
Monitor
Incidents
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
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Matt Wala
arrayzy
Commits
2d2fed9b
Commit
2d2fed9b
authored
4 years ago
by
Andreas Klöckner
Browse files
Options
Downloads
Patches
Plain Diff
More hacking while chatting with Matt
parent
1455930a
Branches
master
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
arrayzy/array.py
+13
-1
13 additions, 1 deletion
arrayzy/array.py
experiments/atax.py
+38
-0
38 additions, 0 deletions
experiments/atax.py
with
51 additions
and
1 deletion
arrayzy/array.py
+
13
−
1
View file @
2d2fed9b
...
...
@@ -38,6 +38,10 @@ class Context:
.. attribute:: target
A :class:`Target` for code generation and execution.
.. note::
*program* may not define any names starting with underscores.
"""
def
__init__
(
self
,
program
,
bindings
,
target
):
...
...
@@ -116,6 +120,9 @@ class Array:
An instance of :class:`loopy.types.LoopyType` or *None* to indicate
that the type of the array is not yet known.
.. attribute:: expression
"""
def
__init__
(
self
,
context
,
shape
,
dtype
,
expression
):
...
...
@@ -146,7 +153,12 @@ def make_sym(context, name, shape, dtype=None):
context
.
update_program
(
context
.
program
.
copy
(
arguments
=
context
.
program
.
arguments
+
[
arg
]))
# return Array(context,
# TODO make sure "name" is not taken
v_name
=
prim
.
Variable
(
name
)
subscripts
=
tuple
(
prim
.
Variable
(
???
)
for
i
in
range
(
len
(
shape
)))
return
Array
(
context
,
expression
=
v_name
[
subscripts
])
def
zeros
(
context
,
shape
,
dtype
):
...
...
This diff is collapsed.
Click to expand it.
experiments/atax.py
0 → 100644
+
38
−
0
View file @
2d2fed9b
import
numpy
as
np
import
pyopencl
as
cl
import
pyopencl.clrandom
import
arrayzy
as
az
import
loopy
as
lp
import
numpy
import
numpy.linalg
as
la
def
matvec
(
a
,
b
):
matvec_knl
=
lp
.
make_kernel
(
"
{[i,j]: 0<=i<m and 0<=j<n}
"
,
"
out[i] = sum(j, a[i,j]*x[j])
"
)
return
az
.
call_kernel
(
matvec_knl
,
a
=
a
,
b
=
b
)
def
main
(
dims
=
2
,
order
=
4
):
cl_ctx
=
cl
.
create_some_context
()
queue
=
cl
.
CommandQueue
(
cl_ctx
)
ctx
=
az
.
make_context
(
queue
)
# queue??
a
=
cl
.
clrandom
.
rand
(
queue
,
(
20
,
20
),
dtype
=
np
.
float64
)
x
=
cl
.
clrandom
.
rand
(
queue
,
(
20
,),
dtype
=
np
.
float64
)
a_l
=
az
.
bind
(
ctx
,
"
a
"
,
a
,
shape
=
"
n,n
"
)
# a_l = az.bind(ctx, "A", a)
x_l
=
az
.
make_sym
(
ctx
,
"
x
"
,
"
n
"
,
np
.
float64
)
result
=
matvec
(
a_l
.
T
,
matvec
(
a_l
,
x_l
).
store
())
# result = A.T @ A @ x
a_h
=
a
.
get
()
assert
la
.
norm
(
result
.
eval
(
x
=
x
).
get
()
-
a_h
.
T
@
a_h
@
x
)
<
1e-12
if
__name__
==
"
__main__
"
:
main
()
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