cdeterman / gpuR

R interface to use GPU's
241 stars 26 forks source link

deviceHasDouble returns TRUE on device without double support #11

Closed jubilatious1 closed 8 years ago

jubilatious1 commented 8 years ago
> devtools::install_github("cdeterman/gpuR", ref = "develop")
...
Error: package ‘RViennaCL’ 1.7.1-0 was found, but >= 1.7.1.1 is required by ‘cdeterman-gpuR-a27bc9c’

R version 3.2.3 (2015-12-10) -- "Wooden Christmas-Tree" Copyright (C) 2015 The R Foundation for Statistical Computing Platform: x86_64-apple-darwin13.4.0 (64-bit) MacOSX 10.10.5 (Yosemite)

cdeterman commented 8 years ago

@jubilatious1 Ah, sorry, I neglected to say that the current 'develop' branch requires you to also install the RViennaCL from my git repo as well. I added a few updates to help work with multiple GPU's that I haven't released to CRAN yet.

Try installing RViennaCL and the try to install gpuR again.

devtools::install_github("cdeterman/RViennaCL")
jubilatious1 commented 8 years ago

Thanks Charles! Didn't notice you had a development branch here on Github. So RViennaCL_1.7.1-1 and gpuR_1.0.2 are installed with no problems (OpenCL 1.2 headers installed).

However... although I followed build instructions here (OpenCL 1.2): https://github.com/cdeterman/gpuR/wiki/Build-Instructions-for-OSX clang++ install warnings and R-project ViennaCL errors below:

>* installing *source* package ‘gpuR’ ...  
checking "Checking for C++ Compiler"... checking for g++... g++  
checking whether the C++ compiler works... yes  
checking for C++ compiler default output file name... a.out  
checking for suffix of executables...   
checking whether we are cross compiling... no  
checking for suffix of object files... o  
checking whether we are using the GNU C++ compiler... yes  
checking whether g++ accepts -g... yes  
checking how to run the C++ preprocessor... g++ -E  
checking build system type... x86_64-apple-darwin14.5.0  
checking host system type... x86_64-apple-darwin14.5.0  
Darwin OS  
checking "Checking OpenCL C++ API"... checking for grep that handles long lines and -e...   /usr/bin/grep  
checking for egrep... /usr/bin/grep -E  
checking for ANSI C header files... yes  
checking for sys/types.h... yes  
checking for sys/stat.h... yes  
checking for stdlib.h... yes  
checking for string.h... yes  
checking for memory.h... yes  
checking for strings.h... yes  
checking for inttypes.h... yes  
checking for stdint.h... yes  
checking for unistd.h... yes  
checking OpenCL/cl2.hpp usability... no  
checking OpenCL/cl2.hpp presence... no  
checking for OpenCL/cl2.hpp... no  
checking OpenCL/cl.hpp usability... yes  
checking OpenCL/cl.hpp presence... yes  
checking for OpenCL/cl.hpp... yes  
configure: Building Makevars  
configure: creating ./config.status  
config.status: creating src/Makevars  
** libs 
clang++ <SNIP>

>context.cpp:75:9: warning: unused variable 'num_devices' [-Wunused-variable]
    int num_devices;
        ^
1 warning generated.

clang++ <SNIP>

>In file included from dynVCLVec.cpp:4:  In file included from ../inst/include/gpuR/dynVCLVec.hpp:14:  In file included from /Users/me/Library/R/3.2/library/RViennaCL/include/viennacl/vector.hpp:33:  In file included from /Users/me/Library/R/3.2/library/RViennaCL/include/viennacl/linalg/vector_operations.hpp:39:  In file included from /Users/me/Library/R/3.2/library/RViennaCL/include/viennacl/linalg/opencl/vector_operations.hpp:35:  In file included from /Users/me/Library/R/3.2/library/RViennaCL/include/viennacl/linalg/opencl/kernels/vector.hpp:25:  In file included from /Users/me/Library/R/3.2/library/RViennaCL/include/viennacl/scheduler/preset.hpp:21:  /Users/me/Library/R/3.2/library/RViennaCL/include/viennacl/device_specific/forwards.h:130:20:  warning: unused function 'generate_value_kernel_argument' [-Wunused-function]  static std::string generate_value_kernel_argument(std::string const & scalartype, std::string const & name)  
                   ^  /Users/me/Library/R/3.2/library/RViennaCL/include/viennacl/device_specific/forwards.h:136:20:  warning: unused function 'generate_pointer_kernel_argument' [-Wunused-function]  static std::string generate_pointer_kernel_argument(std::string const & address_space, std::string const & scalartype, std::string const & name)  
                   ^
2 warnings generated. 

R-output:

