Sha256: 871b5a7d1a1406ceabae1d4096899765563ae0606d3ad66546b472b12001eef4

Contents?: true

Size: 923 Bytes

Versions: 20

Compression:

Stored size: 923 Bytes

Contents

require_relative '../cuda'

module Cumo::CUDA
  class Device
    attr_reader :id

    def self.get_currend_id
      Runtime.cudaGetDevice
    end

    def initialize(device_id = nil)
      if device_id
        @id = device_id
      else
        @id = Runtime.cudaGetDevice
      end
      @_device_stack = []
    end

    def use
      Runtime.cudaSetDevice(@id)
    end

    def with
      raise unless block_given?
      prev_id = Runtime.cudaGetDevice
      @_device_stack << prev_id
      begin
        Runtime.cudaSetDevice(@id) unless prev_id != @id
        yield
      ensure
        prev_id = @_device_stack.pop
        Runtime.cudaSetDevice(prev_id)
      end
    end

    def synchronize
      Runtime.cudaDeviceSynchronize
    end

    def compute_capability
      major = Runtime.cudaDeviceGetAttributes(75, @id)
      minor = Runtime.cudaDeviceGetAttributes(76, @id)
      "#{major}#{minor}"
    end
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
cumo-0.4.3 lib/cumo/cuda/device.rb
cumo-0.4.2 lib/cumo/cuda/device.rb
cumo-0.4.1 lib/cumo/cuda/device.rb
cumo-0.4.0 lib/cumo/cuda/device.rb
cumo-0.3.5 lib/cumo/cuda/device.rb
cumo-0.3.4 lib/cumo/cuda/device.rb
cumo-0.3.3 lib/cumo/cuda/device.rb
cumo-0.3.2 lib/cumo/cuda/device.rb
cumo-0.3.1 lib/cumo/cuda/device.rb
cumo-0.3.0 lib/cumo/cuda/device.rb
cumo-0.3.0.pre1 lib/cumo/cuda/device.rb
cumo-0.2.5 lib/cumo/cuda/device.rb
cumo-0.2.4 lib/cumo/cuda/device.rb
cumo-0.2.3 lib/cumo/cuda/device.rb
cumo-0.2.2 lib/cumo/cuda/device.rb
cumo-0.2.1 lib/cumo/cuda/device.rb
cumo-0.2.0 lib/cumo/cuda/device.rb
cumo-0.1.2 lib/cumo/cuda/device.rb
cumo-0.1.1 lib/cumo/cuda/device.rb
cumo-0.1.0 lib/cumo/cuda/device.rb