int MFNHashTypePlainOpenCL::setOpenCLDeviceID(int newOpenCLPlatformId, int newOpenCLDeviceId) {
    trace_printf("MFNHashTypePlainOpenCL::setOpenCLDeviceID(%d, %d)\n", newOpenCLPlatformId, newOpenCLDeviceId);
    
    MFNCommandLineData *CommandLineData = MultiforcerGlobalClassFactory.getCommandlinedataClass();
    
    this->OpenCL = new CryptohazeOpenCL();

    if (newOpenCLPlatformId > this->OpenCL->getNumberOfPlatforms()) {
        printf("Error: OpenCL Platform ID %d not valid!\n", newOpenCLPlatformId);
        exit(1);
    }

    this->OpenCL->selectPlatformById(newOpenCLPlatformId);

    if (newOpenCLDeviceId > this->OpenCL->getNumberOfDevices()) {
        printf("Error: OpenCL Device ID %d not valid!\n", newOpenCLDeviceId);
        exit(1);
    }

    this->OpenCL->selectDeviceById(newOpenCLDeviceId);

    this->openCLPlatformId = newOpenCLPlatformId;
    this->gpuDeviceId = newOpenCLDeviceId;
    
 
    // If the blocks or threads are set, use them, else use the default.
    if (CommandLineData->GetGpuBlocks()) {
        this->GPUBlocks = CommandLineData->GetGpuBlocks();
    } else {
        this->GPUBlocks = this->OpenCL->getDefaultBlockCount();
    }

    if (CommandLineData->GetGpuThreads()) {
        this->GPUThreads = CommandLineData->GetGpuThreads();
    } else {
        this->GPUThreads = this->OpenCL->getDefaultThreadCount();
    }

    // If target time is 0, use defaults.
    if (CommandLineData->GetTargetExecutionTimeMs()) {
        this->kernelTimeMs = CommandLineData->GetTargetExecutionTimeMs();
    } else {
        this->kernelTimeMs = 100;
    }

    this->OpenCL->createContext();
    this->OpenCL->createCommandQueue();
 
    // For now - set by CLI later.
    this->VectorWidth = 4;

    this->TotalKernelWidth = this->GPUBlocks * this->GPUThreads * this->VectorWidth;

    trace_printf("Thread %d added OpenCL Device (%d, %d)\n", this->threadId,
            newOpenCLPlatformId, newOpenCLDeviceId);;

    return 1;
}
예제 #2
0
int MFNHashTypePlainCUDA::setCUDADeviceID(int newCUDADeviceId) {
    trace_printf("MFNHashTypePlainCUDA::setCUDADeviceID(%d)\n", newCUDADeviceId);
    
    CHCUDAUtils *CudaUtils = MultiforcerGlobalClassFactory.getCudaUtilsClass();
    MFNCommandLineData *CommandLineData = MultiforcerGlobalClassFactory.getCommandlinedataClass();
    
    if (newCUDADeviceId >= CudaUtils->getCudaDeviceCount()) {
        printf("Invalid device ID - greater than number of devices!\n");
        exit(1);
    }
    
    this->gpuDeviceId = newCUDADeviceId;
    
    // If the blocks or threads are set, use them, else use the default.
    if (CommandLineData->GetGpuBlocks()) {
        this->GPUBlocks = CommandLineData->GetGpuBlocks();
        klaunch_printf("Using CLI GPU Blocks %d\n", this->GPUBlocks);
    } else {
        this->GPUBlocks = CudaUtils->getCudaDefaultBlockCount(newCUDADeviceId);
        klaunch_printf("Using Default GPU Blocks %d\n", this->GPUBlocks);
    }
    
    if (CommandLineData->GetGpuThreads()) {
        this->GPUThreads = CommandLineData->GetGpuThreads();
        klaunch_printf("Using CLI GPU Threads %d\n", this->GPUThreads);
    } else {
        this->GPUThreads = CudaUtils->getCudaDefaultThreadCount(newCUDADeviceId);
        klaunch_printf("Using Default GPU Threads %d\n", this->GPUThreads);
    }
    
    // If target time is 0, use defaults.
    if (CommandLineData->GetTargetExecutionTimeMs()) {
        this->kernelTimeMs = CommandLineData->GetTargetExecutionTimeMs();
    } else {
        if (CudaUtils->getCudaHasTimeout(newCUDADeviceId)) {
            this->kernelTimeMs = 50;
        } else {
            this->kernelTimeMs = 500;
        }
    }
    
    // Override thread count if needed for hash type.
    this->GPUThreads = this->getMaxHardwareThreads(this->GPUThreads);
    
    this->VectorWidth = 1;
    this->TotalKernelWidth = this->GPUBlocks * this->GPUThreads * this->VectorWidth;
    
    //printf("Successfully added device %d, thread ID %d\n", newCUDADeviceId, this->threadId);
    //printf("Thread %d blocks/threads/vec: %d/%d/%d\n", this->threadId, this->GPUBlocks, this->GPUThreads, this->VectorWidth);

    return 1;
}