Некорректная работа CUDA на другом компьютере

В VS2019 была написана программа, сравнивающая скорость сортировки пузырьком на CPU и битонической сортировки на GPU (CUDA). На других компьютерах программа работает корректно, на моем - нет: вместо сортировки самих чисел происходит сортировка их модулей. Видеокарта NVIDIA Geforce 940M. Чем вызвана эта проблема и как можно ее исправить?

#define _CRT_SECURE_NO_WARNINGS 
#include <cuda_runtime.h>
#include <device_launch_parameters.h>
#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>
#include <time.h>
#include <math.h>

void bubbleSortCPU(int* mas, int n) {
    for (int i = 0; i < n - 1; i++) {
        for (int j = n - 1; j > i; j--) {
            if (mas[j - 1] > mas[j]) {
                int temp = mas[j - 1];
                mas[j - 1] = mas[j];
                mas[j] = temp;
            }
        }
    }
}

void array_filling(int* arr, int n) {
    int i, num;
    arr[0] = time(0) * rand() % (2 * n);
    for (i = 1; i < n; i++) {
        if (i < n / 2) {
            num = time(0) * rand() % (n * 10);
            while (num <= arr[i - 1]) num = time(0) * rand() % (n * (10 + i));
            arr[i] = num;
        }
        else {
            while (!(num < arr[i - 1])) num = time(0) * rand() % (n * 10) - num;
            arr[i] = num;
        }
    }
}

int isMasEquall(int* mas_1, int* mas_2, int n) {
    int error = 0;
    for (int i = 0; i < n; i++) {
        if (mas_1[i] != mas_2[i]) error++;
    }
    return error;
}

__global__ void bitonicSortGPU(int* mas, int n, int len) {
    int i = blockIdx.x * blockDim.x + threadIdx.x;
    if (i < n / 2) {
        if (i % len >= 0 && i >= len) i += len * (i / len);
        if (mas[i] > mas[i + len]) {
            int elem = mas[i];
            mas[i] = mas[i + len];
            mas[i + len] = elem;
        }
    }
}

void main() {
    int *mas_2, n = 8192;
    cudaMalloc((void**)&mas_2, sizeof(int) * n);
    int* mas_1;
    mas_1 = (int*)malloc(sizeof(int) * n);
    array_filling(mas_1, n);
    cudaMemcpy(mas_2, mas_1, sizeof(int) * n, cudaMemcpyHostToDevice);
    clock_t start_1 = clock();
    bubbleSortCPU(mas_1, n);
    clock_t end_1 = clock();
    double time_1 = end_1 - start_1;
    float t = 0;
    cudaEvent_t start, stop;
    cudaEventCreate(&start);
    cudaEventCreate(&stop);
    cudaEventRecord(start, 0);
    //------------------------------------
    int len = n / 2;
    while (len != 0) {
        bitonicSortGPU <<<10, n / 8>>> (mas_2, n, len);
        len /= 2;
    }
    //------------------------------------
    cudaEventRecord(stop, 0);
    cudaEventSynchronize(stop);
    cudaEventElapsedTime(&t, start, stop);   
    int* mas = (int*)malloc(sizeof(int) * n);
    cudaMemcpy(mas, mas_2, sizeof(int) * n, cudaMemcpyDeviceToHost);
    cudaFree(mas_2);
    if (isMasEquall(mas_1, mas, n) == 0) printf("Outputs are equivalent");
    else printf("Outputs are not equivalent");
    printf("\nBubble sort run time: %lf", time_1);
    printf("\nBitonic sort run time: %lf", t);
}

Ответы (0 шт):