> library(gpuR)
> A <- gpuMatrix(rnorm(10000), 100, 100)
> A %*% A
Error: ViennaCL: FATAL ERROR: You requested to create a ViennaCL type using double precision. However, double precision is not supported by your device.
If you think that this is a bug in ViennaCL, please report it at viennacl-support@lists.sourceforge.net and supply at least the following information:
 * Operating System
 * Which OpenCL implementation (AMD, NVIDIA, etc.)
 * ViennaCL version
Many thanks in advance!

MacOSX 10.10.5 (Yosemite) Intel Iris Graphics 6100 1536 MB https://support.apple.com/en-us/HT202823 ViennaCL version ??

cdeterman commented 8 years ago

Thanks @jubilatious1. The warnings are minor issues that can likely be dealt with. Regarding the error, can you run the function deviceHasDouble() and let me know if it returns TRUE or FALSE? I expect it will return FALSE. If so, I will likely have the gpu objects default to single precision when double precision is not available.

jubilatious1 commented 8 years ago

(in R-project Console)

> deviceHasDouble()
[1] TRUE

While the GPU is onboard (integrated), Apple has supported this OpenCL config since ~2013 (Intel Iris 4000 HD): https://developer.apple.com/videos/play/wwdc2013-508/

Quick question: while MacOSX ships with OpenCL, do I have to specifically install ViennaCL? Or does RViennaCL act as a wrapper for ViennaCL?

http://viennacl.sourceforge.net/viennacl-download.html

Thank you!

cdeterman commented 8 years ago

@jubilatious1 you do not need to install ViennaCL. The RViennaCL is intended to be a wrapper for it similar to the BH package for boost headers.

Odd that it shows double support when ViennaCL thinks there isn't during multiplication. Could you also provide the output of listContexts()?

jubilatious1 commented 8 years ago
>  deviceHasDouble()
[1] TRUE

> library(pander)
>pandoc.table(listContexts(), style = 'rmarkdown', keep.line.breaks = TRUE)
context platform platform_index
1 Apple: OpenCL 1.2 (May 10 2015 19:38:45) 0

Table: Table continues below

device device_index device_type
Intel(R) Iris(TM) Graphics 6100 0 gpu

cdeterman commented 8 years ago

@jubilatious1 okay, one last thing that I forgot now that I see this, please also provide the output of gpuInfo(). I will need to look in to this device's specifics.

Thanks

jubilatious1 commented 8 years ago
> pandoc.table(gpuInfo(), style = 'rmarkdown', keep.line.breaks = TRUE)
deviceName deviceVendor numberOfCores
Intel(R) Iris(TM) Graphics 6100 Intel 48

Table: Table continues below

maxWorkGroupSize maxWorkItemDim maxWorkItemSizes
256 3 256, 256, 256

Table: Table continues below

deviceMemory clockFreq localMem maxAllocatableMem
1610612736 1100 65536 402653184

Table: Table continues below

available
yes

Table: Table continues below

deviceExtensions
cl_APPLE_SetMemObjectDestructor, cl_APPLE_ContextLoggingFunctions, cl_APPLE_clut, cl_APPLE_query_kernel_names, cl_APPLE_gl_sharing, cl_khr_gl_event, cl_khr_global_int32_base_atomics, cl_khr_global_int32_extended_atomics, cl_khr_local_int32_base_atomics, cl_khr_local_int32_extended_atomics, cl_khr_byte_addressable_store, cl_khr_image2d_from_buffer, cl_khr_gl_depth_images, cl_khr_depth_images, cl_khr_3d_image_writes,

R>

Thank you!

cdeterman commented 8 years ago

@jubilatious1 Hmm... something appears off with the deviceHasDouble(). I can see in the device extensions that there isn't a "cl_khr_fp64" extension so the function should return FALSE. I just added another field to gpuInfo().

Please reinstall the 'develop' branch and run gpuInfo() again and see if the new double_support field is still TRUE or if 'correctly' labeled as FALSE.

devtools::install_github("cdeterman/gpuR", ref = "develop")
library(gpuR)
gpuInfo()$double_support

Thanks

jubilatious1 commented 8 years ago

(R-console; installed to Library->Frameworks folder just to be sure)

> devtools::install_github("cdeterman/gpuR", ref = "develop", lib="/Library/Frameworks/R.framework/Versions/3.2/Resources/library")        
> library(gpuR)
> gpuInfo()$double_support
[1] FALSE

but...

> deviceHasDouble()
[1] TRUE
> 
cdeterman commented 8 years ago

@jubilatious1 I have created a different backend function to check for double support of the current device. Please run cpp_device_has_double_test() and let me know the result.

Note, I am also going to change the name of this issue as it is more on the double support bug.

jubilatious1 commented 8 years ago
*Apple System Information (Graphics):*
  Chipset Model:    Intel Iris Graphics 6100
  Type: GPU
  Bus:  Built-In
  VRAM (Dynamic, Max):  1536 MB
  Vendor:   Intel (0x8086)
  Device ID:    0x162b
  Revision ID:  0x0009

