Commit c479bed4 by Zoltan Karsa

file write

parent f9b951c8
......@@ -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)
......
......@@ -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)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment