Comments (3)
@xinyazhang Thank you for reporting this error. Fixes are in the following hipBLAS and rocBLAS commits:
- hipBLAS: 5b1d8ff
- rocBLAS: 335704afda003156408280bfc4d10bd2c59ff5f4
The line below is required before calling hipblasGemmEx:
hipblasSetInt8Datatype(handle, HIPBLAS_INT8_DATATYPE_INT8);
The code below shows the above call and verifies the result. Running the code
gives:
Result from rocblas_gemm_ex with i8 input
62, 74, 14, 63, 20, -85, 43, 93,
Result from hipblasGemmEx with i8 input
62, 74, 14, 63, 20, -85, 43, 93,
Without the call to hipblasSetInt8Datatype the incorrect result is:
Result from rocblas_gemm_ex with i8 input
62, 74, 14, 63, 20, -85, 43, 93,
Result from hipblasGemmEx with i8 input
-49, 147, -89, 34, 117, 20, -47, -2,
#include <stdio.h>
#include <iostream>
#include <stdint.h>
#define __HIP_PLATFORM_AMD__
#include <hipblas.h>
#include <rocblas.h>
#include <vector>
#define CHECK_HIP_ERROR(error) \
if(error != hipSuccess) \
{ \
fprintf(stderr, \
"Hip error: '%s'(%d) at %s:%d\n", \
hipGetErrorString(error), \
error, \
__FILE__, \
__LINE__); \
exit(EXIT_FAILURE); \
}
#define CHECK_HIPBLAS_ERROR(error) \
if(error != HIPBLAS_STATUS_SUCCESS) \
{ \
fprintf(stderr, "rocBLAS error: "); \
if(error == HIPBLAS_STATUS_NOT_INITIALIZED) \
fprintf(stderr, "HIPBLAS_STATUS_NOT_INITIALIZED"); \
if(error == HIPBLAS_STATUS_ALLOC_FAILED) \
fprintf(stderr, "HIPBLAS_STATUS_ALLOC_FAILED"); \
if(error == HIPBLAS_STATUS_INVALID_VALUE) \
fprintf(stderr, "HIPBLAS_STATUS_INVALID_VALUE"); \
if(error == HIPBLAS_STATUS_MAPPING_ERROR) \
fprintf(stderr, "HIPBLAS_STATUS_MAPPING_ERROR"); \
if(error == HIPBLAS_STATUS_EXECUTION_FAILED) \
fprintf(stderr, "HIPBLAS_STATUS_EXECUTION_FAILED"); \
if(error == HIPBLAS_STATUS_INTERNAL_ERROR) \
fprintf(stderr, "HIPBLAS_STATUS_INTERNAL_ERROR"); \
if(error == HIPBLAS_STATUS_NOT_SUPPORTED) \
fprintf(stderr, "HIPBLAS_STATUS_NOT_SUPPORTED"); \
if(error == HIPBLAS_STATUS_INVALID_ENUM) \
fprintf(stderr, "HIPBLAS_STATUS_INVALID_ENUM"); \
if(error == HIPBLAS_STATUS_UNKNOWN) \
fprintf(stderr, "HIPBLAS_STATUS_UNKNOWN"); \
fprintf(stderr, "\n"); \
exit(EXIT_FAILURE); \
}
int main()
{
int m = 2;
int n = 4;
int k = 4;
int sizeA = m*k;
int sizeB = k*n;
int sizeC = m*n;
std::vector<int8_t> hA{-3, 7, 5, -6, 4, -5, 8, 7};
std::vector<int8_t> hB{5, -3, 7, 8, -6, -8, -3, 6, 7, 9, 9, -5, 8, 7, -6, 7};
std::vector<int32_t> hC(sizeC);
int32_t alpha = 1;
int32_t beta = 0;
int lda = m;
int ldb = k;
int ldc = m;
int8_t *da, *db, *dc;
// Note da and db are allocated large enough for a32 and b32
CHECK_HIP_ERROR(hipMalloc(&da, sizeA * sizeof(int8_t)));
CHECK_HIP_ERROR(hipMalloc(&db, sizeB * sizeof(int8_t)));
CHECK_HIP_ERROR(hipMalloc(&dc, sizeC * sizeof(int32_t)));
// copy matrices from host to device
// Let's try ROC BLAS
{
rocblas_handle handle;
rocblas_create_handle(&handle);
rocblas_operation transa = rocblas_operation_none;
rocblas_operation transb = rocblas_operation_none;
CHECK_HIP_ERROR(hipMemcpy(da, hA.data(), sizeof(int8_t) * sizeA, hipMemcpyHostToDevice));
CHECK_HIP_ERROR(hipMemcpy(db, hB.data(), sizeof(int8_t) * sizeB, hipMemcpyHostToDevice));
CHECK_HIP_ERROR(hipMemset(dc, 0, sizeof(int32_t) * sizeC ));
rocblas_gemm_ex(handle,
transa, transb,
m, n, k,
&alpha,
da, rocblas_datatype_i8_r, lda,
db, rocblas_datatype_i8_r, ldb,
&beta,
dc, rocblas_datatype_i32_r, ldc,
dc, rocblas_datatype_i32_r, ldc, // C == D
rocblas_datatype_i32_r,
rocblas_gemm_algo_standard,
0, 0);
CHECK_HIP_ERROR(hipMemcpy(hC.data(), dc, sizeof(int32_t) * sizeC, hipMemcpyDeviceToHost));
std::cout << "Result from rocblas_gemm_ex with i8 input" << std::endl;
for(int32_t i : hC){ std::cout << i << ", ";};
std::cout << std::endl;
rocblas_destroy_handle(handle);
}
// HIP BLAS
hipblasHandle_t handle;
CHECK_HIPBLAS_ERROR(hipblasCreate(&handle));
// below line is needed to use int8_t datatype in place of packed_int8x4 datatype
hipblasSetInt8Datatype(handle, HIPBLAS_INT8_DATATYPE_INT8);
hipblasOperation_t transa = HIPBLAS_OP_N;
hipblasOperation_t transb = HIPBLAS_OP_N;
CHECK_HIP_ERROR(hipMemcpy(da, hA.data(), sizeof(int8_t) * sizeA, hipMemcpyHostToDevice));
CHECK_HIP_ERROR(hipMemcpy(db, hB.data(), sizeof(int8_t) * sizeB, hipMemcpyHostToDevice));
CHECK_HIP_ERROR(hipMemset(dc, 0, sizeof(int32_t) * sizeC));
CHECK_HIPBLAS_ERROR(hipblasGemmEx(handle,
transa,
transb,
m, n, k,
&alpha,
da, HIPBLAS_R_8I, lda,
db, HIPBLAS_R_8I, ldb,
&beta,
dc, HIPBLAS_R_32I, ldc,
HIPBLAS_R_32I,
HIPBLAS_GEMM_DEFAULT));
CHECK_HIP_ERROR(hipMemcpy(hC.data(), dc, sizeof(int32_t) * sizeC, hipMemcpyDeviceToHost));
std::cout << "Result from hipblasGemmEx with i8 input" << std::endl;
for(int32_t i : hC){ std::cout << i << ", ";};
std::cout << std::endl;
CHECK_HIP_ERROR(hipFree(da));
CHECK_HIP_ERROR(hipFree(db));
CHECK_HIP_ERROR(hipFree(dc));
CHECK_HIPBLAS_ERROR(hipblasDestroy(handle));
return 0;
}
from hipblas.
warning: 'hipblasSetInt8Datatype' is deprecated: "The hipblasSetInt8Datatype function will be removed in a future release and only int8_t datatype will be supported. packed_int8x4 datatype support will be removed." [-Wdeprecated-declarations]
hipblasSetInt8Datatype(handle, HIPBLAS_INT8_DATATYPE_INT8);
hipblasSetInt8Datatype is still required..
from hipblas.
Is rocblas preferred over hipblas ?
from hipblas.
Related Issues (20)
- Error with `DgetriBatched` function on AMD devices HOT 5
- GemmEx of float16 runs so fast but with wrong result HOT 12
- hipBLAS Ubuntu packaging is broken HOT 2
- hipBLAS compiled for CUDA cannot be found in CMake HOT 4
- Link broken in the README for `hipBLAS functions` HOT 1
- [5.3.X] TRMM functions do not have correct correspondence in hipBLAS HOT 4
- [5.3.X][CUDA >= 11.0] `hipblasGemmEx` doesn't fully match `cublasGemmEx` HOT 2
- performance of hipblasHgemm HOT 9
- Type of AP in hipblasStrsm functions HOT 2
- hipblasSgemm extremely slow when compared to cublasSgemm HOT 4
- Building rocBLAS for CUDA backend fails HOT 2
- 64-bit interface HOT 3
- hipEventCreate HOT 1
- question about axpby HOT 2
- question about mixed precision dot HOT 3
- compute type of hipblasGemmEx HOT 2
- add topic tags HOT 3
- hipblasXgelsBatched() failed with error HOT 1
- Results of hipblasHgemm seems incorrect HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from hipblas.