Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Karsa Zoltán István
/
politopok
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
c479bed4
authored
Feb 03, 2023
by
Zoltan Karsa
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
file write
parent
f9b951c8
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
39 additions
and
11 deletions
+39
-11
tetrarun.py
+9
-5
utils.py
+30
-6
No files found.
tetrarun.py
View file @
c479bed4
...
...
@@ -2,17 +2,17 @@ import sys, getopt
from
genax
import
gen_angels_to_pick
,
angles_alap
,
angles_ratet
from
gpu
import
start_kernel
from
utils
import
convert
,
printresults
,
search
,
exact_one
,
exact_one_gpu
,
filter_gpu
from
utils
import
convert
,
printresults
,
search
,
exact_one
,
exact_one_gpu
,
filter_gpu
,
writetofile
def
main
(
argv
):
outputfile
=
'out.txt'
outputfile
=
None
n
=
3
v
=
3
w
=
3
PLOT
=
False
try
:
opts
,
args
=
getopt
.
getopt
(
argv
,
"hpn:v:w:d:"
)
opts
,
args
=
getopt
.
getopt
(
argv
,
"hpn:v:w:d:
o:
"
)
except
getopt
.
GetoptError
as
err
:
print
(
err
)
print
(
'tetrarun.py -n <range division:int> -v <> -w <> -o <outputfile>'
)
...
...
@@ -41,9 +41,13 @@ def main(argv):
Dx
,
Dy
,
Dz
=
angles_ratet
(
space
)
res
=
start_kernel
(
Cx
,
Cy
,
Dx
,
Dy
,
Dz
,
v
,
w
)
if
outputfile
:
writetofile
(
outputfile
,
Cx
,
Cy
,
Dx
,
Dy
,
Dz
,
res
)
#printresults(res)
print
(
"Exact one 3-3"
)
exact_one_gpu
(
res
,
3
-
1
,
3
-
1
)
#
print("Exact one 3-3")
#
exact_one_gpu(res, 3-1, 3-1)
#print("Filter 2-1")
#filter21 = filter_gpu(res, 2-1, 1-1)
...
...
utils.py
View file @
c479bed4
...
...
@@ -2,6 +2,7 @@ import cupy as cp
from
functools
import
wraps
import
time
import
torch
import
numpy
as
np
with
open
(
'filtering.cu'
)
as
f
:
code
=
f
.
read
()
...
...
@@ -56,6 +57,34 @@ def printresults(egyensulyi_mtx):
print
(
np
.
resize
(
parok
,
(
int
(
N
/
2
),
2
)))
print
()
def
writetofile
(
filename
,
Cx
,
Cy
,
Dx
,
Dy
,
Dz
,
egyensulyi_mtx
):
lcm
=
compute_lcm
(
Cx
.
size
,
Dx
.
size
)
Cx_cpu
=
Cx
.
get
()
Cy_cpu
=
Cy
.
get
()
Dx_cpu
=
Dx
.
get
()
Dy_cpu
=
Dy
.
get
()
Dz_cpu
=
Dz
.
get
()
mtx_cpu
=
egyensulyi_mtx
.
get
()
pos
=
Cx
.
size
*
Dx
.
size
f
=
open
(
filename
,
"w"
)
size_C
=
Cx
.
size
size_D
=
Dx
.
size
for
i
in
range
(
0
,
pos
):
parok
=
np
.
empty
([
0
],
dtype
=
np
.
int8
)
for
S
in
range
(
0
,
4
):
for
U
in
range
(
0
,
4
):
if
mtx_cpu
[
i
][
S
][
U
]
==
1
:
parok
=
np
.
append
(
parok
,
S
+
1
)
parok
=
np
.
append
(
parok
,
U
+
1
)
N
=
parok
.
size
f
.
write
(
f
"{Cx_cpu[i
%
size_C]}, {Cy_cpu[i
%
size_C]}, {Dx_cpu[(i + int(i / lcm))
%
size_D]}, {Dy_cpu[(i + int(i / lcm))
%
size_D]}, {Dz_cpu[(i + int(i / lcm))
%
size_D]}
\n
"
)
f
.
write
(
np
.
array2string
(
np
.
resize
(
parok
,
(
int
(
N
/
2
),
2
))))
f
.
write
(
"
\n
"
)
f
.
close
()
def
search
(
egyensulyi_mtx
,
S
,
U
):
for
i
in
egyensulyi_mtx
:
if
i
[
S
][
U
]
==
1
:
...
...
@@ -82,12 +111,7 @@ def exact_one_gpu(egyensulyi_mtx, S, U):
indexes
=
cp
.
zeros
((
size
,),
dtype
=
bool
)
numBlock
=
int
((
size
+
256
-
1
)
/
256
)
exact_one_cuda
((
numBlock
,),
(
256
,),
(
egyensulyi_mtx
,
size
,
indexes
,
S
,
U
))
t_emtx
=
torch
.
as_tensor
(
egyensulyi_mtx
,
device
=
torch
.
device
(
'cuda'
),
dtype
=
torch
.
int8
)
assert
t_emtx
.
__cuda_array_interface__
[
'data'
][
0
]
==
egyensulyi_mtx
.
__cuda_array_interface__
[
'data'
][
0
]
t_ind
=
torch
.
as_tensor
(
indexes
,
device
=
torch
.
device
(
'cuda'
),
dtype
=
torch
.
bool
)
t_ind
=
t_ind
.
unsqueeze
(
-
1
)
.
unsqueeze
(
-
1
)
.
expand
(
-
1
,
4
,
4
)
res
=
torch
.
masked_select
(
t_emtx
,
t_ind
)
return
res
return
egyensulyi_mtx
[
indexes
]
def
filter_gpu
(
egyensulyi_mtx
,
S
,
U
):
size
=
int
(
egyensulyi_mtx
.
size
/
16
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment