Vitis コア開発キットでは、デバイスに複数の同じカーネルまたは異なるカーネルのインスタンスが含まれることがあります。
clCreateSubDevices
という OpenCL API を使用してもホスト コードでデバイスを複数のサブデバイスに分割できますが、Vitis コア開発キットでは CL_DEVICE_PARTITION_EQUALLY
による均等なサブデバイス分割 (サブデバイスごとにカーネル インスタンスを 1 つずつ含む) がサポートされています。
この後の例では、次が実行されます。
- サブデバイスごとに 1 つのカーネル インスタンスを実行する同等分割で作成されます。
- 別のコンテキストおよびコマンド キューを使用してサブデバイス リストを反復実行し、それぞれでカーネルを実行します。
- 単純にするため、カーネル実行に関する API (および対応するバッファーに関する) コードは示していませんが、関数
run_cu
内に記述してください。
cl_uint num_devices = 0;
cl_device_partition_property props[3] = {CL_DEVICE_PARTITION_EQUALLY,1,0};
// Get the number of sub-devices
clCreateSubDevices(device,props,0,nullptr,&num_devices);
// Container to hold the sub-devices
std::vector<cl_device_id> devices(num_devices);
// Second call of clCreateSubDevices
// We get sub-device handles in devices.data()
clCreateSubDevices(device,props,num_devices,devices.data(),nullptr);
// Iterating over sub-devices
std::for_each(devices.begin(),devices.end(),[kernel](cl_device_id sdev) {
// Context for sub-device
auto context = clCreateContext(0,1,&sdev,nullptr,nullptr,&err);
// Command-queue for sub-device
auto queue = clCreateCommandQueue(context,sdev,
CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE,&err);
// Execute the kernel on the sub-device using local context and
queue run_cu(context,queue,kernel); // Function not shown
});
重要: 例に示すように、サブデバイスごとに別のコンテキストを作成する必要があります。OpenCL では、複数のデバイスおよびサブデバイスを保持するコンテキストが作成できますが、XRT ではデバイスおよびサブデバイスごとに別のコンテキストを作成する必要があります。