0

以下は、upload() が返されない GPU に画像をアップロードしようとすると、スレッドが停止しているように見える単純なプログラムです。デバイス情報の呼び出しはすべて正常に機能し、適切な値を返します。

  1. GPU へのアップロードはスレッドで可能ですか?
  2. もしそうなら、私は以下で何が間違っていますか?どうすればそれを機能させることができますか?

ここに私の簡単なテストコードがあります:

#include <cstdlib>
#include <iostream>
#include <pthread.h>
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/core/core.hpp"
#include "opencv2/gpu/gpu.hpp" // For GPU processing

using namespace std;


void *PrintHello(void *threadid)
{
    cv::gpu::GpuMat gInputImage, gOutputImage;
    cv::Mat image, image2, image3;

    long tid;
    tid = (long)threadid;

    cout << "Hello World! Thread ID, " << tid << endl;
    cout << "loading image in main memory" << endl;
    image = cv::imread("tdf_1972_poster.jpg");

    cout << "deviceID: " << cv::gpu::getDevice() << endl;
    cv::gpu::DeviceInfo mydeviceinfo = cv::gpu::DeviceInfo();
    cout << "name: " << mydeviceinfo.name() << endl;

    cv::gpu::setDevice(0); // I don't think this will help at all.

    cout << "cols before cpu resize: " << image.cols << endl;
    cv::resize(image, image2, cv::Size(), .5, 0.5, cv::INTER_NEAREST);
    cout << "cols after cpu resize: " << image2.cols << endl;

    cout << "cols before gpu resize: " << image.cols << endl;
    gInputImage.upload(image); // thread stalls here.
    cv::gpu::resize(gInputImage, gOutputImage, cv::Size(), .5, 0.5, cv::INTER_NEAREST);
    gOutputImage.download(image3);
    cout << "cols after gpu resize: " << image3.cols << endl;

    pthread_exit(NULL);
}

int main ()
{
    pthread_t threads[1];
    int rc;
    int i;

    cout << "main() : creating thread, "<< endl;
    rc = pthread_create(&threads[0], NULL, PrintHello, 0);
    if (rc){
      cout << "Error:unable to create thread," << rc << endl;
      exit(1);
    }
    pthread_exit(NULL);
}

これは私が得る出力です:

main() : creating thread, 
Hello World! Thread ID, 0
loading image in main memory
deviceID: 0
name: GeForce GTX 560 Ti
cols before cpu resize: 374
cols after cpu resize: 187
cols before gpu resize: 374
4

1 に答える 1