Intel product page: http://www.intel.com/content/www/us/en/support/graphics-drivers/intel-iris-graphics-6100-for-5th-generation-intel-core-processors.html

> devtools::install_github("cdeterman/gpuR", ref = "develop", lib="/Library/Frameworks/R.framework/Versions/3.2/Resources/library")

...appears to install into user's library folder, two warnings as before-- warning: unused function 'generate_value_kernel_argument' warning: unused function 'generate_pointer_kernel_argument'

> library(gpuR)
> cpp_device_has_double_test()
[1] TRUE
cdeterman commented 8 years ago

@jubilatious1 odd, well, I have just pushed another change I think should fix it (not particularly happy with it but it should work). Try once more reinstalling develop and run deviceHasDouble(). It should return FALSE.

Also, those two warnings I will need to speak with the viennacl developers. They are a minor issue and you should be able to safely ignore those.

jubilatious1 commented 8 years ago
> deviceHasDouble()
[1] FALSE

Is this a CPU/GPU thing? Do you need to query deviceHasDouble() as well as cpuHasDouble() and gpuHasDouble() ?
I've read that OpenCL can offload processing from the GPU back to the CPU if necessary... .

cdeterman commented 8 years ago

@jubilatious1 I'm not sure exactly why it was happening. It shouldn't be conflicting with the CPU. My strategy was to create a new OpenCL context will only gpu devices and determine if the given index (i.e. GPU) has double precision. However, it appears that the context switching is causing some unforseen problems. That said, it appears to be working correctly in the gpuInfo() call. So I think it is best to just have the deviceHasDouble essentially as a wrapper around gpuInfo. This appears to be working, given the output you provided. I will add in the additional checks when creating objects. That way whenever a user tries to create a gpuMatrix/vclMatrix they will receive an error stating that double support is not available and to set type = "float". I will let you know once the checks are available. Thanks

jubilatious1 commented 8 years ago

Thank you Charles! I added type="float" and rechecked:

> library(gpuR)
> deviceHasDouble()
[1] FALSE
> A <- gpuMatrix(rnorm(10000), 100, 100)
> A %*% A
Error in gpu_Mat_mult(x, y) : 
  Selected GPU does not support double precision
> A <- gpuMatrix(rnorm(10000), 100, 100, type="float")
> A %*% A

An object of class "fgpuMatrix"
Slot "address":
<pointer: 0x108537360>

Slot ".context_index":
[1] 1

Slot ".platform_index":
[1] 1

Slot ".platform":
[1] "Apple"

Slot ".device_index":
[1] 1

Slot ".device":
[1] "Intel(R) Iris(TM) Graphics 6100"

> A %*% t(A)
Error in t.default(A) : argument is not a matrix
jubilatious1 commented 8 years ago

Hi Charles, this is the latest gpuInfo() ; might be more readable:

> gpuInfo()

$deviceName
[1] "Intel(R) Iris(TM) Graphics 6100"

$deviceVendor
[1] "Intel"

$numberOfCores
[1] 48

$maxWorkGroupSize
[1] 256

$maxWorkItemDim
[1] 3

$maxWorkItemSizes
[1] 256 256 256

$deviceMemory
[1] 1610612736

$clockFreq
[1] 1100

$localMem
[1] 65536

$maxAllocatableMem
[1] 402653184

$available
[1] "yes"

$deviceExtensions
 [1] "cl_APPLE_SetMemObjectDestructor"      "cl_APPLE_ContextLoggingFunctions"    
 [3] "cl_APPLE_clut"                        "cl_APPLE_query_kernel_names"         
 [5] "cl_APPLE_gl_sharing"                  "cl_khr_gl_event"                     
 [7] "cl_khr_global_int32_base_atomics"     "cl_khr_global_int32_extended_atomics"
 [9] "cl_khr_local_int32_base_atomics"      "cl_khr_local_int32_extended_atomics" 
[11] "cl_khr_byte_addressable_store"        "cl_khr_image2d_from_buffer"          
[13] "cl_khr_gl_depth_images"               "cl_khr_depth_images"                 
[15] "cl_khr_3d_image_writes"               ""                                    

$double_support
[1] FALSE
cdeterman commented 8 years ago

@jubilatious1 I'm glad it is working correctly now. Regarding the t error, I don't have a method currently defined for just t. I do however have crossprod and tcrossprod(i.e. A %*% t(A)). I will open a separate issue to implement t but I will close this one now.

jubilatious1 commented 8 years ago

Hi Charles,

How do I translate <pointer: 0x108537360> into a numerical result?

Thank you!

cdeterman commented 8 years ago

@jubilatious1 you can access the results with brackets []. I don't have a formally defined as.matrix function yet but something I was toying with adding.

Example

A <- gpuMatrix(rnorm(16), 4, 4)
B <- A[]