pycudaでGPU(device)の情報を得る 

ちょっとしたことですが、pycuda中でdevice informationがほしい時があるかもしれません。というときのメモです。

##pycudaのimport

```
import pycuda.autoinit
import pycuda.driver as cuda
```

##個別に表示する

```
for i in range(cuda.Device.count()):
    dev=cuda.Device(i)
    print dev.name()
    print dev.max_threads_per_block
    print dev.max_shared_memory_per_block
    print dev.max_grid_dim_x
```
こんな感じで表示されるはず

```
GeForce GTX 965M
1024
49152
2147483647
```

##得たい情報のattribute名などがわからない

```
dev.get_attributes()
```

のようにすると

```
{pycuda._driver.device_attribute.MAX_THREADS_PER_BLOCK: 1024,
 pycuda._driver.device_attribute.MAX_BLOCK_DIM_X: 1024,
 pycuda._driver.device_attribute.MAX_BLOCK_DIM_Y: 1024,
 pycuda._driver.device_attribute.MAX_BLOCK_DIM_Z: 64,
 pycuda._driver.device_attribute.MAX_GRID_DIM_X: 2147483647,
 pycuda._driver.device_attribute.MAX_GRID_DIM_Y: 65535,
 pycuda._driver.device_attribute.MAX_GRID_DIM_Z: 65535,
 pycuda._driver.device_attribute.MAX_SHARED_MEMORY_PER_BLOCK: 49152,
 pycuda._driver.device_attribute.TOTAL_CONSTANT_MEMORY: 65536,
 pycuda._driver.device_attribute.WARP_SIZE: 32,
 pycuda._driver.device_attribute.MAX_PITCH: 2147483647,
 pycuda._driver.device_attribute.MAX_REGISTERS_PER_BLOCK: 65536,
 pycuda._driver.device_attribute.CLOCK_RATE: 1150000,
 pycuda._driver.device_attribute.TEXTURE_ALIGNMENT: 512,
 pycuda._driver.device_attribute.GPU_OVERLAP: 1,
 pycuda._driver.device_attribute.MULTIPROCESSOR_COUNT: 8,
 pycuda._driver.device_attribute.KERNEL_EXEC_TIMEOUT: 1,
 pycuda._driver.device_attribute.INTEGRATED: 0,
 pycuda._driver.device_attribute.CAN_MAP_HOST_MEMORY: 1,
 pycuda._driver.device_attribute.COMPUTE_MODE: pycuda._driver.compute_mode.DEFAULT,
 pycuda._driver.device_attribute.MAXIMUM_TEXTURE1D_WIDTH: 65536,
 pycuda._driver.device_attribute.MAXIMUM_TEXTURE2D_WIDTH: 65536,
 pycuda._driver.device_attribute.MAXIMUM_TEXTURE2D_HEIGHT: 65536,
 pycuda._driver.device_attribute.MAXIMUM_TEXTURE3D_WIDTH: 4096,
 pycuda._driver.device_attribute.MAXIMUM_TEXTURE3D_HEIGHT: 4096,
 pycuda._driver.device_attribute.MAXIMUM_TEXTURE3D_DEPTH: 4096,
 pycuda._driver.device_attribute.MAXIMUM_TEXTURE2D_ARRAY_WIDTH: 16384,
 pycuda._driver.device_attribute.MAXIMUM_TEXTURE2D_ARRAY_HEIGHT: 16384,
 pycuda._driver.device_attribute.MAXIMUM_TEXTURE2D_ARRAY_NUMSLICES: 2048,
 pycuda._driver.device_attribute.SURFACE_ALIGNMENT: 512,
 pycuda._driver.device_attribute.CONCURRENT_KERNELS: 1,
 pycuda._driver.device_attribute.ECC_ENABLED: 0,
 pycuda._driver.device_attribute.PCI_BUS_ID: 1,
 pycuda._driver.device_attribute.PCI_DEVICE_ID: 0,
 pycuda._driver.device_attribute.TCC_DRIVER: 0,
 pycuda._driver.device_attribute.MEMORY_CLOCK_RATE: 2505000,
 pycuda._driver.device_attribute.GLOBAL_MEMORY_BUS_WIDTH: 128,
 pycuda._driver.device_attribute.L2_CACHE_SIZE: 1048576,
 pycuda._driver.device_attribute.MAX_THREADS_PER_MULTIPROCESSOR: 2048,
 pycuda._driver.device_attribute.ASYNC_ENGINE_COUNT: 2,
 pycuda._driver.device_attribute.UNIFIED_ADDRESSING: 1,
 pycuda._driver.device_attribute.MAXIMUM_TEXTURE1D_LAYERED_WIDTH: 16384,
 pycuda._driver.device_attribute.MAXIMUM_TEXTURE1D_LAYERED_LAYERS: 2048,
 pycuda._driver.device_attribute.MAXIMUM_TEXTURE2D_GATHER_WIDTH: 16384,
 pycuda._driver.device_attribute.MAXIMUM_TEXTURE2D_GATHER_HEIGHT: 16384,
 pycuda._driver.device_attribute.MAXIMUM_TEXTURE3D_WIDTH_ALTERNATE: 2048,
 pycuda._driver.device_attribute.MAXIMUM_TEXTURE3D_HEIGHT_ALTERNATE: 2048,
 pycuda._driver.device_attribute.MAXIMUM_TEXTURE3D_DEPTH_ALTERNATE: 16384,
 pycuda._driver.device_attribute.PCI_DOMAIN_ID: 0,
 pycuda._driver.device_attribute.TEXTURE_PITCH_ALIGNMENT: 32,
 pycuda._driver.device_attribute.MAXIMUM_TEXTURECUBEMAP_WIDTH: 16384,
 pycuda._driver.device_attribute.MAXIMUM_TEXTURECUBEMAP_LAYERED_WIDTH: 16384,
 pycuda._driver.device_attribute.MAXIMUM_TEXTURECUBEMAP_LAYERED_LAYERS: 2046,
 pycuda._driver.device_attribute.MAXIMUM_SURFACE1D_WIDTH: 16384,
 pycuda._driver.device_attribute.MAXIMUM_SURFACE2D_WIDTH: 65536,
 pycuda._driver.device_attribute.MAXIMUM_SURFACE2D_HEIGHT: 65536,
 pycuda._driver.device_attribute.MAXIMUM_SURFACE3D_WIDTH: 4096,
 pycuda._driver.device_attribute.MAXIMUM_SURFACE3D_HEIGHT: 4096,
 pycuda._driver.device_attribute.MAXIMUM_SURFACE3D_DEPTH: 4096,
 pycuda._driver.device_attribute.MAXIMUM_SURFACE1D_LAYERED_WIDTH: 16384,
 pycuda._driver.device_attribute.MAXIMUM_SURFACE1D_LAYERED_LAYERS: 2048,
 pycuda._driver.device_attribute.MAXIMUM_SURFACE2D_LAYERED_WIDTH: 16384,
 pycuda._driver.device_attribute.MAXIMUM_SURFACE2D_LAYERED_HEIGHT: 16384,
 pycuda._driver.device_attribute.MAXIMUM_SURFACE2D_LAYERED_LAYERS: 2048,
 pycuda._driver.device_attribute.MAXIMUM_SURFACECUBEMAP_WIDTH: 16384,
 pycuda._driver.device_attribute.MAXIMUM_SURFACECUBEMAP_LAYERED_WIDTH: 16384,
 pycuda._driver.device_attribute.MAXIMUM_SURFACECUBEMAP_LAYERED_LAYERS: 2046,
 pycuda._driver.device_attribute.MAXIMUM_TEXTURE1D_LINEAR_WIDTH: 134217728,
 pycuda._driver.device_attribute.MAXIMUM_TEXTURE2D_LINEAR_WIDTH: 65536,
 pycuda._driver.device_attribute.MAXIMUM_TEXTURE2D_LINEAR_HEIGHT: 65536,
 pycuda._driver.device_attribute.MAXIMUM_TEXTURE2D_LINEAR_PITCH: 1048544,
 pycuda._driver.device_attribute.MAXIMUM_TEXTURE2D_MIPMAPPED_WIDTH: 16384,
 pycuda._driver.device_attribute.MAXIMUM_TEXTURE2D_MIPMAPPED_HEIGHT: 16384,
 pycuda._driver.device_attribute.COMPUTE_CAPABILITY_MAJOR: 5,
 pycuda._driver.device_attribute.COMPUTE_CAPABILITY_MINOR: 2,
 pycuda._driver.device_attribute.MAXIMUM_TEXTURE1D_MIPMAPPED_WIDTH: 16384,
 pycuda._driver.device_attribute.STREAM_PRIORITIES_SUPPORTED: 1,
 pycuda._driver.device_attribute.GLOBAL_L1_CACHE_SUPPORTED: 1,
 pycuda._driver.device_attribute.LOCAL_L1_CACHE_SUPPORTED: 1,
 pycuda._driver.device_attribute.MAX_SHARED_MEMORY_PER_MULTIPROCESSOR: 98304,
 pycuda._driver.device_attribute.MAX_REGISTERS_PER_MULTIPROCESSOR: 65536,
 pycuda._driver.device_attribute.MANAGED_MEMORY: 1,
 pycuda._driver.device_attribute.MULTI_GPU_BOARD: 0,
 pycuda._driver.device_attribute.MULTI_GPU_BOARD_GROUP_ID: 0}
```

のようにattributes全部が表示されるので、ここから探すこともできます。