【发布时间】:2021-02-01 12:15:49
【问题描述】:
数组存储为xyzxyz...,我想获取某个方向(x或y或z)的最大值和最小值,这是测试程序:
#include <cuda_runtime.h>
#include <cuda_runtime_api.h> // cudaMalloc, cudaMemcpy, etc.
#include <cublas_v2.h>
#include <helper_functions.h> // shared functions common to CUDA Samples
#include <helper_cuda.h> // CUDA error checking
#include <stdio.h> // printf
#include <iostream>
template <typename T>
void print_arr(T *arr, int L)
{
for (int i = 0; i < L; i++)
{
std::cout << arr[i] << " ";
}
std::cout << std::endl;
}
int main()
{
float hV[10] = {3, 0, 7, 1, 2, 8, 6, 7, 6, 4};
print_arr(hV, 10);
float *dV;
cudaMalloc(&dV, sizeof(float) * 10);
cudaMemcpy(dV, hV, sizeof(float) * 10, cudaMemcpyHostToDevice);
cublasHandle_t cublasHandle = NULL;
checkCudaErrors(cublasCreate(&cublasHandle));
int hResult[2] = {0};
checkCudaErrors(cublasIsamax(cublasHandle, 10, dV, 3, hResult + 0));
checkCudaErrors(cublasIsamin(cublasHandle, 10, dV, 3, hResult + 1));
print_arr(hResult, 2);
return 0;
}
预期结果:
3 0 7 1 2 8 6 7 6 4
3 2
结果:
3 0 7 1 2 8 6 7 6 4
3 5
这个结果有问题吗?还是我理解错了?
link 到 cublasIsamin。
【问题讨论】: