Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions src/backend/cuda/blas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@
#include <blas.hpp>
#include <cuda_runtime.h>
#include <cublas_v2.h>
#include <platform.hpp>

#include <stdexcept>
#include <string>
#include <cassert>
#include <iostream>
#include <math.hpp>
#include <err_common.hpp>
#include <boost/scoped_ptr.hpp>

namespace cuda
{
Expand Down Expand Up @@ -48,24 +50,29 @@ class cublasHandle
{
cublasHandle_t handle;
public:
cublasHandle()
{
cublasHandle() : handle(0){
cublasStatus_t cErr;
cErr = cublasCreate(&handle);
if(cErr != CUBLAS_STATUS_SUCCESS) {
using std::string;
throw std::runtime_error(string("cuBLAS Error: ") + cublasErrorString(cErr));
}
}

~cublasHandle() { cublasDestroy(handle);}
operator cublasHandle_t() { return handle; }
};

cublasHandle&
getHandle()
{
static cublasHandle handle;
return handle;
using boost::scoped_ptr;
static scoped_ptr<cublasHandle> handle[DeviceManager::MAX_DEVICES];
if(!handle[getActiveDeviceId()]) {
handle[getActiveDeviceId()].reset(new cublasHandle());
}

return *handle[getActiveDeviceId()];
}

cublasOperation_t
Expand Down
32 changes: 32 additions & 0 deletions test/blas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,3 +208,35 @@ TYPED_TEST(MatrixMultiply, RectangleVector_CPP)
{
cppMatMulCheck<TypeParam, true>(TEST_DIR"/blas/RectangleVector.test");
}

TYPED_TEST(MatrixMultiply, MultiGPUSquare_CPP)
{
for(int i = 0; i < af::getDeviceCount(); i++) {
af::setDevice(i);
cppMatMulCheck<TypeParam, false>(TEST_DIR"/blas/Basic.test");
}
}

TYPED_TEST(MatrixMultiply, MultiGPUNonSquare_CPP)
{
for(int i = 0; i < af::getDeviceCount(); i++) {
af::setDevice(i);
cppMatMulCheck<TypeParam, false>(TEST_DIR"/blas/NonSquare.test");
}
}

TYPED_TEST(MatrixMultiply, MultiGPUSquareVector_CPP)
{
for(int i = 0; i < af::getDeviceCount(); i++) {
af::setDevice(i);
cppMatMulCheck<TypeParam, true>(TEST_DIR"/blas/SquareVector.test");
}
}

TYPED_TEST(MatrixMultiply, MultiGPURectangleVector_CPP)
{
for(int i = 0; i < af::getDeviceCount(); i++) {
af::setDevice(i);
cppMatMulCheck<TypeParam, true>(TEST_DIR"/blas/RectangleVector.test");
}
}