16.1. コマンドキュー

16.1.1. CommandQueue

CommandQueueクラスのコンストラクタはコマンドキューを生成します。

Note

詳しくは「表:clCreateCommandQueue」(Table B.23, “表:clCreateCommandQueue”)と「表:cl_command_queue_properties」(Table B.24, “表:cl_command_queue_properties”)を参照ください。

class pyopencl.CommandQueue(
    context, #(1)
    device=None, #(2)
    properties=None) #(3)

(1)

有効なOpenCLコンテキストを指定。

(2)

対象とするOpenCLデバイスを指定。

(3)

コマンドキューのプロパティのリストを指定するビットフィールド。

では実際のコードを見てみましょう。以下が実装例となります。

import pyopencl as cl
device = cl.get_platforms()[0].get_devices(device_type=cl.device_type.GPU)
ctx = cl.Context(device)
queue = cl.CommandQueue(ctx) #(1)

(1)

コンテキストに関連づけられたデバイス上をターゲットにしたコマンドキューのインスタンスを生成します。

プロパティやデバイスオブジェクトを引数に入れてないので、フィールドは無視されます。

16.1.2. command_queue_properties

Note

詳しくは「表:clCreateCommandQueue」(Table B.23, “表:clCreateCommandQueue”)と「表:cl_command_queue_properties」(Table B.24, “表:cl_command_queue_properties”)を参照ください。

CommandQueueの引数のpropertiesはcommand_queue_propertiesの値からなるビットフィールドです。

class pyopencl.command_queue_properties

command_queue_propertiesのビットフィールド値は以下の表の通りです。

Table 16.1. pyopencl.command_queue_properties

ON_DEVICE(2.0)
ON_DEVICE_DEFAULT(2.0)
OUT_OF_ORDER_EXEC_MODE_ENABLE
PROFILING_ENABLE

ちなみに「OUT_OF_ORDER_EXEC_MODE_ENABLE」については、Intel HD Graphics 4000はサポートしないため、エラーとなります。

16.1.3. from_int_ptr

from_int_ptr関数はcommand_queueの参照カウントをインクリメント。

Note

詳しくは「表:clRetainCommandQueue」(Table B.25, “表:clRetainCommandQueue”)を参照ください。

pyopencl.CommandQueue.from_int_ptr(int_ptr_value, retain=True)

clGetCommandQueueInfo

clGetCommandQueueInfo関数はコマンドキューについての情報を取得します。

Note

詳しくは「表:clGetCommandQueueInfo」(Table B.27, “表:clGetCommandQueueInfo”)と「表:cl_command_queue_info」(Table B.28, “表:cl_command_queue_info”)を参照ください。

pyopencl.CommandQueue.get_info(param) #(1)

(1)

param引数は取得する情報をcommand_queue_infoのビットフィールド値で指定。

ではコード例を見てみましょう。以下のコードでは、コマンドキューに関連付けられたデバイスを取得しています。

device = queue.get_info(cl.command_queue_info.DEVICE)

実装例

import pyopencl as cl
import numpy as np

device = cl.get_platforms()[0].get_devices(device_type=cl.device_type.GPU)

ctx = cl.Context(device)
clprop = cl.command_queue_properties

queue_profile = cl.CommandQueue(ctx, properties=clprop.PROFILING_ENABLE)
props = queue_profile.get_info(cl.command_queue_info.PROPERTIES)
print("Properties on queue_profile: " + clprop.to_string(props))

device = queue_profile.get_info(cl.command_queue_info.DEVICE)
print("DEVICE name: " + device.get_info(cl.device_info.NAME))

出力. 

Properties on queue_profile: PROFILING_ENABLE
DEVICE name: HD Graphics 4000

16.1.4. command_queue_info

Note

詳しくは「表:clGetCommandQueueInfo」(Table B.27, “表:clGetCommandQueueInfo”)と「表:cl_command_queue_info」(Table B.28, “表:cl_command_queue_info”)を参照ください。

コマンドキューの情報を指定するビットフィールドです。宣言は以下のようになります。

class pyopencl.command_queue_info

Table 16.2. pyopencl.command_queue_info

CONTEXT
DEVICE
PROPERTIES
REFERENCE_COUNT

Copyright 2018-2019, by Masaki Komatsu