Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

solve converts gpuMatrix to vclMatrix #108

Closed
nielsenmarkus11 opened this issue Jan 11, 2018 · 2 comments
Closed

solve converts gpuMatrix to vclMatrix #108

nielsenmarkus11 opened this issue Jan 11, 2018 · 2 comments
Assignees
Labels
Milestone

Comments

@nielsenmarkus11
Copy link

So, in trying to do a simple regression with gpuR I've run into a problem... when I test the following code:

epsilon <- rnorm(1000000,0,100)
X <- as.matrix(cbind(rep(1,1000000),
                     rnorm(1000000,5,15),
                     rnorm(1000000,3,12),
                     rnorm(1000000,0,100),
                     rnorm(1000000,100,10)))
mod <- as.matrix(c(12,3,5,-1,10))
Y <- X%*%mod + epsilon

system.time(Beta <- solve(t(X)%*%X)%*%t(X)%*%Y)
system.time(X+X)
Beta

gpuX <- gpuMatrix(X,type = 'float')
gpuY <- gpuMatrix(as.matrix(Y),type = 'float')

system.time(gpuBeta <- solve(t(gpuX)%*%gpuX)%*%t(gpuX)%*%gpuY)
system.time(gpuX+gpuX)
gpuBeta[]

I get the following error for gpuBeta <- solve(t(gpuX)%*%gpuX)%*%t(gpuX)%*%gpuY:

Error in .Primitive("%*%")(x, y) : 
  requires numeric/complex matrix/vector arguments

I don't get the error any more when I change the objects to class vclMatrix:

gpuX <- vclMatrix(X,type = 'float')
gpuY <- vclMatrix(as.matrix(Y),type = 'float')

However the VRAM this takes is much higher than doing this with typical RAM. The object X takes up approx. 38 Mb of RAM where gpuX takes up over 700 MiB VRAM. Am I doing this correctly, or have I gone wrong somewhere or are there configurations that I need to tweak?

I'm using an Nvidia GeForce GTX 1050 with 1 GiB memory.

> sessionInfo()
R version 3.2.3 (2015-12-10)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 16.04.3 LTS

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C               LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8     LC_MONETARY=en_US.UTF-8   
 [6] LC_MESSAGES=en_US.UTF-8    LC_PAPER=en_US.UTF-8       LC_NAME=C                  LC_ADDRESS=C               LC_TELEPHONE=C            
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] gpuR_2.0.0     h2o_3.13.0.369

loaded via a namespace (and not attached):
 [1] Rcpp_0.12.14               assertive.sets_0.0-3       codetools_0.2-14           assertive.data.us_0.0-1    assertive.types_0.0-3     
 [6] assertive.properties_0.0-4 bitops_1.0-6               jsonlite_1.5               assertive.base_0.0-7       assertive.models_0.0-1    
[11] assertive.code_0.0-1       stringi_1.1.2              assertive.strings_0.0-3    assertive.matrices_0.0-1   assertive.reflection_0.0-4
[16] assertive.datetimes_0.0-2  assertive.data_0.0-1       assertive_0.3-5            tools_3.2.3                RCurl_1.95-4.8            
[21] assertive.numbers_0.0-2    yaml_2.1.14                assertive.files_0.0-2      assertive.data.uk_0.0-1    knitr_1.16  
@cdeterman
Copy link
Owner

Thanks for reporting your issue. You have encountered two problems with gpuR currently. To address you first concern regarding solve returning vclMatrix. This was an intentional decision on my part to make the function more efficient. Internally, this allowed the output matrix to be initialized on the device (e.g. GPU) and thereby avoid copying data from host to the device. At the same time, it avoids bringing the data back to the host when completed. I'm not sure there would be a great benefit to forcing it to move back to a gpuMatrix but perhaps I still should to maintain consistency with how the rest of the package API works (i.e. gpuMatrix in -> gpuMatrix out).

Second, the memory issue is definitely a known problem. This is because of the automatic padding done by ViennaCL in increments of 128. As such, although your initial matrix only has 5 columns, the internal matrix object actual has 128. Allowing for the creation of unpadded matrices is scheduled for the next release of ViennaCL as noted in the issue here.

@cdeterman
Copy link
Owner

After thinking about this more I think I will change the solve function to still return to gpuMatrix. This one exception flies in the face of the way the rest of the package works so it should be the same. I will change it in the develop branch in the coming days and it will be part of the 2.1.0 release.

@cdeterman cdeterman added this to the 2.1.0 milestone Feb 23, 2018
@cdeterman cdeterman self-assigned this Feb 23, 2018
@cdeterman cdeterman added the bug label Feb 23, 2018
cdeterman added a commit that referenced this issue Feb 23, 2018
…g a non-identity matrix. The intention is to create identity matrices on the device to avoid the data transfer with gpuMatrix calls. This needed a flag to note when this shouldn't be the case. This should fix the broken unit tests.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants