「複数のOpenCLデバイスを使ってみる」で試した複数のデバイスを使うために、「外部ファイル読み取り関数をOpenCLラップクラスに追加」のOpenCLラップクラスにPlatform選択とDevice選択機能を追加した。
引数にPlatformを指定するインデックスとDeviceを指定するインデックスをとるコンストラクタを追加した。
OpenCL::OpenCL(int platformIndex, int deviceIndex) { this->setPlatform(); this->setContext(CL_DEVICE_TYPE_ALL, platformIndex); this->setDevice(); this->queue_ = cl::CommandQueue(this->context_, this->devices_.at(deviceIndex), 0, &this->error_); }
この変更に伴って、setContext関数の引数を変更している。setContext関数は次の2種類が存在する。
- cl_int setContext()
- cl_int setContext(cl_device_type deviceType)
両方の引数にplatformIndexを追加し、次のように変更した。
- cl_int setContext(int platformIndex)
- cl_int setContext(cl_device_type deviceType, int platformIndex)
それぞれ、内部でcl_context_properties生成時のplataform指定を"0"固定から、platformIndexを使用するように変更している。それに伴い既存のコンストラクタ内でも明示的にplatformIndexを指定している。
変更後のソースとドキュメントはこちら。
コメント