Skip to content
Snippets Groups Projects
Commit ecba9ede authored by Denis Arrivault's avatar Denis Arrivault
Browse files

Svd tests for gpu

parent 3d0e3ae5
Branches
No related tags found
No related merge requests found
Pipeline #
...@@ -5,14 +5,13 @@ Created on 20 févr. 2018 ...@@ -5,14 +5,13 @@ Created on 20 févr. 2018
@author: arrivault @author: arrivault
''' '''
import sys
from timeit import default_timer as timer from timeit import default_timer as timer
from splearn import Spectral from splearn import Spectral
from splearn.tests.datasets.get_dataset_path import get_dataset_path from splearn.tests.datasets.get_dataset_path import get_dataset_path
from splearn.datasets.base import load_data_sample from splearn.datasets.base import load_data_sample
def launch(X, version='classic', partial=True, sparse=True, smooth_method='none'): def launch_fit(X, version='classic', partial=True, sparse=True, smooth_method='none'):
param = "****** {:s} - partial = {:b} - sparse = {:b}, {:s} *****".format(version, partial, sparse, smooth_method) param = "****** {:s} - partial = {:b} - sparse = {:b}, {:s} *****".format(version, partial, sparse, smooth_method)
print(param) print(param)
...@@ -33,7 +32,7 @@ def launch(X, version='classic', partial=True, sparse=True, smooth_method='none' ...@@ -33,7 +32,7 @@ def launch(X, version='classic', partial=True, sparse=True, smooth_method='none'
# else: # else:
# print("The result is different", file=sys.stderr) # print("The result is different", file=sys.stderr)
def test(): def test_fit():
adr = get_dataset_path("3.pautomac_light.train") adr = get_dataset_path("3.pautomac_light.train")
data = load_data_sample(adr=adr) data = load_data_sample(adr=adr)
X = data.data X = data.data
...@@ -43,7 +42,7 @@ def test(): ...@@ -43,7 +42,7 @@ def test():
# for partial in param['partial']: # for partial in param['partial']:
for sparse in param['sparse']: for sparse in param['sparse']:
for smooth_method in param['smooth_method']: for smooth_method in param['smooth_method']:
launch(X, version=version, partial=True, sparse=sparse, smooth_method=smooth_method) launch_fit(X, version=version, partial=True, sparse=sparse, smooth_method=smooth_method)
if __name__ == '__main__': if __name__ == '__main__':
test() test_fit()
# -*- coding: utf-8 -*-
'''
Created on 20 févr. 2018
@author: arrivault
'''
import sys
from timeit import default_timer as timer
import numpy as np
def test_svd():
d = 100
A = np.asarray(np.random.randint(1, 10,(d, d)), dtype=np.float64)
# scipy
print("\n****************** Scipy")
from scipy import linalg as sc_linalg
start = timer()
u_sc, s_sc, v_sc = sc_linalg.svd(A)
duration = timer() - start
print("SVD scipy : " + str(duration))
print(s_sc)
print(type(s_sc))
# scikit-cuda
print("\n****************** scikit-cuda")
import pycuda.autoinit
import pycuda.gpuarray as gpuarray
#import ctypes
#ctypes.CDLL('libgomp.so.1', mode=ctypes.RTLD_GLOBAL)
from skcuda import linalg as sk_linalg
start = timer()
sk_linalg.init()
A_sk = gpuarray.to_gpu(A)
u_sk, s_sk, vh_sk = sk_linalg.svd(A_sk, jobu='S', jobvt='S', lib='cusolver')
u_sk, s_sk, v_sk = u_sk.get_async(), s_sk.get_async(), vh_sk.get_async()
duration = timer() - start
print("SVD skcuda : " + str(duration))
print(s_sk)
print(type(s_sk))
# tensorflow
print("\n****************** tensorflow")
import tensorflow as tf
from tensorflow import linalg as tf_linalg
start = timer()
with tf.Session(config=tf.ConfigProto(log_device_placement=True)) as sess:
s_tf, u_tf, v_tf = tf_linalg.svd(A)
s_tf, u_tf, v_tf = s_tf.eval(), u_tf.eval(), v_tf.eval()
duration = timer() - start
print("SVD tensorflow : " + str(duration))
print(s_tf)
print(type(s_tf))
# Theano
print("\n****************** theano")
import theano.tensor as T
from theano import function
import theano.tensor.nlinalg as th_linalg
x = T.dmatrix('x')
u, s, v = th_linalg.svd(x)
f = function([x], (u, s, v))
start = timer()
u_th, s_th, v_th = f(A)
duration = timer() - start
print("SVD theano : " + str(duration))
print(s_th)
print(type(s_th))
if __name__ == '__main__':
test_svd()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment