Apply .clangformat to all repo source files
Change-Id: I7e79c6058f0303f9a98911e3b7dd2e8596079344
[ROCm/clr commit: 9e47fccc89]
Dieser Commit ist enthalten in:
@@ -30,20 +30,20 @@ THE SOFTWARE.
|
||||
#include "hip/hip_runtime.h"
|
||||
#include "test_common.h"
|
||||
|
||||
int main( void ) {
|
||||
hipDeviceProp_t prop;
|
||||
int main(void) {
|
||||
hipDeviceProp_t prop;
|
||||
int dev;
|
||||
|
||||
hipGetDevice( &dev ) ;
|
||||
printf( "ID of current HIP device: %d\n", dev );
|
||||
hipGetDevice(&dev);
|
||||
printf("ID of current HIP device: %d\n", dev);
|
||||
|
||||
memset( &prop, 0, sizeof( hipDeviceProp_t ) );
|
||||
memset(&prop, 0, sizeof(hipDeviceProp_t));
|
||||
prop.major = 1;
|
||||
prop.minor = 3;
|
||||
hipChooseDevice( &dev, &prop );
|
||||
printf( "ID of hip device closest to revision 1.3: %d\n", dev );
|
||||
hipChooseDevice(&dev, &prop);
|
||||
printf("ID of hip device closest to revision 1.3: %d\n", dev);
|
||||
|
||||
hipSetDevice( dev );
|
||||
hipSetDevice(dev);
|
||||
|
||||
passed();
|
||||
}
|
||||
|
||||
@@ -30,14 +30,13 @@ THE SOFTWARE.
|
||||
|
||||
#include "test_common.h"
|
||||
|
||||
int main()
|
||||
{
|
||||
int main() {
|
||||
int numDevices = 0;
|
||||
int major,minor;
|
||||
int major, minor;
|
||||
hipDevice_t device;
|
||||
HIPCHECK(hipGetDeviceCount(&numDevices));
|
||||
for(int i=0;i<numDevices;i++){
|
||||
HIPCHECK(hipDeviceGet(&device,i));
|
||||
for (int i = 0; i < numDevices; i++) {
|
||||
HIPCHECK(hipDeviceGet(&device, i));
|
||||
HIPCHECK(hipDeviceComputeCapability(&major, &minor, device));
|
||||
HIPASSERT(major >= 0);
|
||||
HIPASSERT(minor >= 0);
|
||||
|
||||
@@ -30,25 +30,25 @@ THE SOFTWARE.
|
||||
#include "hip/hip_runtime.h"
|
||||
#include "test_common.h"
|
||||
|
||||
int main( void ) {
|
||||
int main(void) {
|
||||
char pciBusId[13];
|
||||
int deviceCount = 0;
|
||||
HIPCHECK(hipGetDeviceCount(&deviceCount));
|
||||
HIPASSERT(deviceCount != 0);
|
||||
for(int i=0; i< deviceCount;i++) {
|
||||
for (int i = 0; i < deviceCount; i++) {
|
||||
int pciBusID = -1;
|
||||
int pciDeviceID = -1;
|
||||
int pciDomainID = -1;
|
||||
int tempPciBusId = -1;
|
||||
int tempDeviceId = -1;
|
||||
HIPCHECK(hipDeviceGetPCIBusId ( &pciBusId[0], 13, i ));
|
||||
sscanf (pciBusId,"%04x:%02x:%02x",&pciDomainID,&pciBusID,&pciDeviceID);
|
||||
HIPCHECK(hipDeviceGetAttribute(&tempPciBusId,hipDeviceAttributePciBusId , i));
|
||||
if(pciBusID != tempPciBusId) {
|
||||
HIPCHECK(hipDeviceGetPCIBusId(&pciBusId[0], 13, i));
|
||||
sscanf(pciBusId, "%04x:%02x:%02x", &pciDomainID, &pciBusID, &pciDeviceID);
|
||||
HIPCHECK(hipDeviceGetAttribute(&tempPciBusId, hipDeviceAttributePciBusId, i));
|
||||
if (pciBusID != tempPciBusId) {
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
HIPCHECK(hipDeviceGetByPCIBusId ( &tempDeviceId, pciBusId ));
|
||||
if(tempDeviceId != i) {
|
||||
HIPCHECK(hipDeviceGetByPCIBusId(&tempDeviceId, pciBusId));
|
||||
if (tempDeviceId != i) {
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,15 +32,14 @@ THE SOFTWARE.
|
||||
|
||||
#define len 256
|
||||
|
||||
int main()
|
||||
{
|
||||
int main() {
|
||||
int numDevices = 0;
|
||||
char name[len];
|
||||
hipDevice_t device;
|
||||
HIPCHECK(hipGetDeviceCount(&numDevices));
|
||||
for(int i=0;i<numDevices;i++){
|
||||
HIPCHECK(hipDeviceGet(&device,i));
|
||||
HIPCHECK(hipDeviceGetName(name,len,device));
|
||||
for (int i = 0; i < numDevices; i++) {
|
||||
HIPCHECK(hipDeviceGet(&device, i));
|
||||
HIPCHECK(hipDeviceGetName(name, len, device));
|
||||
HIPASSERT(name != "");
|
||||
}
|
||||
passed();
|
||||
|
||||
@@ -30,20 +30,20 @@ THE SOFTWARE.
|
||||
#include "hip/hip_runtime.h"
|
||||
#include "test_common.h"
|
||||
|
||||
int main( void ) {
|
||||
int main(void) {
|
||||
char pciBusId[13];
|
||||
int deviceCount = 0;
|
||||
HIPCHECK(hipGetDeviceCount(&deviceCount));
|
||||
HIPASSERT(deviceCount != 0);
|
||||
for(int i=0; i< deviceCount;i++) {
|
||||
for (int i = 0; i < deviceCount; i++) {
|
||||
int pciBusID = -1;
|
||||
int pciDeviceID = -1;
|
||||
int pciDomainID = -1;
|
||||
int tempPciBusId = -1;
|
||||
HIPCHECK(hipDeviceGetPCIBusId ( &pciBusId[0], 13, i ));
|
||||
sscanf (pciBusId,"%04x:%02x:%02x",&pciDomainID,&pciBusID,&pciDeviceID);
|
||||
HIPCHECK(hipDeviceGetAttribute(&tempPciBusId,hipDeviceAttributePciBusId , i));
|
||||
if(pciBusID != tempPciBusId) {
|
||||
HIPCHECK(hipDeviceGetPCIBusId(&pciBusId[0], 13, i));
|
||||
sscanf(pciBusId, "%04x:%02x:%02x", &pciDomainID, &pciBusID, &pciDeviceID);
|
||||
HIPCHECK(hipDeviceGetAttribute(&tempPciBusId, hipDeviceAttributePciBusId, i));
|
||||
if (pciBusID != tempPciBusId) {
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ THE SOFTWARE.
|
||||
/*
|
||||
* Test for checking the functionality of
|
||||
* hipError_t hipDeviceSynchronize();
|
||||
*/
|
||||
*/
|
||||
|
||||
/* HIT_START
|
||||
* BUILD: %t %s ../../test_common.cpp
|
||||
@@ -28,47 +28,49 @@ THE SOFTWARE.
|
||||
* HIT_END
|
||||
*/
|
||||
|
||||
#include"test_common.h"
|
||||
#include "test_common.h"
|
||||
|
||||
#define _SIZE sizeof(int)*1024*1024
|
||||
#define _SIZE sizeof(int) * 1024 * 1024
|
||||
#define NUM_STREAMS 2
|
||||
|
||||
__global__ void Iter(hipLaunchParm lp, int *Ad, int num){
|
||||
__global__ void Iter(hipLaunchParm lp, int* Ad, int num) {
|
||||
int tx = threadIdx.x + blockIdx.x * blockDim.x;
|
||||
// Kernel loop designed to execute very slowly... ... ... so we can test timing-related behavior below
|
||||
if(tx == 0){
|
||||
for(int i = 0; i<num;i++){
|
||||
// Kernel loop designed to execute very slowly... ... ... so we can test timing-related
|
||||
// behavior below
|
||||
if (tx == 0) {
|
||||
for (int i = 0; i < num; i++) {
|
||||
Ad[tx] += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int main(){
|
||||
int *A[NUM_STREAMS];
|
||||
int *Ad[NUM_STREAMS];
|
||||
int main() {
|
||||
int* A[NUM_STREAMS];
|
||||
int* Ad[NUM_STREAMS];
|
||||
hipStream_t stream[NUM_STREAMS];
|
||||
for(int i=0;i<NUM_STREAMS;i++){
|
||||
for (int i = 0; i < NUM_STREAMS; i++) {
|
||||
HIPCHECK(hipHostMalloc((void**)&A[i], _SIZE, hipHostMallocDefault));
|
||||
A[i][0] = 1;
|
||||
HIPCHECK(hipMalloc((void**)&Ad[i], _SIZE));
|
||||
HIPCHECK(hipStreamCreate(&stream[i]));
|
||||
}
|
||||
for(int i=0;i<NUM_STREAMS;i++){
|
||||
for (int i = 0; i < NUM_STREAMS; i++) {
|
||||
HIPCHECK(hipMemcpyAsync(Ad[i], A[i], _SIZE, hipMemcpyHostToDevice, stream[i]));
|
||||
}
|
||||
for(int i=0;i<NUM_STREAMS;i++){
|
||||
hipLaunchKernel(HIP_KERNEL_NAME(Iter), dim3(1), dim3(1), 0, stream[i], Ad[i], 1<<30);
|
||||
for (int i = 0; i < NUM_STREAMS; i++) {
|
||||
hipLaunchKernel(HIP_KERNEL_NAME(Iter), dim3(1), dim3(1), 0, stream[i], Ad[i], 1 << 30);
|
||||
}
|
||||
for(int i=0;i<NUM_STREAMS;i++){
|
||||
for (int i = 0; i < NUM_STREAMS; i++) {
|
||||
HIPCHECK(hipMemcpyAsync(A[i], Ad[i], _SIZE, hipMemcpyDeviceToHost, stream[i]));
|
||||
}
|
||||
|
||||
|
||||
// This first check but relies on the kernel running for so long that the D2H async memcopy has not started yet.
|
||||
// This will be true in an optimal asynchronous implementation.
|
||||
// Conservative implementations which synchronize the hipMemcpyAsync will fail, ie if HIP_LAUNCH_BLOCKING=true
|
||||
HIPASSERT(1<<30 != A[NUM_STREAMS-1][0]-1);
|
||||
// This first check but relies on the kernel running for so long that the D2H async memcopy has
|
||||
// not started yet. This will be true in an optimal asynchronous implementation. Conservative
|
||||
// implementations which synchronize the hipMemcpyAsync will fail, ie if
|
||||
// HIP_LAUNCH_BLOCKING=true
|
||||
HIPASSERT(1 << 30 != A[NUM_STREAMS - 1][0] - 1);
|
||||
HIPCHECK(hipDeviceSynchronize());
|
||||
HIPASSERT(1<<30 == A[NUM_STREAMS-1][0]-1);
|
||||
HIPASSERT(1 << 30 == A[NUM_STREAMS - 1][0] - 1);
|
||||
passed();
|
||||
}
|
||||
|
||||
@@ -30,15 +30,14 @@ THE SOFTWARE.
|
||||
|
||||
#include "test_common.h"
|
||||
|
||||
int main()
|
||||
{
|
||||
int main() {
|
||||
int numDevices = 0;
|
||||
size_t totMem;
|
||||
hipDevice_t device;
|
||||
HIPCHECK(hipGetDeviceCount(&numDevices));
|
||||
for(int i=0;i<numDevices;i++){
|
||||
HIPCHECK(hipDeviceGet(&device,i));
|
||||
HIPCHECK(hipDeviceTotalMem(&totMem,device));
|
||||
for (int i = 0; i < numDevices; i++) {
|
||||
HIPCHECK(hipDeviceGet(&device, i));
|
||||
HIPCHECK(hipDeviceTotalMem(&totMem, device));
|
||||
HIPASSERT(totMem != 0);
|
||||
}
|
||||
passed();
|
||||
|
||||
@@ -30,12 +30,11 @@ THE SOFTWARE.
|
||||
|
||||
#include "test_common.h"
|
||||
|
||||
int main()
|
||||
{
|
||||
int main() {
|
||||
int numDevices = 0;
|
||||
int device;
|
||||
HIPCHECK(hipGetDeviceCount(&numDevices));
|
||||
for(int i=0;i<numDevices;i++){
|
||||
for (int i = 0; i < numDevices; i++) {
|
||||
HIPCHECK(hipSetDevice(i));
|
||||
HIPCHECK(hipGetDevice(&device));
|
||||
HIPASSERT(device == i);
|
||||
|
||||
@@ -33,17 +33,20 @@ THE SOFTWARE.
|
||||
|
||||
#include "test_common.h"
|
||||
|
||||
#define CHECK(error) \
|
||||
if (error != hipSuccess) { \
|
||||
fprintf(stderr, "error: '%s'(%d) at %s:%d\n", hipGetErrorString(error), error,__FILE__, __LINE__); \
|
||||
exit(EXIT_FAILURE);\
|
||||
#define CHECK(error) \
|
||||
if (error != hipSuccess) { \
|
||||
fprintf(stderr, "error: '%s'(%d) at %s:%d\n", hipGetErrorString(error), error, __FILE__, \
|
||||
__LINE__); \
|
||||
exit(EXIT_FAILURE); \
|
||||
}
|
||||
|
||||
hipError_t test_hipDeviceGetAttribute(int deviceId, hipDeviceAttribute_t attr, int expectedValue = -1)
|
||||
{
|
||||
hipError_t test_hipDeviceGetAttribute(int deviceId, hipDeviceAttribute_t attr,
|
||||
int expectedValue = -1) {
|
||||
int value = 0;
|
||||
std::cout << "Test hipDeviceGetAttribute attribute " << attr;
|
||||
if (expectedValue != -1) { std::cout << " expected value " << expectedValue; }
|
||||
if (expectedValue != -1) {
|
||||
std::cout << " expected value " << expectedValue;
|
||||
}
|
||||
hipError_t e = hipDeviceGetAttribute(&value, attr, deviceId);
|
||||
std::cout << " actual value " << value << std::endl;
|
||||
if ((expectedValue != -1) && value != expectedValue) {
|
||||
@@ -53,39 +56,57 @@ hipError_t test_hipDeviceGetAttribute(int deviceId, hipDeviceAttribute_t attr, i
|
||||
return hipSuccess;
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int main(int argc, char* argv[]) {
|
||||
int deviceId;
|
||||
CHECK (hipGetDevice(&deviceId));
|
||||
CHECK(hipGetDevice(&deviceId));
|
||||
hipDeviceProp_t props;
|
||||
CHECK(hipGetDeviceProperties(&props, deviceId));
|
||||
printf ("info: running on device #%d %s\n", deviceId, props.name);
|
||||
printf("info: running on device #%d %s\n", deviceId, props.name);
|
||||
|
||||
CHECK(test_hipDeviceGetAttribute(deviceId, hipDeviceAttributeMaxThreadsPerBlock, props.maxThreadsPerBlock));
|
||||
CHECK(test_hipDeviceGetAttribute(deviceId, hipDeviceAttributeMaxBlockDimX, props.maxThreadsDim[0]));
|
||||
CHECK(test_hipDeviceGetAttribute(deviceId, hipDeviceAttributeMaxBlockDimY, props.maxThreadsDim[1]));
|
||||
CHECK(test_hipDeviceGetAttribute(deviceId, hipDeviceAttributeMaxBlockDimZ, props.maxThreadsDim[2]));
|
||||
CHECK(test_hipDeviceGetAttribute(deviceId, hipDeviceAttributeMaxGridDimX, props.maxGridSize[0]));
|
||||
CHECK(test_hipDeviceGetAttribute(deviceId, hipDeviceAttributeMaxGridDimY, props.maxGridSize[1]));
|
||||
CHECK(test_hipDeviceGetAttribute(deviceId, hipDeviceAttributeMaxGridDimZ, props.maxGridSize[2]));
|
||||
CHECK(test_hipDeviceGetAttribute(deviceId, hipDeviceAttributeMaxSharedMemoryPerBlock, props.sharedMemPerBlock));
|
||||
CHECK(test_hipDeviceGetAttribute(deviceId, hipDeviceAttributeTotalConstantMemory, props.totalConstMem));
|
||||
CHECK(test_hipDeviceGetAttribute(deviceId, hipDeviceAttributeMaxThreadsPerBlock,
|
||||
props.maxThreadsPerBlock));
|
||||
CHECK(test_hipDeviceGetAttribute(deviceId, hipDeviceAttributeMaxBlockDimX,
|
||||
props.maxThreadsDim[0]));
|
||||
CHECK(test_hipDeviceGetAttribute(deviceId, hipDeviceAttributeMaxBlockDimY,
|
||||
props.maxThreadsDim[1]));
|
||||
CHECK(test_hipDeviceGetAttribute(deviceId, hipDeviceAttributeMaxBlockDimZ,
|
||||
props.maxThreadsDim[2]));
|
||||
CHECK(
|
||||
test_hipDeviceGetAttribute(deviceId, hipDeviceAttributeMaxGridDimX, props.maxGridSize[0]));
|
||||
CHECK(
|
||||
test_hipDeviceGetAttribute(deviceId, hipDeviceAttributeMaxGridDimY, props.maxGridSize[1]));
|
||||
CHECK(
|
||||
test_hipDeviceGetAttribute(deviceId, hipDeviceAttributeMaxGridDimZ, props.maxGridSize[2]));
|
||||
CHECK(test_hipDeviceGetAttribute(deviceId, hipDeviceAttributeMaxSharedMemoryPerBlock,
|
||||
props.sharedMemPerBlock));
|
||||
CHECK(test_hipDeviceGetAttribute(deviceId, hipDeviceAttributeTotalConstantMemory,
|
||||
props.totalConstMem));
|
||||
CHECK(test_hipDeviceGetAttribute(deviceId, hipDeviceAttributeWarpSize, props.warpSize));
|
||||
CHECK(test_hipDeviceGetAttribute(deviceId, hipDeviceAttributeMaxRegistersPerBlock, props.regsPerBlock));
|
||||
CHECK(test_hipDeviceGetAttribute(deviceId, hipDeviceAttributeMaxRegistersPerBlock,
|
||||
props.regsPerBlock));
|
||||
CHECK(test_hipDeviceGetAttribute(deviceId, hipDeviceAttributeClockRate, props.clockRate));
|
||||
CHECK(test_hipDeviceGetAttribute(deviceId, hipDeviceAttributeMemoryClockRate, props.memoryClockRate));
|
||||
CHECK(test_hipDeviceGetAttribute(deviceId, hipDeviceAttributeMemoryBusWidth, props.memoryBusWidth));
|
||||
CHECK(test_hipDeviceGetAttribute(deviceId, hipDeviceAttributeMultiprocessorCount, props.multiProcessorCount));
|
||||
CHECK(test_hipDeviceGetAttribute(deviceId, hipDeviceAttributeIsMultiGpuBoard, props.isMultiGpuBoard));//
|
||||
CHECK(test_hipDeviceGetAttribute(deviceId, hipDeviceAttributeMemoryClockRate,
|
||||
props.memoryClockRate));
|
||||
CHECK(test_hipDeviceGetAttribute(deviceId, hipDeviceAttributeMemoryBusWidth,
|
||||
props.memoryBusWidth));
|
||||
CHECK(test_hipDeviceGetAttribute(deviceId, hipDeviceAttributeMultiprocessorCount,
|
||||
props.multiProcessorCount));
|
||||
CHECK(test_hipDeviceGetAttribute(deviceId, hipDeviceAttributeIsMultiGpuBoard,
|
||||
props.isMultiGpuBoard)); //
|
||||
CHECK(test_hipDeviceGetAttribute(deviceId, hipDeviceAttributeComputeMode, props.computeMode));
|
||||
CHECK(test_hipDeviceGetAttribute(deviceId, hipDeviceAttributeL2CacheSize, props.l2CacheSize));
|
||||
CHECK(test_hipDeviceGetAttribute(deviceId, hipDeviceAttributeMaxThreadsPerMultiProcessor, props.maxThreadsPerMultiProcessor));
|
||||
CHECK(test_hipDeviceGetAttribute(deviceId, hipDeviceAttributeComputeCapabilityMajor, props.major));
|
||||
CHECK(test_hipDeviceGetAttribute(deviceId, hipDeviceAttributeComputeCapabilityMinor, props.minor));//
|
||||
CHECK(test_hipDeviceGetAttribute(deviceId, hipDeviceAttributeConcurrentKernels, props.concurrentKernels));
|
||||
CHECK(test_hipDeviceGetAttribute(deviceId, hipDeviceAttributeMaxThreadsPerMultiProcessor,
|
||||
props.maxThreadsPerMultiProcessor));
|
||||
CHECK(test_hipDeviceGetAttribute(deviceId, hipDeviceAttributeComputeCapabilityMajor,
|
||||
props.major));
|
||||
CHECK(test_hipDeviceGetAttribute(deviceId, hipDeviceAttributeComputeCapabilityMinor,
|
||||
props.minor)); //
|
||||
CHECK(test_hipDeviceGetAttribute(deviceId, hipDeviceAttributeConcurrentKernels,
|
||||
props.concurrentKernels));
|
||||
CHECK(test_hipDeviceGetAttribute(deviceId, hipDeviceAttributePciBusId, props.pciBusID));
|
||||
CHECK(test_hipDeviceGetAttribute(deviceId, hipDeviceAttributePciDeviceId, props.pciDeviceID));//
|
||||
CHECK(test_hipDeviceGetAttribute(deviceId, hipDeviceAttributeMaxSharedMemoryPerMultiprocessor, props.maxSharedMemoryPerMultiProcessor));
|
||||
CHECK(
|
||||
test_hipDeviceGetAttribute(deviceId, hipDeviceAttributePciDeviceId, props.pciDeviceID)); //
|
||||
CHECK(test_hipDeviceGetAttribute(deviceId, hipDeviceAttributeMaxSharedMemoryPerMultiprocessor,
|
||||
props.maxSharedMemoryPerMultiProcessor));
|
||||
passed();
|
||||
|
||||
};
|
||||
|
||||
@@ -20,7 +20,8 @@ THE SOFTWARE.
|
||||
/*
|
||||
* Conformance test for checking functionality of
|
||||
* hipError_t hipRuntimeGetVersion(int* runtimeVersion);
|
||||
* On HIP/HCC path this function returns HIP runtime patch version(a 5 digit code) however on HIP/NVCC path this function return CUDA runtime version.
|
||||
* On HIP/HCC path this function returns HIP runtime patch version(a 5 digit code) however on
|
||||
* HIP/NVCC path this function return CUDA runtime version.
|
||||
*/
|
||||
|
||||
/* HIT_START
|
||||
@@ -31,8 +32,7 @@ THE SOFTWARE.
|
||||
|
||||
#include "test_common.h"
|
||||
|
||||
int main()
|
||||
{
|
||||
int main() {
|
||||
int runtimeVersion;
|
||||
HIPCHECK(hipRuntimeGetVersion(&runtimeVersion));
|
||||
passed();
|
||||
|
||||
@@ -23,14 +23,13 @@ THE SOFTWARE.
|
||||
* HIT_END
|
||||
*/
|
||||
|
||||
#include<hip/hip_runtime_api.h>
|
||||
#include<iostream>
|
||||
#include"test_common.h"
|
||||
#include <hip/hip_runtime_api.h>
|
||||
#include <iostream>
|
||||
#include "test_common.h"
|
||||
|
||||
int main(){
|
||||
hipFuncCache_t cacheConfig;
|
||||
void *func;
|
||||
hipFuncSetCacheConfig(func, cacheConfig);
|
||||
passed();
|
||||
int main() {
|
||||
hipFuncCache_t cacheConfig;
|
||||
void* func;
|
||||
hipFuncSetCacheConfig(func, cacheConfig);
|
||||
passed();
|
||||
}
|
||||
|
||||
|
||||
@@ -25,10 +25,10 @@ THE SOFTWARE.
|
||||
|
||||
#include "test_common.h"
|
||||
|
||||
int main(){
|
||||
int main() {
|
||||
int numDevices = 0;
|
||||
HIPCHECK(hipGetDeviceCount(&numDevices));
|
||||
for(int i=0;i<numDevices;i++){
|
||||
for (int i = 0; i < numDevices; i++) {
|
||||
HIPCHECK(hipSetDevice(i));
|
||||
}
|
||||
HIPASSERT(hipErrorInvalidDevice == hipSetDevice(numDevices));
|
||||
|
||||
@@ -25,27 +25,24 @@ THE SOFTWARE.
|
||||
|
||||
#include "test_common.h"
|
||||
|
||||
int main()
|
||||
{
|
||||
int main() {
|
||||
unsigned flag = 0;
|
||||
HIPCHECK(hipDeviceReset());
|
||||
|
||||
int deviceCount = 0;
|
||||
HIPCHECK(hipGetDeviceCount(&deviceCount));
|
||||
|
||||
for(int j=0;j<deviceCount;j++){
|
||||
|
||||
for (int j = 0; j < deviceCount; j++) {
|
||||
HIPCHECK(hipSetDevice(j));
|
||||
|
||||
for(int i=0;i<4;i++){
|
||||
for (int i = 0; i < 4; i++) {
|
||||
flag = 1 << i;
|
||||
printf ("Flag=%x\n", flag);
|
||||
printf("Flag=%x\n", flag);
|
||||
HIPCHECK(hipSetDeviceFlags(flag));
|
||||
//HIPCHECK_API(hipSetDeviceFlags(flag), hipErrorInvalidValue);
|
||||
// HIPCHECK_API(hipSetDeviceFlags(flag), hipErrorInvalidValue);
|
||||
}
|
||||
|
||||
flag = 0;
|
||||
|
||||
}
|
||||
|
||||
passed();
|
||||
|
||||
@@ -30,9 +30,7 @@ THE SOFTWARE.
|
||||
|
||||
#include "test_common.h"
|
||||
|
||||
int main()
|
||||
{
|
||||
hipSetDevice(-1);
|
||||
if(hipPeekAtLastError() != hipSuccess)
|
||||
passed();
|
||||
int main() {
|
||||
hipSetDevice(-1);
|
||||
if (hipPeekAtLastError() != hipSuccess) passed();
|
||||
}
|
||||
|
||||
@@ -20,8 +20,8 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
// Test hipEventRecord serialization behavior.
|
||||
// Through manual inspection of the reported timestamps, can determine if recording a NULL event forces synchronization :
|
||||
// set
|
||||
// Through manual inspection of the reported timestamps, can determine if recording a NULL event
|
||||
// forces synchronization : set
|
||||
|
||||
/* HIT_START
|
||||
* BUILD: %t %s ../../test_common.cpp
|
||||
@@ -32,82 +32,70 @@ THE SOFTWARE.
|
||||
#include "hip/hip_runtime.h"
|
||||
#include "test_common.h"
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int main(int argc, char* argv[]) {
|
||||
HipTest::parseStandardArguments(argc, argv, true);
|
||||
|
||||
unsigned blocks = (N+threadsPerBlock-1)/threadsPerBlock;
|
||||
if (blocks > 1024)
|
||||
blocks = 1024;
|
||||
if (blocks ==0 )
|
||||
blocks = 1;
|
||||
unsigned blocks = (N + threadsPerBlock - 1) / threadsPerBlock;
|
||||
if (blocks > 1024) blocks = 1024;
|
||||
if (blocks == 0) blocks = 1;
|
||||
|
||||
printf ("N=%zu (A+B+C= %6.1f MB total) blocks=%u threadsPerBlock=%u iterations=%d\n", N, ((double)3*N*sizeof(float))/1024/1024, blocks, threadsPerBlock, iterations);
|
||||
printf ("iterations=%d\n", iterations);
|
||||
printf("N=%zu (A+B+C= %6.1f MB total) blocks=%u threadsPerBlock=%u iterations=%d\n", N,
|
||||
((double)3 * N * sizeof(float)) / 1024 / 1024, blocks, threadsPerBlock, iterations);
|
||||
printf("iterations=%d\n", iterations);
|
||||
|
||||
size_t Nbytes = N*sizeof(float);
|
||||
size_t Nbytes = N * sizeof(float);
|
||||
|
||||
float * A_h, *B_h, *C_h;
|
||||
float * A_d, *B_d, *C_d;
|
||||
HipTest::initArrays (&A_d, &B_d, &C_d, &A_h, &B_h, &C_h, N);
|
||||
float *A_h, *B_h, *C_h;
|
||||
float *A_d, *B_d, *C_d;
|
||||
HipTest::initArrays(&A_d, &B_d, &C_d, &A_h, &B_h, &C_h, N);
|
||||
|
||||
hipEvent_t start, stop;
|
||||
|
||||
// NULL stream check:
|
||||
HIPCHECK (hipEventCreate(&start));
|
||||
HIPCHECK (hipEventCreate(&stop));
|
||||
HIPCHECK(hipEventCreate(&start));
|
||||
HIPCHECK(hipEventCreate(&stop));
|
||||
|
||||
|
||||
HIPCHECK ( hipMemcpy(A_d, A_h, Nbytes, hipMemcpyHostToDevice));
|
||||
HIPCHECK ( hipMemcpy(B_d, B_h, Nbytes, hipMemcpyHostToDevice));
|
||||
HIPCHECK(hipMemcpy(A_d, A_h, Nbytes, hipMemcpyHostToDevice));
|
||||
HIPCHECK(hipMemcpy(B_d, B_h, Nbytes, hipMemcpyHostToDevice));
|
||||
|
||||
|
||||
for (int i=0; i<iterations; i++) {
|
||||
for (int i = 0; i < iterations; i++) {
|
||||
//--- START TIMED REGION
|
||||
long long hostStart = HipTest::get_time();
|
||||
// Record the start event
|
||||
HIPCHECK(hipEventRecord(start, NULL));
|
||||
|
||||
//--- START TIMED REGION
|
||||
long long hostStart = HipTest::get_time();
|
||||
// Record the start event
|
||||
HIPCHECK (hipEventRecord(start, NULL));
|
||||
|
||||
hipLaunchKernel(
|
||||
HipTest::vectorADD,
|
||||
dim3(blocks),
|
||||
dim3(threadsPerBlock),
|
||||
0,
|
||||
0,
|
||||
static_cast<const float*>(A_d),
|
||||
static_cast<const float*>(B_d),
|
||||
C_d,
|
||||
N);
|
||||
hipLaunchKernel(HipTest::vectorADD, dim3(blocks), dim3(threadsPerBlock), 0, 0,
|
||||
static_cast<const float*>(A_d), static_cast<const float*>(B_d), C_d, N);
|
||||
|
||||
|
||||
HIPCHECK (hipEventRecord(stop, NULL));
|
||||
HIPCHECK (hipEventSynchronize(stop) );
|
||||
long long hostStop = HipTest::get_time();
|
||||
//--- STOP TIMED REGION
|
||||
HIPCHECK(hipEventRecord(stop, NULL));
|
||||
HIPCHECK(hipEventSynchronize(stop));
|
||||
long long hostStop = HipTest::get_time();
|
||||
//--- STOP TIMED REGION
|
||||
|
||||
|
||||
float eventMs = 1.0f;
|
||||
HIPCHECK (hipEventElapsedTime(&eventMs, start, stop));
|
||||
float hostMs = HipTest::elapsed_time(hostStart, hostStop);
|
||||
float eventMs = 1.0f;
|
||||
HIPCHECK(hipEventElapsedTime(&eventMs, start, stop));
|
||||
float hostMs = HipTest::elapsed_time(hostStart, hostStop);
|
||||
|
||||
printf ("host_time (gettimeofday) =%6.3fms\n", hostMs);
|
||||
printf ("kernel_time (hipEventElapsedTime) =%6.3fms\n", eventMs);
|
||||
printf ("\n");
|
||||
printf("host_time (gettimeofday) =%6.3fms\n", hostMs);
|
||||
printf("kernel_time (hipEventElapsedTime) =%6.3fms\n", eventMs);
|
||||
printf("\n");
|
||||
|
||||
// Make sure timer is timing something...
|
||||
HIPASSERT(eventMs > 0.0f);
|
||||
}
|
||||
// Make sure timer is timing something...
|
||||
HIPASSERT(eventMs > 0.0f);
|
||||
}
|
||||
|
||||
|
||||
HIPCHECK (hipMemcpy(C_h, C_d, Nbytes, hipMemcpyDeviceToHost));
|
||||
HIPCHECK(hipMemcpy(C_h, C_d, Nbytes, hipMemcpyDeviceToHost));
|
||||
|
||||
|
||||
printf ("check:\n");
|
||||
printf("check:\n");
|
||||
|
||||
HipTest::checkVectorADD(A_h, B_h, C_h, N, true);
|
||||
|
||||
|
||||
|
||||
passed();
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ enum SyncMode {
|
||||
};
|
||||
|
||||
|
||||
const char *syncModeString(int syncMode) {
|
||||
const char* syncModeString(int syncMode) {
|
||||
switch (syncMode) {
|
||||
case syncNone:
|
||||
return "syncNone";
|
||||
@@ -47,24 +47,24 @@ const char *syncModeString(int syncMode) {
|
||||
};
|
||||
|
||||
|
||||
void test(unsigned testMask, int *C_d, int *C_h, int64_t numElements, hipStream_t stream, int waitStart, SyncMode syncMode)
|
||||
{
|
||||
void test(unsigned testMask, int* C_d, int* C_h, int64_t numElements, hipStream_t stream,
|
||||
int waitStart, SyncMode syncMode) {
|
||||
if (!(testMask & p_tests)) {
|
||||
return;
|
||||
}
|
||||
printf ("\ntest 0x%3x: stream=%p waitStart=%d syncMode=%s\n",
|
||||
testMask, stream, waitStart, syncModeString(syncMode));
|
||||
printf("\ntest 0x%3x: stream=%p waitStart=%d syncMode=%s\n", testMask, stream, waitStart,
|
||||
syncModeString(syncMode));
|
||||
|
||||
size_t sizeBytes = numElements * sizeof(int);
|
||||
|
||||
int count =100;
|
||||
int count = 100;
|
||||
int init0 = 0;
|
||||
HIPCHECK(hipMemset(C_d, init0, sizeBytes));
|
||||
for (int i=0; i<numElements; i++) {
|
||||
C_h[i] = -1; // initialize
|
||||
for (int i = 0; i < numElements; i++) {
|
||||
C_h[i] = -1; // initialize
|
||||
}
|
||||
|
||||
hipEvent_t neverCreated=0, neverRecorded, timingDisabled;
|
||||
hipEvent_t neverCreated = 0, neverRecorded, timingDisabled;
|
||||
HIPCHECK(hipEventCreate(&neverRecorded));
|
||||
HIPCHECK(hipEventCreateWithFlags(&timingDisabled, hipEventDisableTiming));
|
||||
|
||||
@@ -77,16 +77,8 @@ void test(unsigned testMask, int *C_d, int *C_h, int64_t numElements, hipStream_
|
||||
HIPCHECK(hipEventRecord(timingDisabled, stream));
|
||||
// sandwhich a kernel:
|
||||
HIPCHECK(hipEventRecord(start, stream));
|
||||
hipLaunchKernelGGL(
|
||||
HipTest::addCountReverse,
|
||||
dim3(blocks),
|
||||
dim3(threadsPerBlock),
|
||||
0,
|
||||
stream,
|
||||
static_cast<const int*>(C_d),
|
||||
C_h,
|
||||
numElements,
|
||||
count);
|
||||
hipLaunchKernelGGL(HipTest::addCountReverse, dim3(blocks), dim3(threadsPerBlock), 0, stream,
|
||||
static_cast<const int*>(C_d), C_h, numElements, count);
|
||||
HIPCHECK(hipEventRecord(stop, stream));
|
||||
|
||||
|
||||
@@ -116,32 +108,27 @@ void test(unsigned testMask, int *C_d, int *C_h, int64_t numElements, hipStream_
|
||||
float t;
|
||||
|
||||
hipError_t e = hipEventElapsedTime(&t, start, start);
|
||||
if ((e != hipSuccess) && (e != hipErrorNotReady)) {
|
||||
failed ("start event not in expected state, was %d=%s\n", e, hipGetErrorName(e));
|
||||
if ((e != hipSuccess) && (e != hipErrorNotReady)) {
|
||||
failed("start event not in expected state, was %d=%s\n", e, hipGetErrorName(e));
|
||||
}
|
||||
|
||||
if (e == hipSuccess)
|
||||
assert (t==0.0f);
|
||||
if (e == hipSuccess) assert(t == 0.0f);
|
||||
|
||||
|
||||
// stop usually ready unless we skipped the synchronization (syncNone)
|
||||
HIPCHECK_API(hipEventElapsedTime(&t, stop, stop), expectedStopError);
|
||||
if (e == hipSuccess)
|
||||
assert (t==0.0f);
|
||||
if (e == hipSuccess) assert(t == 0.0f);
|
||||
|
||||
|
||||
e = hipEventElapsedTime(&t, start, stop);
|
||||
HIPCHECK_API(e, expectedStopError);
|
||||
if (expectedStopError == hipSuccess)
|
||||
assert (t>0.0f);
|
||||
printf ("time=%6.2f error=%s\n", t, hipGetErrorName(e));
|
||||
if (expectedStopError == hipSuccess) assert(t > 0.0f);
|
||||
printf("time=%6.2f error=%s\n", t, hipGetErrorName(e));
|
||||
|
||||
e = hipEventElapsedTime(&t, stop, start);
|
||||
HIPCHECK_API(e, expectedStopError);
|
||||
if (expectedStopError == hipSuccess)
|
||||
assert (t<0.0f);
|
||||
printf ("negtime=%6.2f error=%s\n", t, hipGetErrorName(e));
|
||||
|
||||
if (expectedStopError == hipSuccess) assert(t < 0.0f);
|
||||
printf("negtime=%6.2f error=%s\n", t, hipGetErrorName(e));
|
||||
|
||||
|
||||
{
|
||||
@@ -150,10 +137,10 @@ void test(unsigned testMask, int *C_d, int *C_h, int64_t numElements, hipStream_
|
||||
HIPCHECK_API(hipEventElapsedTime(&t, start, timingDisabled), hipErrorInvalidResourceHandle);
|
||||
|
||||
HIPCHECK_API(hipEventElapsedTime(&t, neverCreated, stop), hipErrorInvalidResourceHandle);
|
||||
HIPCHECK_API(hipEventElapsedTime(&t, start, neverCreated), hipErrorInvalidResourceHandle);
|
||||
HIPCHECK_API(hipEventElapsedTime(&t, start, neverCreated), hipErrorInvalidResourceHandle);
|
||||
|
||||
HIPCHECK_API(hipEventElapsedTime(&t, neverRecorded, stop), hipErrorInvalidResourceHandle);
|
||||
HIPCHECK_API(hipEventElapsedTime(&t, start, neverRecorded), hipErrorInvalidResourceHandle);
|
||||
HIPCHECK_API(hipEventElapsedTime(&t, start, neverRecorded), hipErrorInvalidResourceHandle);
|
||||
}
|
||||
|
||||
HIPCHECK(hipEventDestroy(start));
|
||||
@@ -162,16 +149,15 @@ void test(unsigned testMask, int *C_d, int *C_h, int64_t numElements, hipStream_
|
||||
// Clear out everything:
|
||||
HIPCHECK(hipDeviceSynchronize());
|
||||
|
||||
printf ("test: OK \n");
|
||||
printf("test: OK \n");
|
||||
}
|
||||
|
||||
|
||||
|
||||
void runTests(int64_t numElements)
|
||||
{
|
||||
void runTests(int64_t numElements) {
|
||||
size_t sizeBytes = numElements * sizeof(int);
|
||||
|
||||
printf ("test: starting sequence with sizeBytes=%zu bytes, %6.2f MB\n", sizeBytes, sizeBytes/1024.0/1024.0);
|
||||
printf("test: starting sequence with sizeBytes=%zu bytes, %6.2f MB\n", sizeBytes,
|
||||
sizeBytes / 1024.0 / 1024.0);
|
||||
|
||||
|
||||
int *C_h, *C_d;
|
||||
@@ -181,15 +167,15 @@ void runTests(int64_t numElements)
|
||||
hipStream_t stream;
|
||||
HIPCHECK(hipStreamCreateWithFlags(&stream, 0x0));
|
||||
|
||||
//for (int waitStart=0; waitStart<2; waitStart++) {
|
||||
for (int waitStart=1; waitStart>=0; waitStart--) {
|
||||
unsigned W = waitStart ? 0x1000:0;
|
||||
test (W | 0x01, C_d, C_h, numElements, 0 , waitStart, syncNone);
|
||||
test (W | 0x02, C_d, C_h, numElements, stream, waitStart, syncNone);
|
||||
test (W | 0x04, C_d, C_h, numElements, 0 , waitStart, syncStream);
|
||||
test (W | 0x08, C_d, C_h, numElements, stream, waitStart, syncStream);
|
||||
test (W | 0x10, C_d, C_h, numElements, 0, waitStart, syncStopEvent);
|
||||
test (W | 0x20, C_d, C_h, numElements, stream, waitStart, syncStopEvent);
|
||||
// for (int waitStart=0; waitStart<2; waitStart++) {
|
||||
for (int waitStart = 1; waitStart >= 0; waitStart--) {
|
||||
unsigned W = waitStart ? 0x1000 : 0;
|
||||
test(W | 0x01, C_d, C_h, numElements, 0, waitStart, syncNone);
|
||||
test(W | 0x02, C_d, C_h, numElements, stream, waitStart, syncNone);
|
||||
test(W | 0x04, C_d, C_h, numElements, 0, waitStart, syncStream);
|
||||
test(W | 0x08, C_d, C_h, numElements, stream, waitStart, syncStream);
|
||||
test(W | 0x10, C_d, C_h, numElements, 0, waitStart, syncStopEvent);
|
||||
test(W | 0x20, C_d, C_h, numElements, stream, waitStart, syncStopEvent);
|
||||
}
|
||||
|
||||
|
||||
@@ -199,8 +185,7 @@ void runTests(int64_t numElements)
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int main(int argc, char* argv[]) {
|
||||
HipTest::parseStandardArguments(argc, argv, true /*failOnUndefinedArg*/);
|
||||
|
||||
runTests(80000000);
|
||||
|
||||
@@ -29,209 +29,213 @@ THE SOFTWARE.
|
||||
#include "hip/hip_runtime.h"
|
||||
#include "test_common.h"
|
||||
|
||||
void printSep()
|
||||
{
|
||||
printf ("======================================================================================\n");
|
||||
void printSep() {
|
||||
printf(
|
||||
"======================================================================================\n");
|
||||
}
|
||||
|
||||
|
||||
//---
|
||||
// Test copies of a matrix numW by numH
|
||||
// The subroutine allocates memory , copies to device, runs a vector add kernel, copies back, and checks the result.
|
||||
// The subroutine allocates memory , copies to device, runs a vector add kernel, copies back, and
|
||||
// checks the result.
|
||||
//
|
||||
// IN: numW: number of elements in the 1st dimension used for allocation
|
||||
// IN: numH: number of elements in the 2nd dimension used for allocation
|
||||
// IN: usePinnedHost : If true, allocate host with hipHostMalloc and is pinned ; else allocate host memory with malloc.
|
||||
// IN: usePinnedHost : If true, allocate host with hipHostMalloc and is pinned ; else allocate host
|
||||
// memory with malloc.
|
||||
//
|
||||
template <typename T>
|
||||
void memcpy2Dtest(size_t numW, size_t numH, bool usePinnedHost)
|
||||
{
|
||||
void memcpy2Dtest(size_t numW, size_t numH, bool usePinnedHost) {
|
||||
size_t width = numW * sizeof(T);
|
||||
size_t sizeElements = width * numH;
|
||||
|
||||
size_t width = numW * sizeof(T);
|
||||
size_t sizeElements = width * numH;
|
||||
printf("memcpy2Dtest: %s<%s> size=%lu (%6.2fMB) W: %d, H:%d, usePinnedHost: %d\n", __func__,
|
||||
TYPENAME(T), sizeElements, sizeElements / 1024.0 / 1024.0, (int)numW, (int)numH,
|
||||
usePinnedHost);
|
||||
|
||||
printf("memcpy2Dtest: %s<%s> size=%lu (%6.2fMB) W: %d, H:%d, usePinnedHost: %d\n",
|
||||
__func__,
|
||||
TYPENAME(T),
|
||||
sizeElements, sizeElements/1024.0/1024.0,
|
||||
(int)numW, (int)numH, usePinnedHost);
|
||||
T *A_d, *B_d, *C_d;
|
||||
T *A_h, *B_h, *C_h;
|
||||
|
||||
T *A_d, *B_d, *C_d;
|
||||
T *A_h, *B_h, *C_h;
|
||||
size_t pitch_A, pitch_B, pitch_C;
|
||||
|
||||
size_t pitch_A, pitch_B, pitch_C;
|
||||
hipChannelFormatDesc desc = hipCreateChannelDesc<T>();
|
||||
HipTest::initArrays2DPitch(&A_d, &B_d, &C_d, &pitch_A, &pitch_B, &pitch_C, numW, numH);
|
||||
HipTest::initArraysForHost(&A_h, &B_h, &C_h, numW * numH, usePinnedHost);
|
||||
unsigned blocks = HipTest::setNumBlocks(blocksPerCU, threadsPerBlock, numW * numH);
|
||||
|
||||
hipChannelFormatDesc desc = hipCreateChannelDesc<T>();
|
||||
HipTest::initArrays2DPitch(&A_d, &B_d, &C_d, &pitch_A, &pitch_B, &pitch_C, numW, numH);
|
||||
HipTest::initArraysForHost(&A_h, &B_h, &C_h, numW*numH, usePinnedHost);
|
||||
unsigned blocks = HipTest::setNumBlocks(blocksPerCU, threadsPerBlock, numW*numH);
|
||||
HIPCHECK(hipMemcpy2D(A_d, pitch_A, A_h, width, width, numH, hipMemcpyHostToDevice));
|
||||
HIPCHECK(hipMemcpy2D(B_d, pitch_B, B_h, width, width, numH, hipMemcpyHostToDevice));
|
||||
|
||||
HIPCHECK (hipMemcpy2D (A_d, pitch_A, A_h, width, width, numH, hipMemcpyHostToDevice) );
|
||||
HIPCHECK (hipMemcpy2D (B_d, pitch_B, B_h, width, width, numH, hipMemcpyHostToDevice) );
|
||||
hipLaunchKernel(HipTest::vectorADD, dim3(blocks), dim3(threadsPerBlock), 0, 0, A_d, B_d, C_d,
|
||||
(pitch_C / sizeof(T)) * numH);
|
||||
|
||||
hipLaunchKernel(HipTest::vectorADD, dim3(blocks), dim3(threadsPerBlock), 0, 0, A_d, B_d, C_d, (pitch_C/sizeof(T))*numH);
|
||||
HIPCHECK(hipMemcpy2D(C_h, width, C_d, pitch_C, width, numH, hipMemcpyDeviceToHost));
|
||||
|
||||
HIPCHECK (hipMemcpy2D (C_h, width, C_d, pitch_C, width, numH, hipMemcpyDeviceToHost) );
|
||||
HIPCHECK(hipDeviceSynchronize());
|
||||
HipTest::checkVectorADD(A_h, B_h, C_h, numW * numH);
|
||||
|
||||
HIPCHECK ( hipDeviceSynchronize() );
|
||||
HipTest::checkVectorADD(A_h, B_h, C_h, numW*numH);
|
||||
HipTest::freeArrays(A_d, B_d, C_d, A_h, B_h, C_h, usePinnedHost);
|
||||
|
||||
HipTest::freeArrays (A_d, B_d, C_d, A_h, B_h, C_h, usePinnedHost);
|
||||
|
||||
printf (" %s success\n", __func__);
|
||||
printf(" %s success\n", __func__);
|
||||
}
|
||||
|
||||
//---
|
||||
// Test copies of a matrix numW by numH into a hipArray data structure
|
||||
// The subroutine allocates memory , copies to device, runs a vector add kernel, copies back, and checks the result.
|
||||
// The subroutine allocates memory , copies to device, runs a vector add kernel, copies back, and
|
||||
// checks the result.
|
||||
//
|
||||
// IN: numW: number of elements in the 1st dimension used for allocation
|
||||
// IN: numH: number of elements in the 2nd dimension used for allocation. If this is 1, then the 1-dimensional copy API
|
||||
// IN: numH: number of elements in the 2nd dimension used for allocation. If this is 1, then the
|
||||
// 1-dimensional copy API
|
||||
// would be used
|
||||
// IN: usePinnedHost : If true, allocate host with hipHostMalloc and is pinned ; else allocate host memory with malloc.
|
||||
// IN: usePitch: If true, pads additional memory. This is only valid in the 2-dimensional case
|
||||
// IN: usePinnedHost : If true, allocate host with hipHostMalloc and is pinned ; else allocate host
|
||||
// memory with malloc. IN: usePitch: If true, pads additional memory. This is only valid in the
|
||||
// 2-dimensional case
|
||||
//
|
||||
template <typename T>
|
||||
void memcpyArraytest(size_t numW, size_t numH, bool usePinnedHost, bool usePitch=false)
|
||||
{
|
||||
void memcpyArraytest(size_t numW, size_t numH, bool usePinnedHost, bool usePitch = false) {
|
||||
size_t width = numW * sizeof(T);
|
||||
size_t sizeElements = width * numH;
|
||||
|
||||
size_t width = numW * sizeof(T);
|
||||
size_t sizeElements = width * numH;
|
||||
printf(
|
||||
"memcpyArraytest: %s<%s> size=%lu (%6.2fMB) W: %d, H: %d, usePinnedHost: %d, usePitch: "
|
||||
"%d\n",
|
||||
__func__, TYPENAME(T), sizeElements, sizeElements / 1024.0 / 1024.0, (int)numW, (int)numH,
|
||||
usePinnedHost, usePitch);
|
||||
|
||||
printf("memcpyArraytest: %s<%s> size=%lu (%6.2fMB) W: %d, H: %d, usePinnedHost: %d, usePitch: %d\n",
|
||||
__func__,
|
||||
TYPENAME(T),
|
||||
sizeElements, sizeElements/1024.0/1024.0,
|
||||
(int)numW, (int)numH, usePinnedHost, usePitch);
|
||||
hipArray *A_d, *B_d, *C_d;
|
||||
T *A_h, *B_h, *C_h;
|
||||
|
||||
hipArray *A_d, *B_d, *C_d;
|
||||
T *A_h, *B_h, *C_h;
|
||||
// 1D
|
||||
if ((numW >= 1) && (numH == 1)) {
|
||||
hipChannelFormatDesc desc = hipCreateChannelDesc<T>();
|
||||
HipTest::initHIPArrays(&A_d, &B_d, &C_d, &desc, numW, 1, 0);
|
||||
HipTest::initArraysForHost(&A_h, &B_h, &C_h, numW * numH, usePinnedHost);
|
||||
unsigned blocks = HipTest::setNumBlocks(blocksPerCU, threadsPerBlock, numW * numH);
|
||||
|
||||
// 1D
|
||||
if ((numW >= 1) && (numH == 1)) {
|
||||
hipChannelFormatDesc desc = hipCreateChannelDesc<T>();
|
||||
HipTest::initHIPArrays(&A_d, &B_d, &C_d, &desc, numW, 1, 0);
|
||||
HipTest::initArraysForHost(&A_h, &B_h, &C_h, numW*numH, usePinnedHost);
|
||||
unsigned blocks = HipTest::setNumBlocks(blocksPerCU, threadsPerBlock, numW*numH);
|
||||
HIPCHECK(hipMemcpyToArray(A_d, 0, 0, (void*)A_h, width, hipMemcpyHostToDevice));
|
||||
HIPCHECK(hipMemcpyToArray(B_d, 0, 0, (void*)B_h, width, hipMemcpyHostToDevice));
|
||||
|
||||
HIPCHECK (hipMemcpyToArray (A_d, 0, 0, (void *)A_h, width, hipMemcpyHostToDevice) );
|
||||
HIPCHECK (hipMemcpyToArray (B_d, 0, 0, (void *)B_h, width, hipMemcpyHostToDevice) );
|
||||
hipLaunchKernel(HipTest::vectorADD, dim3(blocks), dim3(threadsPerBlock), 0, 0,
|
||||
(T*)A_d->data, (T*)B_d->data, (T*)C_d->data, numW);
|
||||
|
||||
hipLaunchKernel(HipTest::vectorADD, dim3(blocks), dim3(threadsPerBlock), 0, 0, (T*)A_d->data, (T*)B_d->data, (T*)C_d->data, numW);
|
||||
HIPCHECK(hipMemcpy(C_h, C_d->data, width, hipMemcpyDeviceToHost));
|
||||
|
||||
HIPCHECK (hipMemcpy (C_h, C_d->data, width, hipMemcpyDeviceToHost) );
|
||||
HIPCHECK(hipDeviceSynchronize());
|
||||
HipTest::checkVectorADD(A_h, B_h, C_h, numW);
|
||||
|
||||
HIPCHECK ( hipDeviceSynchronize() );
|
||||
HipTest::checkVectorADD(A_h, B_h, C_h, numW);
|
||||
|
||||
}
|
||||
// 2D
|
||||
else if ((numW >= 1) && (numH >= 1)) {
|
||||
|
||||
|
||||
hipChannelFormatDesc desc = hipCreateChannelDesc<T>();
|
||||
HipTest::initHIPArrays(&A_d, &B_d, &C_d, &desc, numW, numH, 0);
|
||||
HipTest::initArraysForHost(&A_h, &B_h, &C_h, numW*numH, usePinnedHost);
|
||||
unsigned blocks = HipTest::setNumBlocks(blocksPerCU, threadsPerBlock, numW*numH);
|
||||
|
||||
if (usePitch) {
|
||||
T *A_p, *B_p, *C_p;
|
||||
size_t pitch_A, pitch_B, pitch_C;
|
||||
|
||||
HipTest::initArrays2DPitch(&A_p, &B_p, &C_p, &pitch_A, &pitch_B, &pitch_C, numW, numH);
|
||||
HIPCHECK (hipMemcpy2D (A_p, pitch_A, A_h, width, width, numH, hipMemcpyHostToDevice) );
|
||||
HIPCHECK (hipMemcpy2D (B_p, pitch_B, B_h, width, width, numH, hipMemcpyHostToDevice) );
|
||||
|
||||
HIPCHECK (hipMemcpy2DToArray (A_d, 0, 0, (void *)A_p, pitch_A, width, numH, hipMemcpyDeviceToDevice) );
|
||||
HIPCHECK (hipMemcpy2DToArray (B_d, 0, 0, (void *)B_p, pitch_B, width, numH, hipMemcpyDeviceToDevice) );
|
||||
|
||||
hipFree(A_p);
|
||||
hipFree(B_p);
|
||||
hipFree(C_p);
|
||||
}
|
||||
// 2D
|
||||
else if ((numW >= 1) && (numH >= 1)) {
|
||||
hipChannelFormatDesc desc = hipCreateChannelDesc<T>();
|
||||
HipTest::initHIPArrays(&A_d, &B_d, &C_d, &desc, numW, numH, 0);
|
||||
HipTest::initArraysForHost(&A_h, &B_h, &C_h, numW * numH, usePinnedHost);
|
||||
unsigned blocks = HipTest::setNumBlocks(blocksPerCU, threadsPerBlock, numW * numH);
|
||||
|
||||
if (usePitch) {
|
||||
T *A_p, *B_p, *C_p;
|
||||
size_t pitch_A, pitch_B, pitch_C;
|
||||
|
||||
HipTest::initArrays2DPitch(&A_p, &B_p, &C_p, &pitch_A, &pitch_B, &pitch_C, numW, numH);
|
||||
HIPCHECK(hipMemcpy2D(A_p, pitch_A, A_h, width, width, numH, hipMemcpyHostToDevice));
|
||||
HIPCHECK(hipMemcpy2D(B_p, pitch_B, B_h, width, width, numH, hipMemcpyHostToDevice));
|
||||
|
||||
HIPCHECK(hipMemcpy2DToArray(A_d, 0, 0, (void*)A_p, pitch_A, width, numH,
|
||||
hipMemcpyDeviceToDevice));
|
||||
HIPCHECK(hipMemcpy2DToArray(B_d, 0, 0, (void*)B_p, pitch_B, width, numH,
|
||||
hipMemcpyDeviceToDevice));
|
||||
|
||||
hipFree(A_p);
|
||||
hipFree(B_p);
|
||||
hipFree(C_p);
|
||||
} else {
|
||||
HIPCHECK(hipMemcpy2DToArray(A_d, 0, 0, (void*)A_h, width, width, numH,
|
||||
hipMemcpyHostToDevice));
|
||||
HIPCHECK(hipMemcpy2DToArray(B_d, 0, 0, (void*)B_h, width, width, numH,
|
||||
hipMemcpyHostToDevice));
|
||||
}
|
||||
|
||||
hipLaunchKernel(HipTest::vectorADD, dim3(blocks), dim3(threadsPerBlock), 0, 0,
|
||||
(T*)A_d->data, (T*)B_d->data, (T*)C_d->data, numW * numH);
|
||||
|
||||
HIPCHECK(hipMemcpy2D((void*)C_h, width, (void*)C_d->data, width, width, numH,
|
||||
hipMemcpyDeviceToHost));
|
||||
|
||||
HIPCHECK(hipDeviceSynchronize());
|
||||
HipTest::checkVectorADD(A_h, B_h, C_h, numW * numH);
|
||||
}
|
||||
// Unknown
|
||||
else {
|
||||
HIPCHECK (hipMemcpy2DToArray (A_d, 0, 0, (void *)A_h, width, width, numH, hipMemcpyHostToDevice) );
|
||||
HIPCHECK (hipMemcpy2DToArray (B_d, 0, 0, (void *)B_h, width, width, numH, hipMemcpyHostToDevice) );
|
||||
HIPASSERT("Incompatible dimensions" && 0);
|
||||
}
|
||||
|
||||
hipLaunchKernel(HipTest::vectorADD, dim3(blocks), dim3(threadsPerBlock), 0, 0, (T*)A_d->data, (T*)B_d->data, (T*)C_d->data, numW*numH);
|
||||
|
||||
HIPCHECK (hipMemcpy2D ((void*)C_h, width, (void*)C_d->data, width, width, numH, hipMemcpyDeviceToHost) );
|
||||
|
||||
HIPCHECK ( hipDeviceSynchronize() );
|
||||
HipTest::checkVectorADD(A_h, B_h, C_h, numW*numH);
|
||||
}
|
||||
// Unknown
|
||||
else {
|
||||
HIPASSERT("Incompatible dimensions" && 0);
|
||||
}
|
||||
|
||||
hipFreeArray(A_d);
|
||||
hipFreeArray(B_d);
|
||||
hipFreeArray(C_d);
|
||||
HipTest::freeArraysForHost(A_h, B_h, C_h, usePinnedHost);
|
||||
|
||||
printf (" %s success\n", __func__);
|
||||
hipFreeArray(A_d);
|
||||
hipFreeArray(B_d);
|
||||
hipFreeArray(C_d);
|
||||
HipTest::freeArraysForHost(A_h, B_h, C_h, usePinnedHost);
|
||||
|
||||
printf(" %s success\n", __func__);
|
||||
}
|
||||
|
||||
//---
|
||||
//Try many different sizes to memory copy.
|
||||
// Try many different sizes to memory copy.
|
||||
template <typename T>
|
||||
void memcpyArraytest_size(size_t maxElem=0, size_t offset=0)
|
||||
{
|
||||
printf ("test: %s<%s>\n", __func__, TYPENAME(T));
|
||||
void memcpyArraytest_size(size_t maxElem = 0, size_t offset = 0) {
|
||||
printf("test: %s<%s>\n", __func__, TYPENAME(T));
|
||||
|
||||
int deviceId;
|
||||
HIPCHECK(hipGetDevice(&deviceId));
|
||||
int deviceId;
|
||||
HIPCHECK(hipGetDevice(&deviceId));
|
||||
|
||||
size_t free, total;
|
||||
HIPCHECK(hipMemGetInfo(&free, &total));
|
||||
size_t free, total;
|
||||
HIPCHECK(hipMemGetInfo(&free, &total));
|
||||
|
||||
if (maxElem == 0) {
|
||||
maxElem = free/sizeof(T)/5;
|
||||
}
|
||||
if (maxElem == 0) {
|
||||
maxElem = free / sizeof(T) / 5;
|
||||
}
|
||||
|
||||
printf (" device#%d: hipMemGetInfo: free=%zu (%4.2fMB) total=%zu (%4.2fMB) maxSize=%6.1fMB offset=%lu\n",
|
||||
deviceId, free, (float)(free/1024.0/1024.0), total, (float)(total/1024.0/1024.0), maxElem*sizeof(T)/1024.0/1024.0, offset);
|
||||
printf(
|
||||
" device#%d: hipMemGetInfo: free=%zu (%4.2fMB) total=%zu (%4.2fMB) maxSize=%6.1fMB "
|
||||
"offset=%lu\n",
|
||||
deviceId, free, (float)(free / 1024.0 / 1024.0), total, (float)(total / 1024.0 / 1024.0),
|
||||
maxElem * sizeof(T) / 1024.0 / 1024.0, offset);
|
||||
|
||||
// Test 1D
|
||||
for (size_t elem=64; elem+offset<=maxElem; elem*=2) {
|
||||
HIPCHECK ( hipDeviceReset() );
|
||||
memcpyArraytest<T>(elem+offset, 1, 0); // unpinned host
|
||||
HIPCHECK ( hipDeviceReset() );
|
||||
memcpyArraytest<T>(elem+offset, 1, 1); // pinned host
|
||||
}
|
||||
// Test 1D
|
||||
for (size_t elem = 64; elem + offset <= maxElem; elem *= 2) {
|
||||
HIPCHECK(hipDeviceReset());
|
||||
memcpyArraytest<T>(elem + offset, 1, 0); // unpinned host
|
||||
HIPCHECK(hipDeviceReset());
|
||||
memcpyArraytest<T>(elem + offset, 1, 1); // pinned host
|
||||
}
|
||||
|
||||
// Test 2D
|
||||
size_t maxElem2D = sqrt(maxElem);
|
||||
// Test 2D
|
||||
size_t maxElem2D = sqrt(maxElem);
|
||||
|
||||
for (size_t elem=64; elem+offset<=maxElem2D; elem*=2) {
|
||||
HIPCHECK ( hipDeviceReset() );
|
||||
memcpyArraytest<T>(elem+offset, elem+offset, 0, 1); // use pitch
|
||||
}
|
||||
for (size_t elem = 64; elem + offset <= maxElem2D; elem *= 2) {
|
||||
HIPCHECK(hipDeviceReset());
|
||||
memcpyArraytest<T>(elem + offset, elem + offset, 0, 1); // use pitch
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int main(int argc, char* argv[]) {
|
||||
HipTest::parseStandardArguments(argc, argv, true);
|
||||
|
||||
printf ("info: set device to %d\n", p_gpuDevice);
|
||||
printf("info: set device to %d\n", p_gpuDevice);
|
||||
HIPCHECK(hipSetDevice(p_gpuDevice));
|
||||
|
||||
if (p_tests & 0x1) {
|
||||
printf ("\n\n=== tests&1 (types)\n");
|
||||
printf("\n\n=== tests&1 (types)\n");
|
||||
printSep();
|
||||
HIPCHECK ( hipDeviceReset() );
|
||||
size_t width = N/6;
|
||||
size_t height = N/6;
|
||||
HIPCHECK(hipDeviceReset());
|
||||
size_t width = N / 6;
|
||||
size_t height = N / 6;
|
||||
memcpy2Dtest<float>(321, 211, 0);
|
||||
memcpy2Dtest<double>(322, 211, 0);
|
||||
memcpy2Dtest<char>(320, 211, 0);
|
||||
memcpy2Dtest<int>(323, 211, 0);
|
||||
printf ("===\n\n\n");
|
||||
printf("===\n\n\n");
|
||||
|
||||
printf ("\n\n=== tests&1 (types)\n");
|
||||
printf("\n\n=== tests&1 (types)\n");
|
||||
printSep();
|
||||
// 2D
|
||||
memcpyArraytest<float>(320, 211, 0, 0);
|
||||
@@ -245,23 +249,22 @@ int main(int argc, char *argv[])
|
||||
memcpyArraytest<float>(320, 1, 0);
|
||||
memcpyArraytest<unsigned int>(322, 1, 0);
|
||||
memcpyArraytest<int>(320, 1, 0);
|
||||
printf ("===\n\n\n");
|
||||
printf("===\n\n\n");
|
||||
}
|
||||
|
||||
if (p_tests & 0x4) {
|
||||
printf ("\n\n=== tests&4 (test sizes and offsets)\n");
|
||||
printf("\n\n=== tests&4 (test sizes and offsets)\n");
|
||||
printSep();
|
||||
HIPCHECK ( hipDeviceReset() );
|
||||
HIPCHECK(hipDeviceReset());
|
||||
printSep();
|
||||
memcpyArraytest_size<float>(0,0);
|
||||
memcpyArraytest_size<float>(0, 0);
|
||||
printSep();
|
||||
memcpyArraytest_size<float>(0,64);
|
||||
memcpyArraytest_size<float>(0, 64);
|
||||
printSep();
|
||||
memcpyArraytest_size<float>(1024*1024,13);
|
||||
memcpyArraytest_size<float>(1024 * 1024, 13);
|
||||
printSep();
|
||||
memcpyArraytest_size<float>(1024*1024,50);
|
||||
memcpyArraytest_size<float>(1024 * 1024, 50);
|
||||
}
|
||||
|
||||
passed();
|
||||
|
||||
}
|
||||
|
||||
@@ -26,61 +26,62 @@ THE SOFTWARE.
|
||||
* HIT_END
|
||||
*/
|
||||
|
||||
#include"test_common.h"
|
||||
#include<malloc.h>
|
||||
#include "test_common.h"
|
||||
#include <malloc.h>
|
||||
|
||||
#define LEN 1024*1024
|
||||
#define SIZE LEN*sizeof(float)
|
||||
#define LEN 1024 * 1024
|
||||
#define SIZE LEN * sizeof(float)
|
||||
|
||||
__global__ void Add(hipLaunchParm lp, float *Ad, float *Bd, float *Cd){
|
||||
int tx = threadIdx.x + blockIdx.x * blockDim.x;
|
||||
Cd[tx] = Ad[tx] + Bd[tx];
|
||||
__global__ void Add(hipLaunchParm lp, float* Ad, float* Bd, float* Cd) {
|
||||
int tx = threadIdx.x + blockIdx.x * blockDim.x;
|
||||
Cd[tx] = Ad[tx] + Bd[tx];
|
||||
}
|
||||
|
||||
int main(){
|
||||
float *A, *B, *C, *D;
|
||||
float *Ad, *Bd, *Cd, *Dd;
|
||||
unsigned int FlagA, FlagB, FlagC;
|
||||
FlagA = hipHostMallocWriteCombined | hipHostMallocMapped;
|
||||
FlagB = hipHostMallocWriteCombined | hipHostMallocMapped;
|
||||
FlagC = hipHostMallocMapped;
|
||||
hipDeviceProp_t prop;
|
||||
int device;
|
||||
HIPCHECK(hipGetDevice(&device));
|
||||
HIPCHECK(hipGetDeviceProperties(&prop, device));
|
||||
if(prop.canMapHostMemory != 1){
|
||||
std::cout<<"Exiting..."<<std::endl;
|
||||
}
|
||||
HIPCHECK(hipHostMalloc((void**)&A, SIZE, hipHostMallocWriteCombined | hipHostMallocMapped));
|
||||
HIPCHECK(hipHostMalloc((void**)&B, SIZE, hipHostMallocWriteCombined | hipHostMallocMapped));
|
||||
HIPCHECK(hipHostMalloc((void**)&C, SIZE, hipHostMallocMapped));
|
||||
|
||||
HIPCHECK(hipHostMalloc((void**)&D, SIZE, hipHostMallocDefault));
|
||||
|
||||
unsigned int flagA, flagB, flagC;
|
||||
HIPCHECK(hipHostGetDevicePointer((void**)&Ad, A, 0));
|
||||
HIPCHECK(hipHostGetDevicePointer((void**)&Bd, B, 0));
|
||||
HIPCHECK(hipHostGetDevicePointer((void**)&Cd, C, 0));
|
||||
HIPCHECK(hipHostGetDevicePointer((void**)&Dd, D, 0));
|
||||
HIPCHECK(hipHostGetFlags(&flagA, A));
|
||||
HIPCHECK(hipHostGetFlags(&flagB, B));
|
||||
HIPCHECK(hipHostGetFlags(&flagC, C));
|
||||
|
||||
for(int i=0;i<LEN;i++){
|
||||
A[i] = 1.0f;
|
||||
B[i] = 2.0f;
|
||||
}
|
||||
|
||||
dim3 dimGrid(LEN/512,1,1);
|
||||
dim3 dimBlock(512,1,1);
|
||||
|
||||
hipLaunchKernel(HIP_KERNEL_NAME(Add), dimGrid, dimBlock, 0, 0, Ad, Bd, Cd);
|
||||
|
||||
HIPCHECK(hipMemcpy(C, Cd, SIZE, hipMemcpyDeviceToHost)); // Note this really HostToHost not DeviceToHost, since memory is mapped...
|
||||
HIPASSERT(C[10] == 3.0f);
|
||||
HIPASSERT(flagA == FlagA);
|
||||
HIPASSERT(flagB == FlagB);
|
||||
HIPASSERT(flagC == FlagC);
|
||||
passed();
|
||||
|
||||
int main() {
|
||||
float *A, *B, *C, *D;
|
||||
float *Ad, *Bd, *Cd, *Dd;
|
||||
unsigned int FlagA, FlagB, FlagC;
|
||||
FlagA = hipHostMallocWriteCombined | hipHostMallocMapped;
|
||||
FlagB = hipHostMallocWriteCombined | hipHostMallocMapped;
|
||||
FlagC = hipHostMallocMapped;
|
||||
hipDeviceProp_t prop;
|
||||
int device;
|
||||
HIPCHECK(hipGetDevice(&device));
|
||||
HIPCHECK(hipGetDeviceProperties(&prop, device));
|
||||
if (prop.canMapHostMemory != 1) {
|
||||
std::cout << "Exiting..." << std::endl;
|
||||
}
|
||||
HIPCHECK(hipHostMalloc((void**)&A, SIZE, hipHostMallocWriteCombined | hipHostMallocMapped));
|
||||
HIPCHECK(hipHostMalloc((void**)&B, SIZE, hipHostMallocWriteCombined | hipHostMallocMapped));
|
||||
HIPCHECK(hipHostMalloc((void**)&C, SIZE, hipHostMallocMapped));
|
||||
|
||||
HIPCHECK(hipHostMalloc((void**)&D, SIZE, hipHostMallocDefault));
|
||||
|
||||
unsigned int flagA, flagB, flagC;
|
||||
HIPCHECK(hipHostGetDevicePointer((void**)&Ad, A, 0));
|
||||
HIPCHECK(hipHostGetDevicePointer((void**)&Bd, B, 0));
|
||||
HIPCHECK(hipHostGetDevicePointer((void**)&Cd, C, 0));
|
||||
HIPCHECK(hipHostGetDevicePointer((void**)&Dd, D, 0));
|
||||
HIPCHECK(hipHostGetFlags(&flagA, A));
|
||||
HIPCHECK(hipHostGetFlags(&flagB, B));
|
||||
HIPCHECK(hipHostGetFlags(&flagC, C));
|
||||
|
||||
for (int i = 0; i < LEN; i++) {
|
||||
A[i] = 1.0f;
|
||||
B[i] = 2.0f;
|
||||
}
|
||||
|
||||
dim3 dimGrid(LEN / 512, 1, 1);
|
||||
dim3 dimBlock(512, 1, 1);
|
||||
|
||||
hipLaunchKernel(HIP_KERNEL_NAME(Add), dimGrid, dimBlock, 0, 0, Ad, Bd, Cd);
|
||||
|
||||
HIPCHECK(
|
||||
hipMemcpy(C, Cd, SIZE, hipMemcpyDeviceToHost)); // Note this really HostToHost not
|
||||
// DeviceToHost, since memory is mapped...
|
||||
HIPASSERT(C[10] == 3.0f);
|
||||
HIPASSERT(flagA == FlagA);
|
||||
HIPASSERT(flagB == FlagB);
|
||||
HIPASSERT(flagC == FlagC);
|
||||
passed();
|
||||
}
|
||||
|
||||
@@ -27,18 +27,18 @@
|
||||
*/
|
||||
|
||||
#include <vector>
|
||||
#include"test_common.h"
|
||||
#include "test_common.h"
|
||||
|
||||
#define LEN 1024*1024
|
||||
#define SIZE LEN*sizeof(float)
|
||||
#define LEN 1024 * 1024
|
||||
#define SIZE LEN * sizeof(float)
|
||||
|
||||
__global__ void Add(float *Ad, float *Bd, float *Cd){
|
||||
__global__ void Add(float* Ad, float* Bd, float* Cd) {
|
||||
int tx = threadIdx.x + blockIdx.x * blockDim.x;
|
||||
Cd[tx] = Ad[tx] + Bd[tx];
|
||||
}
|
||||
|
||||
|
||||
__global__ void Set(int *Ad, int val){
|
||||
__global__ void Set(int* Ad, int val) {
|
||||
int tx = threadIdx.x + blockIdx.x * blockDim.x;
|
||||
Ad[tx] = val;
|
||||
}
|
||||
@@ -50,16 +50,16 @@ __global__ void Set(int *Ad, int val){
|
||||
|
||||
std::vector<std::string> syncMsg = {"event", "stream", "device"};
|
||||
|
||||
void CheckHostPointer(int numElements, int *ptr, unsigned eventFlags, int syncMethod, std::string msg)
|
||||
{
|
||||
std::cerr << "test: CheckHostPointer " << msg
|
||||
void CheckHostPointer(int numElements, int* ptr, unsigned eventFlags, int syncMethod,
|
||||
std::string msg) {
|
||||
std::cerr << "test: CheckHostPointer "
|
||||
<< msg
|
||||
//<< " HIP_COHERENT_HOST_ALLOC=" << HIP_COHERENT_HOST_ALLOC
|
||||
//<< " HIP_EVENT_SYS_RELEASE=" << HIP_EVENT_SYS_RELEASE
|
||||
<< " eventFlags = " << std::hex << eventFlags
|
||||
<< ((eventFlags & hipEventReleaseToDevice) ? " hipEventReleaseToDevice" : "")
|
||||
<< ((eventFlags & hipEventReleaseToDevice) ? " hipEventReleaseToDevice" : "")
|
||||
<< ((eventFlags & hipEventReleaseToSystem) ? " hipEventReleaseToSystem" : "")
|
||||
<< " ptr=" << ptr
|
||||
<< " syncMethod=" << syncMsg[syncMethod] << "\n";
|
||||
<< " ptr=" << ptr << " syncMethod=" << syncMsg[syncMethod] << "\n";
|
||||
|
||||
hipStream_t s;
|
||||
hipEvent_t e;
|
||||
@@ -67,8 +67,8 @@ void CheckHostPointer(int numElements, int *ptr, unsigned eventFlags, int syncMe
|
||||
// Init:
|
||||
HIPCHECK(hipStreamCreate(&s));
|
||||
HIPCHECK(hipEventCreateWithFlags(&e, eventFlags))
|
||||
dim3 dimBlock(64,1,1);
|
||||
dim3 dimGrid(numElements/dimBlock.x,1,1);
|
||||
dim3 dimBlock(64, 1, 1);
|
||||
dim3 dimGrid(numElements / dimBlock.x, 1, 1);
|
||||
|
||||
const int expected = 13;
|
||||
|
||||
@@ -94,9 +94,9 @@ void CheckHostPointer(int numElements, int *ptr, unsigned eventFlags, int syncMe
|
||||
assert(0);
|
||||
};
|
||||
|
||||
for (int i=0; i<numElements; i++) {
|
||||
for (int i = 0; i < numElements; i++) {
|
||||
if (ptr[i] != expected) {
|
||||
printf ("mismatch at %d: %d != %d\n", i, ptr[i], expected);
|
||||
printf("mismatch at %d: %d != %d\n", i, ptr[i], expected);
|
||||
assert(ptr[i] == expected);
|
||||
}
|
||||
}
|
||||
@@ -105,15 +105,13 @@ void CheckHostPointer(int numElements, int *ptr, unsigned eventFlags, int syncMe
|
||||
HIPCHECK(hipEventDestroy(e));
|
||||
};
|
||||
|
||||
int main(){
|
||||
|
||||
|
||||
int main() {
|
||||
hipDeviceProp_t prop;
|
||||
int device;
|
||||
HIPCHECK(hipGetDevice(&device));
|
||||
HIPCHECK(hipGetDeviceProperties(&prop, device));
|
||||
if(prop.canMapHostMemory != 1){
|
||||
std::cout<<"Exiting..."<<std::endl;
|
||||
if (prop.canMapHostMemory != 1) {
|
||||
std::cout << "Exiting..." << std::endl;
|
||||
failed("Does support HostPinned Memory");
|
||||
}
|
||||
|
||||
@@ -128,7 +126,7 @@ int main(){
|
||||
HIPCHECK(hipHostGetDevicePointer((void**)&Ad, A, 0));
|
||||
HIPCHECK(hipHostGetDevicePointer((void**)&Cd, C, 0));
|
||||
|
||||
for(int i=0;i<LEN;i++){
|
||||
for (int i = 0; i < LEN; i++) {
|
||||
A[i] = 1.0f;
|
||||
B[i] = 2.0f;
|
||||
}
|
||||
@@ -136,8 +134,8 @@ int main(){
|
||||
HIPCHECK(hipMalloc((void**)&Bd, SIZE));
|
||||
HIPCHECK(hipMemcpy(Bd, B, SIZE, hipMemcpyHostToDevice));
|
||||
|
||||
dim3 dimGrid(LEN/512,1,1);
|
||||
dim3 dimBlock(512,1,1);
|
||||
dim3 dimGrid(LEN / 512, 1, 1);
|
||||
dim3 dimBlock(512, 1, 1);
|
||||
|
||||
hipLaunchKernelGGL(Add, dimGrid, dimBlock, 0, 0, Ad, Bd, Cd);
|
||||
|
||||
@@ -149,64 +147,61 @@ int main(){
|
||||
}
|
||||
|
||||
{
|
||||
int numElements = 1024*16;
|
||||
size_t sizeBytes = numElements * sizeof (int);
|
||||
int numElements = 1024 * 16;
|
||||
size_t sizeBytes = numElements * sizeof(int);
|
||||
|
||||
#ifdef __HIP_PLATFORM_HCC__
|
||||
{
|
||||
// Stimulate error condition:
|
||||
int *A = &numElements;
|
||||
HIPCHECK_API(hipHostMalloc((void**)&A, sizeBytes, hipHostMallocCoherent|hipHostMallocNonCoherent), hipErrorInvalidValue);
|
||||
int* A = &numElements;
|
||||
HIPCHECK_API(hipHostMalloc((void**)&A, sizeBytes,
|
||||
hipHostMallocCoherent | hipHostMallocNonCoherent),
|
||||
hipErrorInvalidValue);
|
||||
|
||||
assert (A == 0);
|
||||
assert(A == 0);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
{
|
||||
int *A = nullptr;
|
||||
int* A = nullptr;
|
||||
HIPCHECK(hipHostMalloc((void**)&A, sizeBytes, hipHostMallocNonCoherent));
|
||||
const char *ptrType = "non-coherent"; // TODO
|
||||
CheckHostPointer(numElements, A, hipEventReleaseToSystem, SYNC_DEVICE, ptrType);
|
||||
CheckHostPointer(numElements, A, hipEventReleaseToSystem, SYNC_STREAM, ptrType);
|
||||
CheckHostPointer(numElements, A, hipEventReleaseToSystem, SYNC_EVENT, ptrType);
|
||||
const char* ptrType = "non-coherent"; // TODO
|
||||
CheckHostPointer(numElements, A, hipEventReleaseToSystem, SYNC_DEVICE, ptrType);
|
||||
CheckHostPointer(numElements, A, hipEventReleaseToSystem, SYNC_STREAM, ptrType);
|
||||
CheckHostPointer(numElements, A, hipEventReleaseToSystem, SYNC_EVENT, ptrType);
|
||||
|
||||
// agent-scope releases don't provide host visibility, don't use them here:
|
||||
}
|
||||
|
||||
if (1) {
|
||||
int *A = nullptr;
|
||||
int* A = nullptr;
|
||||
HIPCHECK(hipHostMalloc((void**)&A, sizeBytes, hipHostMallocCoherent));
|
||||
const char *ptrType = "coherent";
|
||||
CheckHostPointer(numElements, A, hipEventReleaseToDevice, SYNC_DEVICE, ptrType);
|
||||
CheckHostPointer(numElements, A, hipEventReleaseToDevice, SYNC_STREAM, ptrType);
|
||||
CheckHostPointer(numElements, A, hipEventReleaseToDevice, SYNC_EVENT, ptrType);
|
||||
const char* ptrType = "coherent";
|
||||
CheckHostPointer(numElements, A, hipEventReleaseToDevice, SYNC_DEVICE, ptrType);
|
||||
CheckHostPointer(numElements, A, hipEventReleaseToDevice, SYNC_STREAM, ptrType);
|
||||
CheckHostPointer(numElements, A, hipEventReleaseToDevice, SYNC_EVENT, ptrType);
|
||||
|
||||
CheckHostPointer(numElements, A, hipEventReleaseToSystem, SYNC_DEVICE, ptrType);
|
||||
CheckHostPointer(numElements, A, hipEventReleaseToSystem, SYNC_STREAM, ptrType);
|
||||
CheckHostPointer(numElements, A, hipEventReleaseToSystem, SYNC_EVENT, ptrType);
|
||||
CheckHostPointer(numElements, A, hipEventReleaseToSystem, SYNC_DEVICE, ptrType);
|
||||
CheckHostPointer(numElements, A, hipEventReleaseToSystem, SYNC_STREAM, ptrType);
|
||||
CheckHostPointer(numElements, A, hipEventReleaseToSystem, SYNC_EVENT, ptrType);
|
||||
}
|
||||
|
||||
|
||||
// Check defaults:
|
||||
if (1) {
|
||||
int *A = nullptr;
|
||||
int* A = nullptr;
|
||||
HIPCHECK(hipHostMalloc((void**)&A, sizeBytes));
|
||||
const char *ptrType = "default";
|
||||
CheckHostPointer(numElements, A, 0, SYNC_DEVICE, ptrType);
|
||||
CheckHostPointer(numElements, A, 0, SYNC_STREAM, ptrType);
|
||||
CheckHostPointer(numElements, A, 0, SYNC_EVENT, ptrType);
|
||||
const char* ptrType = "default";
|
||||
CheckHostPointer(numElements, A, 0, SYNC_DEVICE, ptrType);
|
||||
CheckHostPointer(numElements, A, 0, SYNC_STREAM, ptrType);
|
||||
CheckHostPointer(numElements, A, 0, SYNC_EVENT, ptrType);
|
||||
|
||||
CheckHostPointer(numElements, A, 0, SYNC_DEVICE, ptrType);
|
||||
CheckHostPointer(numElements, A, 0, SYNC_STREAM, ptrType);
|
||||
CheckHostPointer(numElements, A, 0, SYNC_EVENT, ptrType);
|
||||
CheckHostPointer(numElements, A, 0, SYNC_DEVICE, ptrType);
|
||||
CheckHostPointer(numElements, A, 0, SYNC_STREAM, ptrType);
|
||||
CheckHostPointer(numElements, A, 0, SYNC_EVENT, ptrType);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
passed();
|
||||
|
||||
}
|
||||
|
||||
@@ -25,18 +25,17 @@ THE SOFTWARE.
|
||||
|
||||
// TODO - bug if run both back-to-back, once fixed should just need one command line
|
||||
|
||||
#include"test_common.h"
|
||||
#include<malloc.h>
|
||||
#include "test_common.h"
|
||||
#include <malloc.h>
|
||||
|
||||
__global__ void Inc(hipLaunchParm lp, float *Ad){
|
||||
__global__ void Inc(hipLaunchParm lp, float* Ad) {
|
||||
int tx = threadIdx.x + blockIdx.x * blockDim.x;
|
||||
Ad[tx] = Ad[tx] + float(1);
|
||||
}
|
||||
|
||||
|
||||
template<typename T>
|
||||
void doMemCopy(size_t numElements, int offset, T *A, T *Bh, T *Bd, bool internalRegister)
|
||||
{
|
||||
template <typename T>
|
||||
void doMemCopy(size_t numElements, int offset, T* A, T* Bh, T* Bd, bool internalRegister) {
|
||||
A = A + offset;
|
||||
numElements -= offset;
|
||||
|
||||
@@ -48,7 +47,7 @@ void doMemCopy(size_t numElements, int offset, T *A, T *Bh, T *Bd, bool internal
|
||||
|
||||
|
||||
// Reset
|
||||
for(size_t i=0;i<numElements;i++){
|
||||
for (size_t i = 0; i < numElements; i++) {
|
||||
A[i] = float(i);
|
||||
Bh[i] = 0.0f;
|
||||
}
|
||||
@@ -57,13 +56,13 @@ void doMemCopy(size_t numElements, int offset, T *A, T *Bh, T *Bd, bool internal
|
||||
|
||||
|
||||
//
|
||||
HIPCHECK(hipMemcpy(Bd, A, sizeBytes, hipMemcpyHostToDevice));
|
||||
HIPCHECK(hipMemcpy(Bd, A, sizeBytes, hipMemcpyHostToDevice));
|
||||
HIPCHECK(hipMemcpy(Bh, Bd, sizeBytes, hipMemcpyDeviceToHost));
|
||||
|
||||
// Make sure the copy worked
|
||||
for(size_t i=0;i<numElements;i++){
|
||||
for (size_t i = 0; i < numElements; i++) {
|
||||
if (Bh[i] != A[i]) {
|
||||
printf ("mismatch at Bh[%zu]=%f, A[%zu]=%f\n", i, Bh[i], i, A[i]);
|
||||
printf("mismatch at Bh[%zu]=%f, A[%zu]=%f\n", i, Bh[i], i, A[i]);
|
||||
failed("mismatch");
|
||||
};
|
||||
}
|
||||
@@ -71,12 +70,9 @@ void doMemCopy(size_t numElements, int offset, T *A, T *Bh, T *Bd, bool internal
|
||||
if (internalRegister) {
|
||||
HIPCHECK(hipHostUnregister(A));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
HipTest::parseStandardArguments(argc, argv, true);
|
||||
|
||||
const size_t size = N * sizeof(float);
|
||||
@@ -90,20 +86,20 @@ int main(int argc, char *argv[])
|
||||
HIPCHECK(hipHostRegister(A, size, 0));
|
||||
|
||||
|
||||
for(int i=0;i<N;i++){
|
||||
for (int i = 0; i < N; i++) {
|
||||
A[i] = float(1);
|
||||
}
|
||||
|
||||
|
||||
for(int i=0;i<num_devices;i++){
|
||||
for (int i = 0; i < num_devices; i++) {
|
||||
HIPCHECK(hipSetDevice(i));
|
||||
HIPCHECK(hipHostGetDevicePointer((void**)&Ad[i], A, 0));
|
||||
}
|
||||
|
||||
// Reference the registered device pointer Ad from inside the kernel:
|
||||
for(int i=0;i<num_devices;i++){
|
||||
for (int i = 0; i < num_devices; i++) {
|
||||
HIPCHECK(hipSetDevice(i));
|
||||
hipLaunchKernel(Inc, dim3(N/512), dim3(512), 0, 0, Ad[i]);
|
||||
hipLaunchKernel(Inc, dim3(N / 512), dim3(512), 0, 0, Ad[i]);
|
||||
|
||||
HIPCHECK(hipDeviceSynchronize());
|
||||
}
|
||||
@@ -111,7 +107,7 @@ int main(int argc, char *argv[])
|
||||
|
||||
HIPCHECK(hipHostUnregister(A));
|
||||
|
||||
free (A);
|
||||
free(A);
|
||||
}
|
||||
|
||||
|
||||
@@ -120,7 +116,7 @@ int main(int argc, char *argv[])
|
||||
HIPCHECK(hipSetDevice(0));
|
||||
|
||||
|
||||
float * A = (float*)malloc(size);
|
||||
float* A = (float*)malloc(size);
|
||||
|
||||
// Copy to B, this should be optimal pinned malloc copy:
|
||||
// Note we are using the host pointer here:
|
||||
@@ -130,29 +126,26 @@ int main(int argc, char *argv[])
|
||||
|
||||
// TODO - set to 128
|
||||
#define OFFSETS_TO_TRY 128
|
||||
assert (N>OFFSETS_TO_TRY);
|
||||
assert(N > OFFSETS_TO_TRY);
|
||||
|
||||
if (p_tests & 0x2) {
|
||||
for (size_t i=0; i<OFFSETS_TO_TRY; i++) {
|
||||
doMemCopy(N, i, A, Bh, Bd, true/*internalRegister*/);
|
||||
for (size_t i = 0; i < OFFSETS_TO_TRY; i++) {
|
||||
doMemCopy(N, i, A, Bh, Bd, true /*internalRegister*/);
|
||||
}
|
||||
}
|
||||
|
||||
if (p_tests & 0x4) {
|
||||
HIPCHECK(hipHostRegister(A, size, 0));
|
||||
for (size_t i=0; i<OFFSETS_TO_TRY; i++) {
|
||||
doMemCopy(N, i, A, Bh, Bd, false/*internalRegister*/);
|
||||
for (size_t i = 0; i < OFFSETS_TO_TRY; i++) {
|
||||
doMemCopy(N, i, A, Bh, Bd, false /*internalRegister*/);
|
||||
}
|
||||
HIPCHECK(hipHostUnregister(A));
|
||||
}
|
||||
|
||||
|
||||
|
||||
free (A);
|
||||
|
||||
free(A);
|
||||
}
|
||||
|
||||
|
||||
|
||||
passed();
|
||||
passed();
|
||||
}
|
||||
|
||||
@@ -26,27 +26,27 @@ THE SOFTWARE.
|
||||
* HIT_END
|
||||
*/
|
||||
|
||||
#include"test_common.h"
|
||||
#include "test_common.h"
|
||||
|
||||
struct {
|
||||
float a;
|
||||
int b;
|
||||
void *c;
|
||||
} Struct ;
|
||||
float a;
|
||||
int b;
|
||||
void* c;
|
||||
} Struct;
|
||||
|
||||
int main(){
|
||||
int *iPtr;
|
||||
float *fPtr;
|
||||
struct Struct *sPtr;
|
||||
size_t sSetSize = 1024, sGetSize;
|
||||
hipMalloc(&iPtr, sSetSize);
|
||||
hipMalloc(&fPtr, sSetSize);
|
||||
hipMalloc(&sPtr, sSetSize);
|
||||
hipMemPtrGetInfo(iPtr, &sGetSize);
|
||||
assert(sGetSize == sSetSize);
|
||||
hipMemPtrGetInfo(fPtr, &sGetSize);
|
||||
assert(sGetSize == sSetSize);
|
||||
hipMemPtrGetInfo(sPtr, &sGetSize);
|
||||
assert(sGetSize == sSetSize);
|
||||
passed();
|
||||
int main() {
|
||||
int* iPtr;
|
||||
float* fPtr;
|
||||
struct Struct* sPtr;
|
||||
size_t sSetSize = 1024, sGetSize;
|
||||
hipMalloc(&iPtr, sSetSize);
|
||||
hipMalloc(&fPtr, sSetSize);
|
||||
hipMalloc(&sPtr, sSetSize);
|
||||
hipMemPtrGetInfo(iPtr, &sGetSize);
|
||||
assert(sGetSize == sSetSize);
|
||||
hipMemPtrGetInfo(fPtr, &sGetSize);
|
||||
assert(sGetSize == sSetSize);
|
||||
hipMemPtrGetInfo(sPtr, &sGetSize);
|
||||
assert(sGetSize == sSetSize);
|
||||
passed();
|
||||
}
|
||||
|
||||
@@ -35,23 +35,22 @@ THE SOFTWARE.
|
||||
#include "test_common.h"
|
||||
|
||||
|
||||
void printSep()
|
||||
{
|
||||
printf ("======================================================================================\n");
|
||||
void printSep() {
|
||||
printf(
|
||||
"======================================================================================\n");
|
||||
}
|
||||
|
||||
//-------
|
||||
template<typename T>
|
||||
class DeviceMemory
|
||||
{
|
||||
public:
|
||||
template <typename T>
|
||||
class DeviceMemory {
|
||||
public:
|
||||
DeviceMemory(size_t numElements);
|
||||
~DeviceMemory();
|
||||
|
||||
T *A_d() const { return _A_d + _offset; };
|
||||
T *B_d() const { return _B_d + _offset; };
|
||||
T *C_d() const { return _C_d + _offset; };
|
||||
T *C_dd() const { return _C_dd + _offset; };
|
||||
T* A_d() const { return _A_d + _offset; };
|
||||
T* B_d() const { return _B_d + _offset; };
|
||||
T* C_d() const { return _C_d + _offset; };
|
||||
T* C_dd() const { return _C_dd + _offset; };
|
||||
|
||||
size_t maxNumElements() const { return _maxNumElements; };
|
||||
|
||||
@@ -59,92 +58,83 @@ public:
|
||||
void offset(int offset) { _offset = offset; };
|
||||
int offset() const { return _offset; };
|
||||
|
||||
private:
|
||||
T * _A_d;
|
||||
T* _B_d;
|
||||
T* _C_d;
|
||||
T* _C_dd;
|
||||
private:
|
||||
T* _A_d;
|
||||
T* _B_d;
|
||||
T* _C_d;
|
||||
T* _C_dd;
|
||||
|
||||
|
||||
size_t _maxNumElements;
|
||||
int _offset;
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
DeviceMemory<T>::DeviceMemory(size_t numElements)
|
||||
: _maxNumElements(numElements),
|
||||
_offset(0)
|
||||
{
|
||||
T ** np = nullptr;
|
||||
HipTest::initArrays (&_A_d, &_B_d, &_C_d, np, np, np, numElements, 0);
|
||||
template <typename T>
|
||||
DeviceMemory<T>::DeviceMemory(size_t numElements) : _maxNumElements(numElements), _offset(0) {
|
||||
T** np = nullptr;
|
||||
HipTest::initArrays(&_A_d, &_B_d, &_C_d, np, np, np, numElements, 0);
|
||||
|
||||
|
||||
size_t sizeElements = numElements * sizeof(T);
|
||||
|
||||
|
||||
HIPCHECK ( hipMalloc(&_C_dd, sizeElements) );
|
||||
HIPCHECK(hipMalloc(&_C_dd, sizeElements));
|
||||
}
|
||||
|
||||
|
||||
template<typename T>
|
||||
DeviceMemory<T>::~DeviceMemory ()
|
||||
{
|
||||
T * np = nullptr;
|
||||
HipTest::freeArrays (_A_d, _B_d, _C_d, np, np, np, 0);
|
||||
template <typename T>
|
||||
DeviceMemory<T>::~DeviceMemory() {
|
||||
T* np = nullptr;
|
||||
HipTest::freeArrays(_A_d, _B_d, _C_d, np, np, np, 0);
|
||||
|
||||
HIPCHECK (hipFree(_C_dd));
|
||||
HIPCHECK(hipFree(_C_dd));
|
||||
|
||||
_C_dd = NULL;
|
||||
};
|
||||
|
||||
|
||||
|
||||
//-------
|
||||
template<typename T>
|
||||
class HostMemory
|
||||
{
|
||||
public:
|
||||
template <typename T>
|
||||
class HostMemory {
|
||||
public:
|
||||
HostMemory(size_t numElements, bool usePinnedHost);
|
||||
void reset(size_t numElements, bool full=false) ;
|
||||
void reset(size_t numElements, bool full = false);
|
||||
~HostMemory();
|
||||
|
||||
|
||||
T *A_h() const { return _A_h + _offset; };
|
||||
T *B_h() const { return _B_h + _offset; };
|
||||
T *C_h() const { return _C_h + _offset; };
|
||||
|
||||
T* A_h() const { return _A_h + _offset; };
|
||||
T* B_h() const { return _B_h + _offset; };
|
||||
T* C_h() const { return _C_h + _offset; };
|
||||
|
||||
|
||||
size_t maxNumElements() const { return _maxNumElements; };
|
||||
|
||||
void offset(int offset) { _offset = offset; };
|
||||
int offset() const { return _offset; };
|
||||
public:
|
||||
|
||||
public:
|
||||
// Host arrays, secondary copy
|
||||
T * A_hh;
|
||||
T* B_hh;
|
||||
T* A_hh;
|
||||
T* B_hh;
|
||||
|
||||
bool _usePinnedHost;
|
||||
private:
|
||||
bool _usePinnedHost;
|
||||
|
||||
private:
|
||||
size_t _maxNumElements;
|
||||
|
||||
int _offset;
|
||||
|
||||
// Host arrays
|
||||
T * _A_h;
|
||||
T* _B_h;
|
||||
T* _C_h;
|
||||
T* _A_h;
|
||||
T* _B_h;
|
||||
T* _C_h;
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
template <typename T>
|
||||
HostMemory<T>::HostMemory(size_t numElements, bool usePinnedHost)
|
||||
: _maxNumElements(numElements),
|
||||
_usePinnedHost(usePinnedHost),
|
||||
_offset(0)
|
||||
{
|
||||
T ** np = nullptr;
|
||||
HipTest::initArrays (np, np, np, &_A_h, &_B_h, &_C_h, numElements, usePinnedHost);
|
||||
: _maxNumElements(numElements), _usePinnedHost(usePinnedHost), _offset(0) {
|
||||
T** np = nullptr;
|
||||
HipTest::initArrays(np, np, np, &_A_h, &_B_h, &_C_h, numElements, usePinnedHost);
|
||||
|
||||
A_hh = NULL;
|
||||
B_hh = NULL;
|
||||
@@ -153,142 +143,137 @@ HostMemory<T>::HostMemory(size_t numElements, bool usePinnedHost)
|
||||
size_t sizeElements = numElements * sizeof(T);
|
||||
|
||||
if (usePinnedHost) {
|
||||
HIPCHECK ( hipHostMalloc((void**)&A_hh, sizeElements, hipHostMallocDefault) );
|
||||
HIPCHECK ( hipHostMalloc((void**)&B_hh, sizeElements, hipHostMallocDefault) );
|
||||
HIPCHECK(hipHostMalloc((void**)&A_hh, sizeElements, hipHostMallocDefault));
|
||||
HIPCHECK(hipHostMalloc((void**)&B_hh, sizeElements, hipHostMallocDefault));
|
||||
} else {
|
||||
A_hh = (T*)malloc(sizeElements);
|
||||
B_hh = (T*)malloc(sizeElements);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
template<typename T>
|
||||
void
|
||||
HostMemory<T>::reset(size_t numElements, bool full)
|
||||
{
|
||||
template <typename T>
|
||||
void HostMemory<T>::reset(size_t numElements, bool full) {
|
||||
// Initialize the host data:
|
||||
for (size_t i=0; i<numElements; i++) {
|
||||
for (size_t i = 0; i < numElements; i++) {
|
||||
(A_hh)[i] = 1097.0 + i;
|
||||
(B_hh)[i] = 1492.0 + i; // Phi
|
||||
(B_hh)[i] = 1492.0 + i; // Phi
|
||||
|
||||
if (full) {
|
||||
(_A_h)[i] = 3.146f + i; // Pi
|
||||
(_B_h)[i] = 1.618f + i; // Phi
|
||||
(_A_h)[i] = 3.146f + i; // Pi
|
||||
(_B_h)[i] = 1.618f + i; // Phi
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
HostMemory<T>::~HostMemory ()
|
||||
{
|
||||
HipTest::freeArraysForHost (_A_h, _B_h, _C_h, _usePinnedHost);
|
||||
template <typename T>
|
||||
HostMemory<T>::~HostMemory() {
|
||||
HipTest::freeArraysForHost(_A_h, _B_h, _C_h, _usePinnedHost);
|
||||
|
||||
if (_usePinnedHost) {
|
||||
HIPCHECK (hipHostFree(A_hh));
|
||||
HIPCHECK (hipHostFree(B_hh));
|
||||
HIPCHECK(hipHostFree(A_hh));
|
||||
HIPCHECK(hipHostFree(B_hh));
|
||||
|
||||
} else {
|
||||
free(A_hh);
|
||||
free(B_hh);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
//---
|
||||
// Test many different kinds of memory copies.
|
||||
// The subroutine allocates memory , copies to device, runs a vector add kernel, copies back, and checks the result.
|
||||
// The subroutine allocates memory , copies to device, runs a vector add kernel, copies back, and
|
||||
// checks the result.
|
||||
//
|
||||
// IN: numElements controls the number of elements used for allocations.
|
||||
// IN: usePinnedHost : If true, allocate host with hipHostMalloc and is pinned ; else allocate host memory with malloc.
|
||||
// IN: useHostToHost : If true, add an extra host-to-host copy.
|
||||
// IN: useDeviceToDevice : If true, add an extra deviceto-device copy after result is produced.
|
||||
// IN: useMemkindDefault : If true, use memkinddefault (runtime figures out direction). if false, use explicit memcpy direction.
|
||||
// IN: usePinnedHost : If true, allocate host with hipHostMalloc and is pinned ; else allocate host
|
||||
// memory with malloc. IN: useHostToHost : If true, add an extra host-to-host copy. IN:
|
||||
// useDeviceToDevice : If true, add an extra deviceto-device copy after result is produced. IN:
|
||||
// useMemkindDefault : If true, use memkinddefault (runtime figures out direction). if false, use
|
||||
// explicit memcpy direction.
|
||||
//
|
||||
template <typename T>
|
||||
void memcpytest2(DeviceMemory<T> *dmem, HostMemory<T> *hmem, size_t numElements, bool useHostToHost, bool useDeviceToDevice, bool useMemkindDefault)
|
||||
{
|
||||
void memcpytest2(DeviceMemory<T>* dmem, HostMemory<T>* hmem, size_t numElements, bool useHostToHost,
|
||||
bool useDeviceToDevice, bool useMemkindDefault) {
|
||||
size_t sizeElements = numElements * sizeof(T);
|
||||
printf ("test: %s<%s> size=%lu (%6.2fMB) usePinnedHost:%d, useHostToHost:%d, useDeviceToDevice:%d, useMemkindDefault:%d, offsets:dev:%+d host:+%d\n",
|
||||
__func__,
|
||||
TYPENAME(T),
|
||||
sizeElements, sizeElements/1024.0/1024.0,
|
||||
hmem->_usePinnedHost, useHostToHost, useDeviceToDevice, useMemkindDefault,
|
||||
dmem->offset(), hmem->offset()
|
||||
);
|
||||
printf(
|
||||
"test: %s<%s> size=%lu (%6.2fMB) usePinnedHost:%d, useHostToHost:%d, useDeviceToDevice:%d, "
|
||||
"useMemkindDefault:%d, offsets:dev:%+d host:+%d\n",
|
||||
__func__, TYPENAME(T), sizeElements, sizeElements / 1024.0 / 1024.0, hmem->_usePinnedHost,
|
||||
useHostToHost, useDeviceToDevice, useMemkindDefault, dmem->offset(), hmem->offset());
|
||||
|
||||
|
||||
hmem->reset(numElements);
|
||||
unsigned blocks = HipTest::setNumBlocks(blocksPerCU, threadsPerBlock, numElements);
|
||||
|
||||
assert (numElements <= dmem->maxNumElements());
|
||||
assert (numElements <= hmem->maxNumElements());
|
||||
|
||||
assert(numElements <= dmem->maxNumElements());
|
||||
assert(numElements <= hmem->maxNumElements());
|
||||
|
||||
|
||||
if (useHostToHost) {
|
||||
// Do some extra host-to-host copies here to mix things up:
|
||||
HIPCHECK ( hipMemcpy(hmem->A_hh, hmem->A_h(), sizeElements, useMemkindDefault? hipMemcpyDefault : hipMemcpyHostToHost));
|
||||
HIPCHECK ( hipMemcpy(hmem->B_hh, hmem->B_h(), sizeElements, useMemkindDefault? hipMemcpyDefault : hipMemcpyHostToHost));
|
||||
HIPCHECK(hipMemcpy(hmem->A_hh, hmem->A_h(), sizeElements,
|
||||
useMemkindDefault ? hipMemcpyDefault : hipMemcpyHostToHost));
|
||||
HIPCHECK(hipMemcpy(hmem->B_hh, hmem->B_h(), sizeElements,
|
||||
useMemkindDefault ? hipMemcpyDefault : hipMemcpyHostToHost));
|
||||
|
||||
|
||||
HIPCHECK ( hipMemcpy(dmem->A_d(), hmem->A_hh, sizeElements, useMemkindDefault ? hipMemcpyDefault : hipMemcpyHostToDevice));
|
||||
HIPCHECK ( hipMemcpy(dmem->B_d(), hmem->B_hh, sizeElements, useMemkindDefault ? hipMemcpyDefault : hipMemcpyHostToDevice));
|
||||
HIPCHECK(hipMemcpy(dmem->A_d(), hmem->A_hh, sizeElements,
|
||||
useMemkindDefault ? hipMemcpyDefault : hipMemcpyHostToDevice));
|
||||
HIPCHECK(hipMemcpy(dmem->B_d(), hmem->B_hh, sizeElements,
|
||||
useMemkindDefault ? hipMemcpyDefault : hipMemcpyHostToDevice));
|
||||
} else {
|
||||
HIPCHECK ( hipMemcpy(dmem->A_d(), hmem->A_h(), sizeElements, useMemkindDefault ? hipMemcpyDefault : hipMemcpyHostToDevice));
|
||||
HIPCHECK ( hipMemcpy(dmem->B_d(), hmem->B_h(), sizeElements, useMemkindDefault ? hipMemcpyDefault : hipMemcpyHostToDevice));
|
||||
HIPCHECK(hipMemcpy(dmem->A_d(), hmem->A_h(), sizeElements,
|
||||
useMemkindDefault ? hipMemcpyDefault : hipMemcpyHostToDevice));
|
||||
HIPCHECK(hipMemcpy(dmem->B_d(), hmem->B_h(), sizeElements,
|
||||
useMemkindDefault ? hipMemcpyDefault : hipMemcpyHostToDevice));
|
||||
}
|
||||
|
||||
hipLaunchKernel(
|
||||
HipTest::vectorADD,
|
||||
dim3(blocks),
|
||||
dim3(threadsPerBlock),
|
||||
0,
|
||||
0,
|
||||
static_cast<const T*>(dmem->A_d()),
|
||||
static_cast<const T*>(dmem->B_d()),
|
||||
dmem->C_d(),
|
||||
numElements);
|
||||
hipLaunchKernel(HipTest::vectorADD, dim3(blocks), dim3(threadsPerBlock), 0, 0,
|
||||
static_cast<const T*>(dmem->A_d()), static_cast<const T*>(dmem->B_d()),
|
||||
dmem->C_d(), numElements);
|
||||
|
||||
if (useDeviceToDevice) {
|
||||
// Do an extra device-to-device copy here to mix things up:
|
||||
HIPCHECK ( hipMemcpy(dmem->C_dd(), dmem->C_d(), sizeElements, useMemkindDefault? hipMemcpyDefault : hipMemcpyDeviceToDevice));
|
||||
HIPCHECK(hipMemcpy(dmem->C_dd(), dmem->C_d(), sizeElements,
|
||||
useMemkindDefault ? hipMemcpyDefault : hipMemcpyDeviceToDevice));
|
||||
|
||||
//Destroy the original dmem->C_d():
|
||||
HIPCHECK ( hipMemset(dmem->C_d(), 0x5A, sizeElements));
|
||||
// Destroy the original dmem->C_d():
|
||||
HIPCHECK(hipMemset(dmem->C_d(), 0x5A, sizeElements));
|
||||
|
||||
HIPCHECK ( hipMemcpy(hmem->C_h(), dmem->C_dd(), sizeElements, useMemkindDefault? hipMemcpyDefault:hipMemcpyDeviceToHost));
|
||||
HIPCHECK(hipMemcpy(hmem->C_h(), dmem->C_dd(), sizeElements,
|
||||
useMemkindDefault ? hipMemcpyDefault : hipMemcpyDeviceToHost));
|
||||
} else {
|
||||
HIPCHECK ( hipMemcpy(hmem->C_h(), dmem->C_d(), sizeElements, useMemkindDefault? hipMemcpyDefault:hipMemcpyDeviceToHost));
|
||||
HIPCHECK(hipMemcpy(hmem->C_h(), dmem->C_d(), sizeElements,
|
||||
useMemkindDefault ? hipMemcpyDefault : hipMemcpyDeviceToHost));
|
||||
}
|
||||
|
||||
HIPCHECK ( hipDeviceSynchronize() );
|
||||
HIPCHECK(hipDeviceSynchronize());
|
||||
HipTest::checkVectorADD(hmem->A_h(), hmem->B_h(), hmem->C_h(), numElements);
|
||||
|
||||
|
||||
|
||||
printf (" %s success\n", __func__);
|
||||
printf(" %s success\n", __func__);
|
||||
}
|
||||
|
||||
|
||||
//---
|
||||
//Try all the 16 possible combinations to memcpytest2 - usePinnedHost, useHostToHost, useDeviceToDevice, useMemkindDefault
|
||||
template<typename T>
|
||||
void memcpytest2_for_type(size_t numElements)
|
||||
{
|
||||
// Try all the 16 possible combinations to memcpytest2 - usePinnedHost, useHostToHost,
|
||||
// useDeviceToDevice, useMemkindDefault
|
||||
template <typename T>
|
||||
void memcpytest2_for_type(size_t numElements) {
|
||||
printSep();
|
||||
|
||||
DeviceMemory<T> memD(numElements);
|
||||
HostMemory<T> memU(numElements, 0/*usePinnedHost*/);
|
||||
HostMemory<T> memP(numElements, 1/*usePinnedHost*/);
|
||||
HostMemory<T> memU(numElements, 0 /*usePinnedHost*/);
|
||||
HostMemory<T> memP(numElements, 1 /*usePinnedHost*/);
|
||||
|
||||
for (int usePinnedHost =0; usePinnedHost<=1; usePinnedHost++) {
|
||||
for (int useHostToHost =0; useHostToHost<=1; useHostToHost++) { // TODO
|
||||
for (int useDeviceToDevice =0; useDeviceToDevice<=1; useDeviceToDevice++) {
|
||||
for (int useMemkindDefault =0; useMemkindDefault<=1; useMemkindDefault++) {
|
||||
memcpytest2<T>(&memD, usePinnedHost ? &memP : &memU, numElements, useHostToHost, useDeviceToDevice, useMemkindDefault);
|
||||
for (int usePinnedHost = 0; usePinnedHost <= 1; usePinnedHost++) {
|
||||
for (int useHostToHost = 0; useHostToHost <= 1; useHostToHost++) { // TODO
|
||||
for (int useDeviceToDevice = 0; useDeviceToDevice <= 1; useDeviceToDevice++) {
|
||||
for (int useMemkindDefault = 0; useMemkindDefault <= 1; useMemkindDefault++) {
|
||||
memcpytest2<T>(&memD, usePinnedHost ? &memP : &memU, numElements, useHostToHost,
|
||||
useDeviceToDevice, useMemkindDefault);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -297,12 +282,11 @@ void memcpytest2_for_type(size_t numElements)
|
||||
|
||||
|
||||
//---
|
||||
//Try many different sizes to memory copy.
|
||||
template<typename T>
|
||||
void memcpytest2_sizes(size_t maxElem=0)
|
||||
{
|
||||
// Try many different sizes to memory copy.
|
||||
template <typename T>
|
||||
void memcpytest2_sizes(size_t maxElem = 0) {
|
||||
printSep();
|
||||
printf ("test: %s<%s>\n", __func__, TYPENAME(T));
|
||||
printf("test: %s<%s>\n", __func__, TYPENAME(T));
|
||||
|
||||
int deviceId;
|
||||
HIPCHECK(hipGetDevice(&deviceId));
|
||||
@@ -311,17 +295,19 @@ void memcpytest2_sizes(size_t maxElem=0)
|
||||
HIPCHECK(hipMemGetInfo(&free, &total));
|
||||
|
||||
if (maxElem == 0) {
|
||||
maxElem = free/sizeof(T)/8;
|
||||
maxElem = free / sizeof(T) / 8;
|
||||
}
|
||||
|
||||
printf (" device#%d: hipMemGetInfo: free=%zu (%4.2fMB) total=%zu (%4.2fMB) maxSize=%6.1fMB\n",
|
||||
deviceId, free, (float)(free/1024.0/1024.0), total, (float)(total/1024.0/1024.0), maxElem*sizeof(T)/1024.0/1024.0);
|
||||
HIPCHECK ( hipDeviceReset() );
|
||||
printf(
|
||||
" device#%d: hipMemGetInfo: free=%zu (%4.2fMB) total=%zu (%4.2fMB) maxSize=%6.1fMB\n",
|
||||
deviceId, free, (float)(free / 1024.0 / 1024.0), total, (float)(total / 1024.0 / 1024.0),
|
||||
maxElem * sizeof(T) / 1024.0 / 1024.0);
|
||||
HIPCHECK(hipDeviceReset());
|
||||
DeviceMemory<T> memD(maxElem);
|
||||
HostMemory<T> memU(maxElem, 0/*usePinnedHost*/);
|
||||
HostMemory<T> memP(maxElem, 1/*usePinnedHost*/);
|
||||
HostMemory<T> memU(maxElem, 0 /*usePinnedHost*/);
|
||||
HostMemory<T> memP(maxElem, 1 /*usePinnedHost*/);
|
||||
|
||||
for (size_t elem=1; elem<=maxElem; elem*=2) {
|
||||
for (size_t elem = 1; elem <= maxElem; elem *= 2) {
|
||||
memcpytest2<T>(&memD, &memU, elem, 1, 1, 0); // unpinned host
|
||||
memcpytest2<T>(&memD, &memP, elem, 1, 1, 0); // pinned host
|
||||
}
|
||||
@@ -329,12 +315,11 @@ void memcpytest2_sizes(size_t maxElem=0)
|
||||
|
||||
|
||||
//---
|
||||
//Try many different sizes to memory copy.
|
||||
template<typename T>
|
||||
void memcpytest2_offsets(size_t maxElem, bool devOffsets, bool hostOffsets)
|
||||
{
|
||||
// Try many different sizes to memory copy.
|
||||
template <typename T>
|
||||
void memcpytest2_offsets(size_t maxElem, bool devOffsets, bool hostOffsets) {
|
||||
printSep();
|
||||
printf ("test: %s<%s>\n", __func__, TYPENAME(T));
|
||||
printf("test: %s<%s>\n", __func__, TYPENAME(T));
|
||||
|
||||
int deviceId;
|
||||
HIPCHECK(hipGetDevice(&deviceId));
|
||||
@@ -343,17 +328,19 @@ void memcpytest2_offsets(size_t maxElem, bool devOffsets, bool hostOffsets)
|
||||
HIPCHECK(hipMemGetInfo(&free, &total));
|
||||
|
||||
|
||||
printf (" device#%d: hipMemGetInfo: free=%zu (%4.2fMB) total=%zu (%4.2fMB) maxSize=%6.1fMB\n",
|
||||
deviceId, free, (float)(free/1024.0/1024.0), total, (float)(total/1024.0/1024.0), maxElem*sizeof(T)/1024.0/1024.0);
|
||||
HIPCHECK ( hipDeviceReset() );
|
||||
printf(
|
||||
" device#%d: hipMemGetInfo: free=%zu (%4.2fMB) total=%zu (%4.2fMB) maxSize=%6.1fMB\n",
|
||||
deviceId, free, (float)(free / 1024.0 / 1024.0), total, (float)(total / 1024.0 / 1024.0),
|
||||
maxElem * sizeof(T) / 1024.0 / 1024.0);
|
||||
HIPCHECK(hipDeviceReset());
|
||||
DeviceMemory<T> memD(maxElem);
|
||||
HostMemory<T> memU(maxElem, 0/*usePinnedHost*/);
|
||||
HostMemory<T> memP(maxElem, 1/*usePinnedHost*/);
|
||||
HostMemory<T> memU(maxElem, 0 /*usePinnedHost*/);
|
||||
HostMemory<T> memP(maxElem, 1 /*usePinnedHost*/);
|
||||
|
||||
size_t elem = maxElem / 2;
|
||||
|
||||
for (int offset=0; offset < 512; offset++) {
|
||||
assert (elem + offset < maxElem);
|
||||
for (int offset = 0; offset < 512; offset++) {
|
||||
assert(elem + offset < maxElem);
|
||||
if (devOffsets) {
|
||||
memD.offset(offset);
|
||||
}
|
||||
@@ -365,8 +352,8 @@ void memcpytest2_offsets(size_t maxElem, bool devOffsets, bool hostOffsets)
|
||||
memcpytest2<T>(&memD, &memP, elem, 1, 1, 0); // pinned host
|
||||
}
|
||||
|
||||
for (int offset=512; offset < elem; offset*=2) {
|
||||
assert (elem + offset < maxElem);
|
||||
for (int offset = 512; offset < elem; offset *= 2) {
|
||||
assert(elem + offset < maxElem);
|
||||
if (devOffsets) {
|
||||
memD.offset(offset);
|
||||
}
|
||||
@@ -381,23 +368,24 @@ void memcpytest2_offsets(size_t maxElem, bool devOffsets, bool hostOffsets)
|
||||
|
||||
|
||||
//---
|
||||
//Create multiple threads to stress multi-thread locking behavior in the allocation/deallocation/tracking logic:
|
||||
template<typename T>
|
||||
void multiThread_1(bool serialize, bool usePinnedHost)
|
||||
{
|
||||
// Create multiple threads to stress multi-thread locking behavior in the
|
||||
// allocation/deallocation/tracking logic:
|
||||
template <typename T>
|
||||
void multiThread_1(bool serialize, bool usePinnedHost) {
|
||||
printSep();
|
||||
printf ("test: %s<%s> serialize=%d usePinnedHost=%d\n", __func__, TYPENAME(T), serialize, usePinnedHost);
|
||||
printf("test: %s<%s> serialize=%d usePinnedHost=%d\n", __func__, TYPENAME(T), serialize,
|
||||
usePinnedHost);
|
||||
DeviceMemory<T> memD(N);
|
||||
HostMemory<T> mem1(N, usePinnedHost);
|
||||
HostMemory<T> mem2(N, usePinnedHost);
|
||||
|
||||
std::thread t1 (memcpytest2<T>, &memD, &mem1, N, 0,0,0);
|
||||
std::thread t1(memcpytest2<T>, &memD, &mem1, N, 0, 0, 0);
|
||||
if (serialize) {
|
||||
t1.join();
|
||||
}
|
||||
|
||||
|
||||
std::thread t2 (memcpytest2<T>,&memD, &mem2, N, 0,0,0);
|
||||
std::thread t2(memcpytest2<T>, &memD, &mem2, N, 0, 0, 0);
|
||||
if (serialize) {
|
||||
t2.join();
|
||||
}
|
||||
@@ -409,64 +397,57 @@ void multiThread_1(bool serialize, bool usePinnedHost)
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int main(int argc, char* argv[]) {
|
||||
HipTest::parseStandardArguments(argc, argv, true);
|
||||
|
||||
printf ("info: set device to %d\n", p_gpuDevice);
|
||||
printf("info: set device to %d\n", p_gpuDevice);
|
||||
HIPCHECK(hipSetDevice(p_gpuDevice));
|
||||
|
||||
|
||||
if (p_tests & 0x1) {
|
||||
printf ("\n\n=== tests&1 (types and different memcpy kinds (H2D, D2H, H2H, D2D)\n");
|
||||
HIPCHECK ( hipDeviceReset() );
|
||||
printf("\n\n=== tests&1 (types and different memcpy kinds (H2D, D2H, H2H, D2D)\n");
|
||||
HIPCHECK(hipDeviceReset());
|
||||
memcpytest2_for_type<float>(N);
|
||||
memcpytest2_for_type<double>(N);
|
||||
memcpytest2_for_type<char>(N);
|
||||
memcpytest2_for_type<int>(N);
|
||||
printf ("===\n\n\n");
|
||||
printf("===\n\n\n");
|
||||
}
|
||||
|
||||
|
||||
if (p_tests & 0x2) {
|
||||
// Some tests around the 64KB boundary which have historically shown issues:
|
||||
printf ("\n\n=== tests&0x2 (64KB boundary)\n");
|
||||
size_t maxElem = 32*1024*1024;
|
||||
printf("\n\n=== tests&0x2 (64KB boundary)\n");
|
||||
size_t maxElem = 32 * 1024 * 1024;
|
||||
DeviceMemory<float> memD(maxElem);
|
||||
HostMemory<float> memU(maxElem, 0/*usePinnedHost*/);
|
||||
HostMemory<float> memP(maxElem, 0/*usePinnedHost*/);
|
||||
HostMemory<float> memU(maxElem, 0 /*usePinnedHost*/);
|
||||
HostMemory<float> memP(maxElem, 0 /*usePinnedHost*/);
|
||||
// These all pass:
|
||||
memcpytest2<float>(&memD, &memP, 15*1024*1024, 0, 0, 0);
|
||||
memcpytest2<float>(&memD, &memP, 16*1024*1024, 0, 0, 0);
|
||||
memcpytest2<float>(&memD, &memP, 16*1024*1024+16*1024, 0, 0, 0);
|
||||
memcpytest2<float>(&memD, &memP, 15 * 1024 * 1024, 0, 0, 0);
|
||||
memcpytest2<float>(&memD, &memP, 16 * 1024 * 1024, 0, 0, 0);
|
||||
memcpytest2<float>(&memD, &memP, 16 * 1024 * 1024 + 16 * 1024, 0, 0, 0);
|
||||
|
||||
// Just over 64MB:
|
||||
memcpytest2<float>(&memD, &memP, 16*1024*1024+512*1024, 0, 0, 0);
|
||||
memcpytest2<float>(&memD, &memP, 17*1024*1024+1024, 0, 0, 0);
|
||||
memcpytest2<float>(&memD, &memP, 32*1024*1024, 0, 0, 0);
|
||||
memcpytest2<float>(&memD, &memU, 32*1024*1024, 0, 0, 0);
|
||||
memcpytest2<float>(&memD, &memP, 32*1024*1024, 1, 1, 0);
|
||||
memcpytest2<float>(&memD, &memP, 32*1024*1024, 1, 1, 0);
|
||||
|
||||
|
||||
memcpytest2<float>(&memD, &memP, 16 * 1024 * 1024 + 512 * 1024, 0, 0, 0);
|
||||
memcpytest2<float>(&memD, &memP, 17 * 1024 * 1024 + 1024, 0, 0, 0);
|
||||
memcpytest2<float>(&memD, &memP, 32 * 1024 * 1024, 0, 0, 0);
|
||||
memcpytest2<float>(&memD, &memU, 32 * 1024 * 1024, 0, 0, 0);
|
||||
memcpytest2<float>(&memD, &memP, 32 * 1024 * 1024, 1, 1, 0);
|
||||
memcpytest2<float>(&memD, &memP, 32 * 1024 * 1024, 1, 1, 0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (p_tests & 0x4) {
|
||||
printf ("\n\n=== tests&4 (test sizes)\n");
|
||||
HIPCHECK ( hipDeviceReset() );
|
||||
printf("\n\n=== tests&4 (test sizes)\n");
|
||||
HIPCHECK(hipDeviceReset());
|
||||
memcpytest2_sizes<float>(0);
|
||||
printSep();
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (p_tests & 0x8) {
|
||||
printf ("\n\n=== tests&8\n");
|
||||
HIPCHECK ( hipDeviceReset() );
|
||||
printf("\n\n=== tests&8\n");
|
||||
HIPCHECK(hipDeviceReset());
|
||||
printSep();
|
||||
|
||||
// Simplest cases: serialize the threads, and also used pinned memory:
|
||||
@@ -480,32 +461,30 @@ int main(int argc, char *argv[])
|
||||
multiThread_1<float>(false, true);
|
||||
|
||||
// Remove serialization, and use unpinned.
|
||||
multiThread_1<float>(false, false); // TODO
|
||||
printf ("===\n\n\n");
|
||||
multiThread_1<float>(false, false); // TODO
|
||||
printf("===\n\n\n");
|
||||
}
|
||||
|
||||
|
||||
if (p_tests & 0x10) {
|
||||
printf ("\n\n=== tests&0x10 (test device offsets)\n");
|
||||
HIPCHECK ( hipDeviceReset() );
|
||||
size_t maxSize = 256*1024;
|
||||
memcpytest2_offsets<char> (maxSize, true, false);
|
||||
memcpytest2_offsets<float> (maxSize, true, false);
|
||||
printf("\n\n=== tests&0x10 (test device offsets)\n");
|
||||
HIPCHECK(hipDeviceReset());
|
||||
size_t maxSize = 256 * 1024;
|
||||
memcpytest2_offsets<char>(maxSize, true, false);
|
||||
memcpytest2_offsets<float>(maxSize, true, false);
|
||||
memcpytest2_offsets<double>(maxSize, true, false);
|
||||
}
|
||||
|
||||
|
||||
if (p_tests & 0x20) {
|
||||
printf ("\n\n=== tests&0x10 (test device offsets)\n");
|
||||
HIPCHECK ( hipDeviceReset() );
|
||||
size_t maxSize = 256*1024;
|
||||
memcpytest2_offsets<char> (maxSize, false, true);
|
||||
memcpytest2_offsets<float> (maxSize, false, true);
|
||||
printf("\n\n=== tests&0x10 (test device offsets)\n");
|
||||
HIPCHECK(hipDeviceReset());
|
||||
size_t maxSize = 256 * 1024;
|
||||
memcpytest2_offsets<char>(maxSize, false, true);
|
||||
memcpytest2_offsets<float>(maxSize, false, true);
|
||||
memcpytest2_offsets<double>(maxSize, false, true);
|
||||
}
|
||||
|
||||
|
||||
|
||||
passed();
|
||||
|
||||
}
|
||||
|
||||
@@ -23,112 +23,106 @@ THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "hip/hip_runtime.h"
|
||||
#include<iostream>
|
||||
#include<assert.h>
|
||||
#include"test_common.h"
|
||||
#include <iostream>
|
||||
#include <assert.h>
|
||||
#include "test_common.h"
|
||||
|
||||
#define len 1024*1024
|
||||
#define len 1024 * 1024
|
||||
#define size len * sizeof(float)
|
||||
|
||||
template<typename T>
|
||||
void hmemset(T *ptr, T value)
|
||||
{
|
||||
for(int i=0;i<len;i++){
|
||||
ptr[i] = value;
|
||||
}
|
||||
template <typename T>
|
||||
void hmemset(T* ptr, T value) {
|
||||
for (int i = 0; i < len; i++) {
|
||||
ptr[i] = value;
|
||||
}
|
||||
}
|
||||
|
||||
int main(){
|
||||
int main() {
|
||||
int num;
|
||||
hipGetDeviceCount(&num);
|
||||
if (num < 2) {
|
||||
printf("warning: Not enough GPUs to run the test, exiting without running.\n");
|
||||
passed();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int num;
|
||||
hipGetDeviceCount(&num);
|
||||
if(num < 2)
|
||||
{
|
||||
printf ("warning: Not enough GPUs to run the test, exiting without running.\n");
|
||||
float *h0, *h1;
|
||||
float *ph0, *ph1;
|
||||
float *d0, *d1;
|
||||
h0 = new float[len];
|
||||
h1 = new float[len];
|
||||
hmemset(h0, 1.0f);
|
||||
int gpu0 = 0, gpu1 = 1;
|
||||
hipSetDevice(gpu0);
|
||||
hipHostMalloc((void**)&ph0, size);
|
||||
hipMalloc(&d0, size);
|
||||
hipSetDevice(gpu1);
|
||||
hipHostMalloc((void**)&ph1, size);
|
||||
hipMalloc(&d1, size);
|
||||
hipSetDevice(gpu0);
|
||||
|
||||
|
||||
hipMemcpy(h1, h0, size, hipMemcpyDefault);
|
||||
hipMemcpy(ph0, h1, size, hipMemcpyDefault);
|
||||
hipMemcpy(ph1, ph0, size, hipMemcpyDefault);
|
||||
assert(h0[0] == ph1[0]);
|
||||
hmemset(ph1, 0.0f);
|
||||
hipMemcpy(h0, ph1, size, hipMemcpyDefault);
|
||||
assert(h0[0] == 0.0f);
|
||||
|
||||
|
||||
hipSetDevice(gpu0);
|
||||
hmemset(ph0, 2.0f);
|
||||
hipMemcpy(d0, ph0, size, hipMemcpyDefault);
|
||||
hipMemcpy(h0, d0, size, hipMemcpyDefault);
|
||||
|
||||
assert(h0[0] == ph0[0]);
|
||||
hmemset(h0, 3.0f);
|
||||
hipMemcpy(d0, h0, size, hipMemcpyDefault);
|
||||
|
||||
hipMemcpy(ph0, d0, size, hipMemcpyDefault);
|
||||
|
||||
assert(h0[0] == ph0[0]);
|
||||
|
||||
hipSetDevice(gpu1);
|
||||
hmemset(ph1, 2.0f);
|
||||
hipMemcpy(d1, ph1, size, hipMemcpyDefault);
|
||||
|
||||
hipMemcpy(h1, d1, size, hipMemcpyDefault);
|
||||
|
||||
assert(h1[0] == ph1[0]);
|
||||
hmemset(h1, 3.0f);
|
||||
hipMemcpy(d1, h1, size, hipMemcpyDefault);
|
||||
|
||||
hipMemcpy(ph1, d1, size, hipMemcpyDefault);
|
||||
|
||||
assert(h1[0] == ph1[0]);
|
||||
|
||||
hipSetDevice(gpu0);
|
||||
hmemset(ph0, 4.0f);
|
||||
hipMemcpy(d0, ph0, size, hipMemcpyDefault);
|
||||
|
||||
hipMemcpy(ph0, d0, size, hipMemcpyDefault);
|
||||
|
||||
hipMemcpy(h0, d0, size, hipMemcpyDefault);
|
||||
|
||||
assert(ph0[0] == 4.0f);
|
||||
assert(h0[0] == 4.0f);
|
||||
|
||||
hipSetDevice(gpu1);
|
||||
hmemset(ph1, 5.0f);
|
||||
hipMemcpy(d1, ph1, size, hipMemcpyDefault);
|
||||
|
||||
hipMemcpy(ph1, d1, size, hipMemcpyDefault);
|
||||
|
||||
hipMemcpy(h1, d1, size, hipMemcpyDefault);
|
||||
|
||||
assert(ph1[0] == 5.0f);
|
||||
assert(h1[0] == 5.0f);
|
||||
|
||||
hipSetDevice(gpu0);
|
||||
hipMemcpy(d0, ph1, size, hipMemcpyDefault);
|
||||
|
||||
hipMemcpy(d1, d0, size, hipMemcpyDefault);
|
||||
passed();
|
||||
return 0;
|
||||
}
|
||||
|
||||
float *h0, *h1;
|
||||
float *ph0, *ph1;
|
||||
float *d0, *d1;
|
||||
h0 = new float[len];
|
||||
h1 = new float[len];
|
||||
hmemset(h0, 1.0f);
|
||||
int gpu0 = 0, gpu1 = 1;
|
||||
hipSetDevice(gpu0);
|
||||
hipHostMalloc((void**)&ph0, size);
|
||||
hipMalloc(&d0, size);
|
||||
hipSetDevice(gpu1);
|
||||
hipHostMalloc((void**)&ph1, size);
|
||||
hipMalloc(&d1, size);
|
||||
hipSetDevice(gpu0);
|
||||
|
||||
|
||||
|
||||
hipMemcpy(h1, h0, size, hipMemcpyDefault);
|
||||
hipMemcpy(ph0, h1, size, hipMemcpyDefault);
|
||||
hipMemcpy(ph1, ph0, size, hipMemcpyDefault);
|
||||
assert(h0[0] == ph1[0]);
|
||||
hmemset(ph1, 0.0f);
|
||||
hipMemcpy(h0, ph1, size, hipMemcpyDefault);
|
||||
assert(h0[0] == 0.0f);
|
||||
|
||||
|
||||
|
||||
|
||||
hipSetDevice(gpu0);
|
||||
hmemset(ph0, 2.0f);
|
||||
hipMemcpy(d0, ph0, size, hipMemcpyDefault);
|
||||
hipMemcpy(h0, d0, size, hipMemcpyDefault);
|
||||
|
||||
assert(h0[0] == ph0[0]);
|
||||
hmemset(h0, 3.0f);
|
||||
hipMemcpy(d0, h0, size, hipMemcpyDefault);
|
||||
|
||||
hipMemcpy(ph0, d0, size, hipMemcpyDefault);
|
||||
|
||||
assert(h0[0] == ph0[0]);
|
||||
|
||||
hipSetDevice(gpu1);
|
||||
hmemset(ph1, 2.0f);
|
||||
hipMemcpy(d1, ph1, size, hipMemcpyDefault);
|
||||
|
||||
hipMemcpy(h1, d1, size, hipMemcpyDefault);
|
||||
|
||||
assert(h1[0] == ph1[0]);
|
||||
hmemset(h1, 3.0f);
|
||||
hipMemcpy(d1, h1, size, hipMemcpyDefault);
|
||||
|
||||
hipMemcpy(ph1, d1, size, hipMemcpyDefault);
|
||||
|
||||
assert(h1[0] == ph1[0]);
|
||||
|
||||
hipSetDevice(gpu0);
|
||||
hmemset(ph0, 4.0f);
|
||||
hipMemcpy(d0, ph0, size, hipMemcpyDefault);
|
||||
|
||||
hipMemcpy(ph0, d0, size, hipMemcpyDefault);
|
||||
|
||||
hipMemcpy(h0, d0, size, hipMemcpyDefault);
|
||||
|
||||
assert(ph0[0] == 4.0f);
|
||||
assert(h0[0] == 4.0f);
|
||||
|
||||
hipSetDevice(gpu1);
|
||||
hmemset(ph1, 5.0f);
|
||||
hipMemcpy(d1, ph1, size, hipMemcpyDefault);
|
||||
|
||||
hipMemcpy(ph1, d1, size, hipMemcpyDefault);
|
||||
|
||||
hipMemcpy(h1, d1, size, hipMemcpyDefault);
|
||||
|
||||
assert(ph1[0] == 5.0f);
|
||||
assert(h1[0] == 5.0f);
|
||||
|
||||
hipSetDevice(gpu0);
|
||||
hipMemcpy(d0, ph1, size, hipMemcpyDefault);
|
||||
|
||||
hipMemcpy(d1, d0, size, hipMemcpyDefault);
|
||||
passed();
|
||||
}
|
||||
|
||||
@@ -24,13 +24,12 @@ THE SOFTWARE.
|
||||
unsigned p_streams = 2;
|
||||
|
||||
|
||||
void simpleNegTest()
|
||||
{
|
||||
printf ("testing: %s\n",__func__);
|
||||
void simpleNegTest() {
|
||||
printf("testing: %s\n", __func__);
|
||||
hipError_t e;
|
||||
float *A_malloc, *A_pinned, *A_d;
|
||||
|
||||
size_t Nbytes = N*sizeof(float);
|
||||
size_t Nbytes = N * sizeof(float);
|
||||
A_malloc = (float*)malloc(Nbytes);
|
||||
HIPCHECK(hipHostMalloc((void**)&A_pinned, Nbytes, hipHostMallocDefault));
|
||||
A_d = NULL;
|
||||
@@ -38,68 +37,70 @@ void simpleNegTest()
|
||||
HIPASSERT(A_d != NULL);
|
||||
// Can't use default with async copy
|
||||
e = hipMemcpyAsync(A_pinned, A_d, Nbytes, hipMemcpyDefault, NULL);
|
||||
// HIPASSERT (e == hipSuccess);
|
||||
// HIPASSERT (e == hipSuccess);
|
||||
|
||||
|
||||
// Not sure what happens here, the memory must be pinned.
|
||||
e = hipMemcpyAsync(A_malloc, A_d, Nbytes, hipMemcpyHostToDevice, NULL);
|
||||
|
||||
printf (" async memcpy of A_malloc to A_d. Result=%d\n", e);
|
||||
//HIPASSERT (e==hipErrorInvalidValue);
|
||||
printf(" async memcpy of A_malloc to A_d. Result=%d\n", e);
|
||||
// HIPASSERT (e==hipErrorInvalidValue);
|
||||
}
|
||||
|
||||
class Pinned;
|
||||
class Unpinned;
|
||||
|
||||
template <typename T> struct HostTraits;
|
||||
template <typename T>
|
||||
struct HostTraits;
|
||||
|
||||
template<>
|
||||
struct HostTraits<Pinned>
|
||||
{
|
||||
static const char *Name() { return "Pinned"; } ;
|
||||
template <>
|
||||
struct HostTraits<Pinned> {
|
||||
static const char* Name() { return "Pinned"; };
|
||||
|
||||
static void *Alloc(size_t sizeBytes) {
|
||||
void *p;
|
||||
static void* Alloc(size_t sizeBytes) {
|
||||
void* p;
|
||||
HIPCHECK(hipHostMalloc((void**)&p, sizeBytes, hipHostMallocDefault));
|
||||
return p;
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
template<typename T>
|
||||
__global__ void
|
||||
addK (hipLaunchParm lp, T *A, T K, size_t numElements)
|
||||
{
|
||||
template <typename T>
|
||||
__global__ void addK(hipLaunchParm lp, T* A, T K, size_t numElements) {
|
||||
size_t offset = (blockIdx.x * blockDim.x + threadIdx.x);
|
||||
size_t stride = blockDim.x * gridDim.x ;
|
||||
size_t stride = blockDim.x * gridDim.x;
|
||||
|
||||
for (size_t i=offset; i<numElements; i+=stride) {
|
||||
for (size_t i = offset; i < numElements; i += stride) {
|
||||
A[i] = A[i] + K;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
//---
|
||||
//Tests propert dependency resolution between H2D and D2H commands in same stream:
|
||||
//IN: numInflight : number of copies inflight at any time:
|
||||
//IN: numPongs = number of iterations to run (iteration)
|
||||
template<typename T, class AllocType>
|
||||
void test_pingpong(hipStream_t stream, size_t numElements, int numInflight, int numPongs, bool doHostSide)
|
||||
{
|
||||
HIPASSERT(numElements % numInflight == 0); // Must be evenly divisible.
|
||||
size_t Nbytes = numElements*sizeof(T);
|
||||
// Tests propert dependency resolution between H2D and D2H commands in same stream:
|
||||
// IN: numInflight : number of copies inflight at any time:
|
||||
// IN: numPongs = number of iterations to run (iteration)
|
||||
template <typename T, class AllocType>
|
||||
void test_pingpong(hipStream_t stream, size_t numElements, int numInflight, int numPongs,
|
||||
bool doHostSide) {
|
||||
HIPASSERT(numElements % numInflight == 0); // Must be evenly divisible.
|
||||
size_t Nbytes = numElements * sizeof(T);
|
||||
size_t eachCopyElements = numElements / numInflight;
|
||||
size_t eachCopyBytes = eachCopyElements * sizeof(T);
|
||||
|
||||
unsigned blocks = HipTest::setNumBlocks(blocksPerCU, threadsPerBlock, numElements);
|
||||
|
||||
printf ("-----------------------------------------------------------------------------------------------\n");
|
||||
printf ("testing: %s<%s> Nbytes=%zu (%6.1f MB) numPongs=%d numInflight=%d eachCopyElements=%zu eachCopyBytes=%zu\n",
|
||||
__func__, HostTraits<AllocType>::Name(), Nbytes, (double)(Nbytes)/1024.0/1024.0, numPongs, numInflight, eachCopyElements, eachCopyBytes);
|
||||
printf(
|
||||
"------------------------------------------------------------------------------------------"
|
||||
"-----\n");
|
||||
printf(
|
||||
"testing: %s<%s> Nbytes=%zu (%6.1f MB) numPongs=%d numInflight=%d eachCopyElements=%zu "
|
||||
"eachCopyBytes=%zu\n",
|
||||
__func__, HostTraits<AllocType>::Name(), Nbytes, (double)(Nbytes) / 1024.0 / 1024.0,
|
||||
numPongs, numInflight, eachCopyElements, eachCopyBytes);
|
||||
|
||||
T *A_h = NULL;
|
||||
T *A_d = NULL;
|
||||
T* A_h = NULL;
|
||||
T* A_d = NULL;
|
||||
|
||||
A_h = (T*)(HostTraits<AllocType>::Alloc(Nbytes));
|
||||
HIPCHECK(hipMalloc(&A_d, Nbytes));
|
||||
@@ -108,22 +109,25 @@ void test_pingpong(hipStream_t stream, size_t numElements, int numInflight, int
|
||||
const T initValue = 13;
|
||||
const T deviceConst = 2;
|
||||
const T hostConst = 10000;
|
||||
for (size_t i=0; i<numElements; i++) {
|
||||
for (size_t i = 0; i < numElements; i++) {
|
||||
A_h[i] = initValue + i;
|
||||
}
|
||||
|
||||
|
||||
for (int k=0; k<numPongs; k++ ) {
|
||||
for (int i=0; i<numInflight; i++) {
|
||||
HIPASSERT(A_d + i*eachCopyElements < A_d + Nbytes);
|
||||
HIPCHECK(hipMemcpyAsync(&A_d[i*eachCopyElements], &A_h[i*eachCopyElements], eachCopyBytes, hipMemcpyHostToDevice, stream));
|
||||
for (int k = 0; k < numPongs; k++) {
|
||||
for (int i = 0; i < numInflight; i++) {
|
||||
HIPASSERT(A_d + i * eachCopyElements < A_d + Nbytes);
|
||||
HIPCHECK(hipMemcpyAsync(&A_d[i * eachCopyElements], &A_h[i * eachCopyElements],
|
||||
eachCopyBytes, hipMemcpyHostToDevice, stream));
|
||||
}
|
||||
|
||||
hipLaunchKernel(addK<T>, dim3(blocks), dim3(threadsPerBlock), 0, stream, A_d, 2, numElements);
|
||||
hipLaunchKernel(addK<T>, dim3(blocks), dim3(threadsPerBlock), 0, stream, A_d, 2,
|
||||
numElements);
|
||||
|
||||
for (int i=0; i<numInflight; i++ ) {
|
||||
HIPASSERT(A_d + i*eachCopyElements < A_d + Nbytes);
|
||||
HIPCHECK(hipMemcpyAsync(&A_h[i*eachCopyElements], &A_d[i*eachCopyElements], eachCopyBytes, hipMemcpyDeviceToHost, stream));
|
||||
for (int i = 0; i < numInflight; i++) {
|
||||
HIPASSERT(A_d + i * eachCopyElements < A_d + Nbytes);
|
||||
HIPCHECK(hipMemcpyAsync(&A_h[i * eachCopyElements], &A_d[i * eachCopyElements],
|
||||
eachCopyBytes, hipMemcpyDeviceToHost, stream));
|
||||
}
|
||||
|
||||
if (doHostSide) {
|
||||
@@ -133,7 +137,7 @@ void test_pingpong(hipStream_t stream, size_t numElements, int numInflight, int
|
||||
HIPCHECK(hipEventCreate(&e));
|
||||
#endif
|
||||
HIPCHECK(hipDeviceSynchronize());
|
||||
for (size_t i=0; i<numElements; i++) {
|
||||
for (size_t i = 0; i < numElements; i++) {
|
||||
A_h[i] += hostConst;
|
||||
}
|
||||
}
|
||||
@@ -143,10 +147,10 @@ void test_pingpong(hipStream_t stream, size_t numElements, int numInflight, int
|
||||
|
||||
|
||||
// Verify we copied back all the data correctly:
|
||||
for (size_t i=0; i<numElements; i++) {
|
||||
for (size_t i = 0; i < numElements; i++) {
|
||||
T gold = initValue + i;
|
||||
// Perform calcs in same order as test above to replicate FP order-of-operations:
|
||||
for (int k=0; k<numPongs; k++) {
|
||||
for (int k = 0; k < numPongs; k++) {
|
||||
gold += deviceConst;
|
||||
if (doHostSide) {
|
||||
gold += hostConst;
|
||||
@@ -166,55 +170,60 @@ void test_pingpong(hipStream_t stream, size_t numElements, int numInflight, int
|
||||
|
||||
|
||||
//---
|
||||
//Send many async copies to the same stream.
|
||||
//This requires runtime to keep track of many outstanding commands, and in the case of HCC requires growing/tracking the signal pool:
|
||||
template<typename T>
|
||||
void test_manyInflightCopies(hipStream_t stream, int numElements, int numCopies, bool syncBetweenCopies)
|
||||
{
|
||||
size_t Nbytes = numElements*sizeof(T);
|
||||
// Send many async copies to the same stream.
|
||||
// This requires runtime to keep track of many outstanding commands, and in the case of HCC requires
|
||||
// growing/tracking the signal pool:
|
||||
template <typename T>
|
||||
void test_manyInflightCopies(hipStream_t stream, int numElements, int numCopies,
|
||||
bool syncBetweenCopies) {
|
||||
size_t Nbytes = numElements * sizeof(T);
|
||||
size_t eachCopyElements = numElements / numCopies;
|
||||
size_t eachCopyBytes = eachCopyElements * sizeof(T);
|
||||
|
||||
printf ("-----------------------------------------------------------------------------------------------\n");
|
||||
printf ("testing: %s Nbytes=%zu (%6.1f MB) numCopies=%d eachCopyElements=%zu eachCopyBytes=%zu\n",
|
||||
__func__, Nbytes, (double)(Nbytes)/1024.0/1024.0, numCopies, eachCopyElements, eachCopyBytes);
|
||||
printf(
|
||||
"------------------------------------------------------------------------------------------"
|
||||
"-----\n");
|
||||
printf(
|
||||
"testing: %s Nbytes=%zu (%6.1f MB) numCopies=%d eachCopyElements=%zu eachCopyBytes=%zu\n",
|
||||
__func__, Nbytes, (double)(Nbytes) / 1024.0 / 1024.0, numCopies, eachCopyElements,
|
||||
eachCopyBytes);
|
||||
|
||||
T *A_d;
|
||||
T* A_d;
|
||||
T *A_h1, *A_h2;
|
||||
|
||||
HIPCHECK(hipHostMalloc((void**)&A_h1, Nbytes, hipHostMallocDefault));
|
||||
HIPCHECK(hipHostMalloc((void**)&A_h2, Nbytes, hipHostMallocDefault));
|
||||
HIPCHECK(hipMalloc(&A_d, Nbytes));
|
||||
|
||||
for (int i=0; i<numElements; i++) {
|
||||
A_h1[i] = 3.14f + static_cast<T> (i);
|
||||
for (int i = 0; i < numElements; i++) {
|
||||
A_h1[i] = 3.14f + static_cast<T>(i);
|
||||
}
|
||||
|
||||
|
||||
//stream=0; // fixme TODO
|
||||
// stream=0; // fixme TODO
|
||||
|
||||
|
||||
for (int i=0; i<numCopies; i++)
|
||||
{
|
||||
HIPASSERT(A_d + i*eachCopyElements < A_d + Nbytes);
|
||||
HIPCHECK(hipMemcpyAsync(&A_d[i*eachCopyElements], &A_h1[i*eachCopyElements], eachCopyBytes, hipMemcpyHostToDevice, stream));
|
||||
for (int i = 0; i < numCopies; i++) {
|
||||
HIPASSERT(A_d + i * eachCopyElements < A_d + Nbytes);
|
||||
HIPCHECK(hipMemcpyAsync(&A_d[i * eachCopyElements], &A_h1[i * eachCopyElements],
|
||||
eachCopyBytes, hipMemcpyHostToDevice, stream));
|
||||
}
|
||||
|
||||
if (syncBetweenCopies) {
|
||||
HIPCHECK(hipDeviceSynchronize());
|
||||
}
|
||||
|
||||
for (int i=0; i<numCopies; i++)
|
||||
{
|
||||
HIPASSERT(A_d + i*eachCopyElements < A_d + Nbytes);
|
||||
HIPCHECK(hipMemcpyAsync(&A_h2[i*eachCopyElements], &A_d[i*eachCopyElements], eachCopyBytes, hipMemcpyDeviceToHost, stream));
|
||||
for (int i = 0; i < numCopies; i++) {
|
||||
HIPASSERT(A_d + i * eachCopyElements < A_d + Nbytes);
|
||||
HIPCHECK(hipMemcpyAsync(&A_h2[i * eachCopyElements], &A_d[i * eachCopyElements],
|
||||
eachCopyBytes, hipMemcpyDeviceToHost, stream));
|
||||
}
|
||||
|
||||
HIPCHECK(hipDeviceSynchronize());
|
||||
|
||||
|
||||
// Verify we copied back all the data correctly:
|
||||
for (int i=0; i<numElements; i++) {
|
||||
for (int i = 0; i < numElements; i++) {
|
||||
HIPASSERT(A_h1[i] == A_h2[i]);
|
||||
}
|
||||
|
||||
@@ -226,38 +235,38 @@ void test_manyInflightCopies(hipStream_t stream, int numElements, int numCopies,
|
||||
|
||||
|
||||
//---
|
||||
//Classic example showing how to overlap data transfer with compute.
|
||||
//We divide the work into "chunks" and create a stream for each chunk.
|
||||
//Each chunk then runs a H2D copy, followed by kernel execution, followed by D2H copyback.
|
||||
//Work in separate streams is independent which enables concurrency.
|
||||
// Classic example showing how to overlap data transfer with compute.
|
||||
// We divide the work into "chunks" and create a stream for each chunk.
|
||||
// Each chunk then runs a H2D copy, followed by kernel execution, followed by D2H copyback.
|
||||
// Work in separate streams is independent which enables concurrency.
|
||||
|
||||
// IN: nStreams : number of streams to use for the test
|
||||
// IN :useNullStream - use NULL stream. Synchronizes everything.
|
||||
// IN: useSyncMemcpyH2D - use sync memcpy (no overlap) for H2D
|
||||
// IN: useSyncMemcpyD2H - use sync memcpy (no overlap) for D2H
|
||||
void test_chunkedAsyncExample(int nStreams, bool useNullStream, bool useSyncMemcpyH2D, bool useSyncMemcpyD2H)
|
||||
{
|
||||
|
||||
size_t Nbytes = N*sizeof(int);
|
||||
printf ("testing: %s(useNullStream=%d, useSyncMemcpyH2D=%d, useSyncMemcpyD2H=%d) ",__func__, useNullStream, useSyncMemcpyH2D, useSyncMemcpyD2H);
|
||||
printf ("Nbytes=%zu (%6.1f MB)\n", Nbytes, (double)(Nbytes)/1024.0/1024.0);
|
||||
void test_chunkedAsyncExample(int nStreams, bool useNullStream, bool useSyncMemcpyH2D,
|
||||
bool useSyncMemcpyD2H) {
|
||||
size_t Nbytes = N * sizeof(int);
|
||||
printf("testing: %s(useNullStream=%d, useSyncMemcpyH2D=%d, useSyncMemcpyD2H=%d) ", __func__,
|
||||
useNullStream, useSyncMemcpyH2D, useSyncMemcpyD2H);
|
||||
printf("Nbytes=%zu (%6.1f MB)\n", Nbytes, (double)(Nbytes) / 1024.0 / 1024.0);
|
||||
|
||||
int *A_d, *B_d, *C_d;
|
||||
int *A_h, *B_h, *C_h;
|
||||
|
||||
HipTest::initArrays (&A_d, &B_d, &C_d, &A_h, &B_h, &C_h, N, true);
|
||||
HipTest::initArrays(&A_d, &B_d, &C_d, &A_h, &B_h, &C_h, N, true);
|
||||
|
||||
|
||||
unsigned blocks = HipTest::setNumBlocks(blocksPerCU, threadsPerBlock, N);
|
||||
|
||||
|
||||
hipStream_t *stream = (hipStream_t*)malloc(sizeof(hipStream_t) * nStreams);
|
||||
hipStream_t* stream = (hipStream_t*)malloc(sizeof(hipStream_t) * nStreams);
|
||||
if (useNullStream) {
|
||||
nStreams = 1;
|
||||
stream[0] = NULL;
|
||||
} else {
|
||||
} else {
|
||||
for (int i = 0; i < nStreams; ++i) {
|
||||
HIPCHECK (hipStreamCreate(&stream[i]));
|
||||
HIPCHECK(hipStreamCreate(&stream[i]));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -268,52 +277,55 @@ void test_chunkedAsyncExample(int nStreams, bool useNullStream, bool useSyncMemc
|
||||
size_t work = (workLeft < workPerStream) ? workLeft : workPerStream;
|
||||
size_t workBytes = work * sizeof(int);
|
||||
|
||||
size_t offset = i*workPerStream;
|
||||
size_t offset = i * workPerStream;
|
||||
HIPASSERT(A_d + offset < A_d + Nbytes);
|
||||
HIPASSERT(B_d + offset < B_d + Nbytes);
|
||||
HIPASSERT(C_d + offset < C_d + Nbytes);
|
||||
if (useSyncMemcpyH2D) {
|
||||
HIPCHECK ( hipMemcpy(&A_d[offset], &A_h[offset], workBytes, hipMemcpyHostToDevice));
|
||||
HIPCHECK ( hipMemcpy(&B_d[offset], &B_h[offset], workBytes, hipMemcpyHostToDevice));
|
||||
HIPCHECK(hipMemcpy(&A_d[offset], &A_h[offset], workBytes, hipMemcpyHostToDevice));
|
||||
HIPCHECK(hipMemcpy(&B_d[offset], &B_h[offset], workBytes, hipMemcpyHostToDevice));
|
||||
} else {
|
||||
HIPCHECK ( hipMemcpyAsync(&A_d[offset], &A_h[offset], workBytes, hipMemcpyHostToDevice, stream[i]));
|
||||
HIPCHECK ( hipMemcpyAsync(&B_d[offset], &B_h[offset], workBytes, hipMemcpyHostToDevice, stream[i]));
|
||||
HIPCHECK(hipMemcpyAsync(&A_d[offset], &A_h[offset], workBytes, hipMemcpyHostToDevice,
|
||||
stream[i]));
|
||||
HIPCHECK(hipMemcpyAsync(&B_d[offset], &B_h[offset], workBytes, hipMemcpyHostToDevice,
|
||||
stream[i]));
|
||||
};
|
||||
|
||||
hipLaunchKernel(HipTest::vectorADD, dim3(blocks), dim3(threadsPerBlock), 0, stream[i], &A_d[offset], &B_d[offset], &C_d[offset], work);
|
||||
hipLaunchKernel(HipTest::vectorADD, dim3(blocks), dim3(threadsPerBlock), 0, stream[i],
|
||||
&A_d[offset], &B_d[offset], &C_d[offset], work);
|
||||
|
||||
if (useSyncMemcpyD2H) {
|
||||
HIPCHECK ( hipMemcpy(&C_h[offset], &C_d[offset], workBytes, hipMemcpyDeviceToHost));
|
||||
HIPCHECK(hipMemcpy(&C_h[offset], &C_d[offset], workBytes, hipMemcpyDeviceToHost));
|
||||
} else {
|
||||
HIPCHECK ( hipMemcpyAsync(&C_h[offset], &C_d[offset], workBytes, hipMemcpyDeviceToHost, stream[i]));
|
||||
HIPCHECK(hipMemcpyAsync(&C_h[offset], &C_d[offset], workBytes, hipMemcpyDeviceToHost,
|
||||
stream[i]));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
HIPCHECK (hipDeviceSynchronize());
|
||||
HIPCHECK(hipDeviceSynchronize());
|
||||
|
||||
|
||||
HipTest::checkVectorADD(A_h, B_h, C_h, N);
|
||||
|
||||
HipTest::freeArrays (A_d, B_d, C_d, A_h, B_h, C_h, true);
|
||||
HipTest::freeArrays(A_d, B_d, C_d, A_h, B_h, C_h, true);
|
||||
|
||||
free(stream);
|
||||
};
|
||||
|
||||
|
||||
//---
|
||||
//Parse arguments specific to this test.
|
||||
void parseMyArguments(int argc, char *argv[])
|
||||
{
|
||||
// Parse arguments specific to this test.
|
||||
void parseMyArguments(int argc, char* argv[]) {
|
||||
int more_argc = HipTest::parseStandardArguments(argc, argv, false);
|
||||
|
||||
// parse args for this test:
|
||||
for (int i = 1; i < more_argc; i++) {
|
||||
const char *arg = argv[i];
|
||||
const char* arg = argv[i];
|
||||
|
||||
if (!strcmp(arg, "--streams")) {
|
||||
if (++i >= argc || !HipTest::parseUInt(argv[i], &p_streams)) {
|
||||
failed("Bad streams argument");
|
||||
failed("Bad streams argument");
|
||||
}
|
||||
} else {
|
||||
failed("Bad argument '%s'", arg);
|
||||
@@ -322,15 +334,12 @@ void parseMyArguments(int argc, char *argv[])
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int main(int argc, char* argv[]) {
|
||||
HipTest::parseStandardArguments(argc, argv, false);
|
||||
parseMyArguments(argc, argv);
|
||||
|
||||
|
||||
printf ("info: set device to %d tests=%x\n", p_gpuDevice, p_tests);
|
||||
printf("info: set device to %d tests=%x\n", p_gpuDevice, p_tests);
|
||||
HIPCHECK(hipSetDevice(p_gpuDevice));
|
||||
|
||||
if (p_tests & 0x01) {
|
||||
@@ -339,34 +348,34 @@ int main(int argc, char *argv[])
|
||||
|
||||
if (p_tests & 0x02) {
|
||||
hipStream_t stream;
|
||||
HIPCHECK (hipStreamCreate(&stream));
|
||||
HIPCHECK(hipStreamCreate(&stream));
|
||||
|
||||
test_manyInflightCopies<float>(stream, 1024, 16, true);
|
||||
test_manyInflightCopies<float>(stream, 1024, 4, true); // verify we re-use the same entries instead of growing pool.
|
||||
test_manyInflightCopies<float>(stream, 1024*8, 64, false);
|
||||
test_manyInflightCopies<float>(stream, 1024, 16, true);
|
||||
test_manyInflightCopies<float>(
|
||||
stream, 1024, 4, true); // verify we re-use the same entries instead of growing pool.
|
||||
test_manyInflightCopies<float>(stream, 1024 * 8, 64, false);
|
||||
|
||||
HIPCHECK(hipStreamDestroy(stream));
|
||||
}
|
||||
|
||||
|
||||
if (p_tests & 0x04) {
|
||||
test_chunkedAsyncExample(p_streams, true, true, true); // Easy sync version
|
||||
test_chunkedAsyncExample(p_streams, false, true, true); // Easy sync version
|
||||
test_chunkedAsyncExample(p_streams, false, false, true); // Some async
|
||||
test_chunkedAsyncExample(p_streams, false, false, false); // All async
|
||||
test_chunkedAsyncExample(p_streams, true, true, true); // Easy sync version
|
||||
test_chunkedAsyncExample(p_streams, false, true, true); // Easy sync version
|
||||
test_chunkedAsyncExample(p_streams, false, false, true); // Some async
|
||||
test_chunkedAsyncExample(p_streams, false, false, false); // All async
|
||||
}
|
||||
|
||||
if (p_tests & 0x08) {
|
||||
hipStream_t stream;
|
||||
HIPCHECK (hipStreamCreate(&stream));
|
||||
HIPCHECK(hipStreamCreate(&stream));
|
||||
|
||||
// test_pingpong<int, Pinned>(stream, 1024*1024*32, 1, 1, false);
|
||||
// test_pingpong<int, Pinned>(stream, 1024*1024*32, 1, 10, false);
|
||||
// test_pingpong<int, Pinned>(stream, 1024*1024*32, 1, 1, false);
|
||||
// test_pingpong<int, Pinned>(stream, 1024*1024*32, 1, 10, false);
|
||||
|
||||
HIPCHECK(hipStreamDestroy(stream));
|
||||
}
|
||||
|
||||
|
||||
passed();
|
||||
|
||||
}
|
||||
|
||||
@@ -22,18 +22,18 @@ THE SOFTWARE.
|
||||
* HIT_END
|
||||
*/
|
||||
|
||||
#include"test_common.h"
|
||||
#include "test_common.h"
|
||||
|
||||
#define SIZE 1024*1024
|
||||
#define SIZE 1024 * 1024
|
||||
|
||||
int main(){
|
||||
int main() {
|
||||
float *A, *Ad;
|
||||
HIPCHECK(hipHostMalloc((void**)&A,SIZE, hipHostMallocDefault));
|
||||
HIPCHECK(hipHostMalloc((void**)&A, SIZE, hipHostMallocDefault));
|
||||
HIPCHECK(hipMalloc((void**)&Ad, SIZE));
|
||||
hipStream_t stream;
|
||||
HIPCHECK(hipStreamCreate(&stream));
|
||||
for(int i=0;i<SIZE;i++){
|
||||
HIPCHECK(hipMemcpyAsync(Ad, A, SIZE, hipMemcpyHostToDevice, stream));
|
||||
HIPCHECK(hipDeviceSynchronize());
|
||||
for (int i = 0; i < SIZE; i++) {
|
||||
HIPCHECK(hipMemcpyAsync(Ad, A, SIZE, hipMemcpyHostToDevice, stream));
|
||||
HIPCHECK(hipDeviceSynchronize());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,7 +19,8 @@ THE SOFTWARE.
|
||||
|
||||
/*
|
||||
* Conformance test for checking functionality of
|
||||
* hipError_t hipMemcpyPeer(void* dst, int dstDeviceId, const void* src, int srcDeviceId, size_t sizeBytes);
|
||||
* hipError_t hipMemcpyPeer(void* dst, int dstDeviceId, const void* src, int srcDeviceId, size_t
|
||||
* sizeBytes);
|
||||
*/
|
||||
|
||||
/* HIT_START
|
||||
@@ -30,58 +31,39 @@ THE SOFTWARE.
|
||||
|
||||
#include "test_common.h"
|
||||
|
||||
int main()
|
||||
{
|
||||
|
||||
size_t Nbytes = N*sizeof(int);
|
||||
int main() {
|
||||
size_t Nbytes = N * sizeof(int);
|
||||
int numDevices = 0;
|
||||
int *A_d, *B_d, *C_d, *X_d, *Y_d, *Z_d;
|
||||
int *A_h, *B_h, *C_h ;
|
||||
int *A_h, *B_h, *C_h;
|
||||
|
||||
HIPCHECK(hipGetDeviceCount(&numDevices));
|
||||
if(numDevices > 1)
|
||||
{
|
||||
if (numDevices > 1) {
|
||||
HIPCHECK(hipSetDevice(0));
|
||||
unsigned blocks = HipTest::setNumBlocks(blocksPerCU, threadsPerBlock, N);
|
||||
HipTest::initArrays(&A_d, &B_d, &C_d, &A_h, &B_h, &C_h, N, false);
|
||||
HIPCHECK(hipSetDevice(1));
|
||||
HIPCHECK(hipMalloc(&X_d,Nbytes));
|
||||
HIPCHECK(hipMalloc(&Y_d,Nbytes));
|
||||
HIPCHECK(hipMalloc(&Z_d,Nbytes));
|
||||
HIPCHECK(hipMalloc(&X_d, Nbytes));
|
||||
HIPCHECK(hipMalloc(&Y_d, Nbytes));
|
||||
HIPCHECK(hipMalloc(&Z_d, Nbytes));
|
||||
|
||||
|
||||
HIPCHECK(hipSetDevice(0));
|
||||
HIPCHECK(hipMemcpy(A_d, A_h, Nbytes, hipMemcpyHostToDevice));
|
||||
HIPCHECK(hipMemcpy(B_d, B_h, Nbytes, hipMemcpyHostToDevice));
|
||||
hipLaunchKernel(
|
||||
HipTest::vectorADD,
|
||||
dim3(blocks),
|
||||
dim3(threadsPerBlock),
|
||||
0,
|
||||
0,
|
||||
static_cast<const int*>(A_d),
|
||||
static_cast<const int*>(B_d),
|
||||
C_d,
|
||||
N);
|
||||
hipLaunchKernel(HipTest::vectorADD, dim3(blocks), dim3(threadsPerBlock), 0, 0,
|
||||
static_cast<const int*>(A_d), static_cast<const int*>(B_d), C_d, N);
|
||||
HIPCHECK(hipMemcpy(C_h, C_d, Nbytes, hipMemcpyDeviceToHost));
|
||||
HIPCHECK(hipDeviceSynchronize());
|
||||
HipTest::checkVectorADD(A_h, B_h, C_h, N);
|
||||
|
||||
|
||||
HIPCHECK(hipSetDevice(1));
|
||||
HIPCHECK(hipMemcpyDtoD((hipDeviceptr_t)X_d, (hipDeviceptr_t)A_d, Nbytes));
|
||||
HIPCHECK(hipMemcpyDtoD((hipDeviceptr_t)Y_d, (hipDeviceptr_t)B_d, Nbytes));
|
||||
HIPCHECK(hipMemcpyDtoD((hipDeviceptr_t)X_d, (hipDeviceptr_t)A_d, Nbytes));
|
||||
HIPCHECK(hipMemcpyDtoD((hipDeviceptr_t)Y_d, (hipDeviceptr_t)B_d, Nbytes));
|
||||
|
||||
hipLaunchKernel(
|
||||
HipTest::vectorADD,
|
||||
dim3(blocks),
|
||||
dim3(threadsPerBlock),
|
||||
0,
|
||||
0,
|
||||
static_cast<const int*>(X_d),
|
||||
static_cast<const int*>(Y_d),
|
||||
Z_d,
|
||||
N);
|
||||
hipLaunchKernel(HipTest::vectorADD, dim3(blocks), dim3(threadsPerBlock), 0, 0,
|
||||
static_cast<const int*>(X_d), static_cast<const int*>(Y_d), Z_d, N);
|
||||
HIPCHECK(hipMemcpyDtoH(C_h, (hipDeviceptr_t)Z_d, Nbytes));
|
||||
HIPCHECK(hipDeviceSynchronize());
|
||||
HipTest::checkVectorADD(A_h, B_h, C_h, N);
|
||||
@@ -90,9 +72,7 @@ int main()
|
||||
HIPCHECK(hipFree(X_d));
|
||||
HIPCHECK(hipFree(Y_d));
|
||||
HIPCHECK(hipFree(Z_d));
|
||||
}
|
||||
|
||||
passed();
|
||||
}
|
||||
|
||||
passed();
|
||||
}
|
||||
|
||||
|
||||
@@ -19,7 +19,8 @@ THE SOFTWARE.
|
||||
|
||||
/*
|
||||
* Conformance test for checking functionality of
|
||||
* hipError_t hipMemcpyPeer(void* dst, int dstDeviceId, const void* src, int srcDeviceId, size_t sizeBytes);
|
||||
* hipError_t hipMemcpyPeer(void* dst, int dstDeviceId, const void* src, int srcDeviceId, size_t
|
||||
* sizeBytes);
|
||||
*/
|
||||
|
||||
/* HIT_START
|
||||
@@ -30,39 +31,29 @@ THE SOFTWARE.
|
||||
|
||||
#include "test_common.h"
|
||||
|
||||
int main()
|
||||
{
|
||||
size_t Nbytes = N*sizeof(int);
|
||||
int main() {
|
||||
size_t Nbytes = N * sizeof(int);
|
||||
int numDevices = 0;
|
||||
int *A_d, *B_d, *C_d, *X_d, *Y_d, *Z_d;
|
||||
int *A_h, *B_h, *C_h ;
|
||||
int *A_h, *B_h, *C_h;
|
||||
hipStream_t s;
|
||||
|
||||
HIPCHECK(hipGetDeviceCount(&numDevices));
|
||||
if(numDevices > 1)
|
||||
{
|
||||
if (numDevices > 1) {
|
||||
HIPCHECK(hipSetDevice(0));
|
||||
unsigned blocks = HipTest::setNumBlocks(blocksPerCU, threadsPerBlock, N);
|
||||
HipTest::initArrays(&A_d, &B_d, &C_d, &A_h, &B_h, &C_h, N, false);
|
||||
HIPCHECK(hipSetDevice(1));
|
||||
HIPCHECK(hipMalloc(&X_d,Nbytes));
|
||||
HIPCHECK(hipMalloc(&Y_d,Nbytes));
|
||||
HIPCHECK(hipMalloc(&Z_d,Nbytes));
|
||||
HIPCHECK(hipMalloc(&X_d, Nbytes));
|
||||
HIPCHECK(hipMalloc(&Y_d, Nbytes));
|
||||
HIPCHECK(hipMalloc(&Z_d, Nbytes));
|
||||
|
||||
|
||||
HIPCHECK(hipSetDevice(0));
|
||||
HIPCHECK(hipMemcpy(A_d, A_h, Nbytes, hipMemcpyHostToDevice));
|
||||
HIPCHECK(hipMemcpy(B_d, B_h, Nbytes, hipMemcpyHostToDevice));
|
||||
hipLaunchKernel(
|
||||
HipTest::vectorADD,
|
||||
dim3(blocks),
|
||||
dim3(threadsPerBlock),
|
||||
0,
|
||||
0,
|
||||
static_cast<const int*>(A_d),
|
||||
static_cast<const int*>(B_d),
|
||||
C_d,
|
||||
N);
|
||||
hipLaunchKernel(HipTest::vectorADD, dim3(blocks), dim3(threadsPerBlock), 0, 0,
|
||||
static_cast<const int*>(A_d), static_cast<const int*>(B_d), C_d, N);
|
||||
HIPCHECK(hipMemcpy(C_h, C_d, Nbytes, hipMemcpyDeviceToHost));
|
||||
HIPCHECK(hipDeviceSynchronize());
|
||||
HipTest::checkVectorADD(A_h, B_h, C_h, N);
|
||||
@@ -72,16 +63,8 @@ int main()
|
||||
HIPCHECK(hipMemcpyDtoDAsync((hipDeviceptr_t)X_d, (hipDeviceptr_t)A_d, Nbytes, s));
|
||||
HIPCHECK(hipMemcpyDtoDAsync((hipDeviceptr_t)Y_d, (hipDeviceptr_t)B_d, Nbytes, s));
|
||||
|
||||
hipLaunchKernel(
|
||||
HipTest::vectorADD,
|
||||
dim3(blocks),
|
||||
dim3(threadsPerBlock),
|
||||
0,
|
||||
0,
|
||||
static_cast<const int*>(X_d),
|
||||
static_cast<const int*>(Y_d),
|
||||
Z_d,
|
||||
N);
|
||||
hipLaunchKernel(HipTest::vectorADD, dim3(blocks), dim3(threadsPerBlock), 0, 0,
|
||||
static_cast<const int*>(X_d), static_cast<const int*>(Y_d), Z_d, N);
|
||||
HIPCHECK(hipMemcpyDtoHAsync(C_h, (hipDeviceptr_t)Z_d, Nbytes, s));
|
||||
HIPCHECK(hipStreamSynchronize(s));
|
||||
HIPCHECK(hipDeviceSynchronize());
|
||||
@@ -92,10 +75,7 @@ int main()
|
||||
HIPCHECK(hipFree(X_d));
|
||||
HIPCHECK(hipFree(Y_d));
|
||||
HIPCHECK(hipFree(Z_d));
|
||||
}
|
||||
|
||||
passed();
|
||||
|
||||
}
|
||||
|
||||
passed();
|
||||
}
|
||||
|
||||
|
||||
@@ -19,7 +19,8 @@ THE SOFTWARE.
|
||||
|
||||
/*
|
||||
* Conformance test for checking functionality of
|
||||
* hipError_t hipMemcpyPeer(void* dst, int dstDeviceId, const void* src, int srcDeviceId, size_t sizeBytes);
|
||||
* hipError_t hipMemcpyPeer(void* dst, int dstDeviceId, const void* src, int srcDeviceId, size_t
|
||||
* sizeBytes);
|
||||
*/
|
||||
|
||||
/* HIT_START
|
||||
@@ -30,55 +31,39 @@ THE SOFTWARE.
|
||||
|
||||
#include "test_common.h"
|
||||
|
||||
int main()
|
||||
{
|
||||
size_t Nbytes = N*sizeof(int);
|
||||
int main() {
|
||||
size_t Nbytes = N * sizeof(int);
|
||||
int numDevices = 0;
|
||||
int *A_d, *B_d, *C_d, *X_d, *Y_d, *Z_d;
|
||||
int *A_h, *B_h, *C_h ;
|
||||
int *A_h, *B_h, *C_h;
|
||||
|
||||
HIPCHECK(hipGetDeviceCount(&numDevices));
|
||||
if(numDevices > 1)
|
||||
{
|
||||
if (numDevices > 1) {
|
||||
HIPCHECK(hipSetDevice(0));
|
||||
unsigned blocks = HipTest::setNumBlocks(blocksPerCU, threadsPerBlock, N);
|
||||
HipTest::initArrays(&A_d, &B_d, &C_d, &A_h, &B_h, &C_h, N, false);
|
||||
HIPCHECK(hipSetDevice(1));
|
||||
HIPCHECK(hipMalloc(&X_d,Nbytes));
|
||||
HIPCHECK(hipMalloc(&Y_d,Nbytes));
|
||||
HIPCHECK(hipMalloc(&Z_d,Nbytes));
|
||||
HIPCHECK(hipMalloc(&X_d, Nbytes));
|
||||
HIPCHECK(hipMalloc(&Y_d, Nbytes));
|
||||
HIPCHECK(hipMalloc(&Z_d, Nbytes));
|
||||
|
||||
HIPCHECK(hipSetDevice(0));
|
||||
HIPCHECK(hipMemcpy(A_d, A_h, Nbytes, hipMemcpyHostToDevice));
|
||||
HIPCHECK(hipMemcpy(B_d, B_h, Nbytes, hipMemcpyHostToDevice));
|
||||
hipLaunchKernel(
|
||||
HipTest::vectorADD,
|
||||
dim3(blocks),
|
||||
dim3(threadsPerBlock),
|
||||
0,
|
||||
0,
|
||||
static_cast<const int*>(A_d),
|
||||
static_cast<const int*>(B_d),
|
||||
C_d,
|
||||
N);
|
||||
hipLaunchKernel(HipTest::vectorADD, dim3(blocks), dim3(threadsPerBlock), 0, 0,
|
||||
static_cast<const int*>(A_d), static_cast<const int*>(B_d), C_d, N);
|
||||
HIPCHECK(hipMemcpy(C_h, C_d, Nbytes, hipMemcpyDeviceToHost));
|
||||
HIPCHECK(hipDeviceSynchronize());
|
||||
HipTest::checkVectorADD(A_h, B_h, C_h, N);
|
||||
|
||||
HIPCHECK(hipSetDevice(1));
|
||||
hipMemcpyPeer(X_d, 1, A_d, 0, Nbytes); //this call is eqv to hipMemcpy(hipMemcpyD2D) which goes via stg bufs.
|
||||
hipMemcpyPeer(
|
||||
X_d, 1, A_d, 0,
|
||||
Nbytes); // this call is eqv to hipMemcpy(hipMemcpyD2D) which goes via stg bufs.
|
||||
hipMemcpyPeer(Y_d, 1, B_d, 0, Nbytes);
|
||||
|
||||
hipLaunchKernel(
|
||||
HipTest::vectorADD,
|
||||
dim3(blocks),
|
||||
dim3(threadsPerBlock),
|
||||
0,
|
||||
0,
|
||||
static_cast<const int*>(X_d),
|
||||
static_cast<const int*>(Y_d),
|
||||
Z_d,
|
||||
N);
|
||||
hipLaunchKernel(HipTest::vectorADD, dim3(blocks), dim3(threadsPerBlock), 0, 0,
|
||||
static_cast<const int*>(X_d), static_cast<const int*>(Y_d), Z_d, N);
|
||||
HIPCHECK(hipMemcpy(C_h, Z_d, Nbytes, hipMemcpyDeviceToHost));
|
||||
HIPCHECK(hipDeviceSynchronize());
|
||||
HipTest::checkVectorADD(A_h, B_h, C_h, N);
|
||||
@@ -87,11 +72,6 @@ int main()
|
||||
HIPCHECK(hipFree(X_d));
|
||||
HIPCHECK(hipFree(Y_d));
|
||||
HIPCHECK(hipFree(Z_d));
|
||||
}
|
||||
passed();
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
passed();
|
||||
}
|
||||
|
||||
|
||||
@@ -19,7 +19,8 @@ THE SOFTWARE.
|
||||
|
||||
/*
|
||||
* Conformance test for checking functionality of
|
||||
* hipError_t hipMemcpyPeer(void* dst, int dstDeviceId, const void* src, int srcDeviceId, size_t sizeBytes);
|
||||
* hipError_t hipMemcpyPeer(void* dst, int dstDeviceId, const void* src, int srcDeviceId, size_t
|
||||
* sizeBytes);
|
||||
*/
|
||||
|
||||
/* HIT_START
|
||||
@@ -30,43 +31,33 @@ THE SOFTWARE.
|
||||
|
||||
#include "test_common.h"
|
||||
|
||||
int main()
|
||||
{
|
||||
int main() {
|
||||
hipDevice_t device;
|
||||
size_t Nbytes = N*sizeof(int);
|
||||
size_t Nbytes = N * sizeof(int);
|
||||
int numDevices = 0;
|
||||
int *A_d, *B_d, *C_d, *X_d, *Y_d, *Z_d;
|
||||
int *A_h, *B_h, *C_h ;
|
||||
int *A_h, *B_h, *C_h;
|
||||
hipStream_t s;
|
||||
|
||||
|
||||
HIPCHECK(hipGetDeviceCount(&numDevices));
|
||||
if(numDevices > 1)
|
||||
{
|
||||
if (numDevices > 1) {
|
||||
HIPCHECK(hipSetDevice(0));
|
||||
unsigned blocks = HipTest::setNumBlocks(blocksPerCU, threadsPerBlock, N);
|
||||
HipTest::initArrays(&A_d, &B_d, &C_d, &A_h, &B_h, &C_h, N, false);
|
||||
HIPCHECK(hipSetDevice(1));
|
||||
HIPCHECK(hipMalloc(&X_d,Nbytes));
|
||||
HIPCHECK(hipMalloc(&Y_d,Nbytes));
|
||||
HIPCHECK(hipMalloc(&Z_d,Nbytes));
|
||||
HIPCHECK(hipMalloc(&X_d, Nbytes));
|
||||
HIPCHECK(hipMalloc(&Y_d, Nbytes));
|
||||
HIPCHECK(hipMalloc(&Z_d, Nbytes));
|
||||
|
||||
|
||||
HIPCHECK(hipSetDevice(0));
|
||||
HIPCHECK ( hipMemcpy(A_d, A_h, Nbytes, hipMemcpyHostToDevice));
|
||||
HIPCHECK ( hipMemcpy(B_d, B_h, Nbytes, hipMemcpyHostToDevice));
|
||||
hipLaunchKernel(
|
||||
HipTest::vectorADD,
|
||||
dim3(blocks),
|
||||
dim3(threadsPerBlock),
|
||||
0,
|
||||
0,
|
||||
static_cast<const int*>(A_d),
|
||||
static_cast<const int*>(B_d),
|
||||
C_d,
|
||||
N);
|
||||
HIPCHECK ( hipMemcpy(C_h, C_d, Nbytes, hipMemcpyDeviceToHost));
|
||||
HIPCHECK (hipDeviceSynchronize());
|
||||
HIPCHECK(hipMemcpy(A_d, A_h, Nbytes, hipMemcpyHostToDevice));
|
||||
HIPCHECK(hipMemcpy(B_d, B_h, Nbytes, hipMemcpyHostToDevice));
|
||||
hipLaunchKernel(HipTest::vectorADD, dim3(blocks), dim3(threadsPerBlock), 0, 0,
|
||||
static_cast<const int*>(A_d), static_cast<const int*>(B_d), C_d, N);
|
||||
HIPCHECK(hipMemcpy(C_h, C_d, Nbytes, hipMemcpyDeviceToHost));
|
||||
HIPCHECK(hipDeviceSynchronize());
|
||||
HipTest::checkVectorADD(A_h, B_h, C_h, N);
|
||||
|
||||
HIPCHECK(hipStreamCreate(&s));
|
||||
@@ -74,19 +65,11 @@ int main()
|
||||
HIPCHECK(hipMemcpyPeerAsync(X_d, 1, A_d, 0, Nbytes, s));
|
||||
HIPCHECK(hipMemcpyPeerAsync(Y_d, 1, B_d, 0, Nbytes, s));
|
||||
|
||||
hipLaunchKernel(
|
||||
HipTest::vectorADD,
|
||||
dim3(blocks),
|
||||
dim3(threadsPerBlock),
|
||||
0,
|
||||
0,
|
||||
static_cast<const int*>(X_d),
|
||||
static_cast<const int*>(Y_d),
|
||||
Z_d,
|
||||
N);
|
||||
HIPCHECK ( hipMemcpy(C_h, Z_d, Nbytes, hipMemcpyDeviceToHost));
|
||||
HIPCHECK (hipDeviceSynchronize());
|
||||
HIPCHECK (hipStreamSynchronize(s));
|
||||
hipLaunchKernel(HipTest::vectorADD, dim3(blocks), dim3(threadsPerBlock), 0, 0,
|
||||
static_cast<const int*>(X_d), static_cast<const int*>(Y_d), Z_d, N);
|
||||
HIPCHECK(hipMemcpy(C_h, Z_d, Nbytes, hipMemcpyDeviceToHost));
|
||||
HIPCHECK(hipDeviceSynchronize());
|
||||
HIPCHECK(hipStreamSynchronize(s));
|
||||
HipTest::checkVectorADD(A_h, B_h, C_h, N);
|
||||
|
||||
HIPCHECK(hipStreamDestroy(s));
|
||||
@@ -94,10 +77,7 @@ int main()
|
||||
HIPCHECK(hipFree(X_d));
|
||||
HIPCHECK(hipFree(Y_d));
|
||||
HIPCHECK(hipFree(Z_d));
|
||||
}
|
||||
|
||||
passed();
|
||||
|
||||
}
|
||||
|
||||
passed();
|
||||
}
|
||||
|
||||
|
||||
@@ -33,8 +33,7 @@ THE SOFTWARE.
|
||||
bool p_async = false;
|
||||
|
||||
// ****************************************************************************
|
||||
hipError_t memcopy(void * dst, const void *src, size_t sizeBytes, enum hipMemcpyKind kind)
|
||||
{
|
||||
hipError_t memcopy(void* dst, const void* src, size_t sizeBytes, enum hipMemcpyKind kind) {
|
||||
if (p_async) {
|
||||
return hipMemcpyAsync(dst, src, sizeBytes, kind, NULL);
|
||||
} else {
|
||||
@@ -46,59 +45,50 @@ hipError_t memcopy(void * dst, const void *src, size_t sizeBytes, enum hipMemcpy
|
||||
//---
|
||||
// Test simple H2D copies and back.
|
||||
// Designed to stress a small number of simple smoke tests
|
||||
void simpleTest1()
|
||||
{
|
||||
printf ("test: %s\n", __func__);
|
||||
size_t Nbytes = N*sizeof(int);
|
||||
printf ("N=%zu Nbytes=%6.2fMB\n", N, Nbytes/1024.0/1024.0);
|
||||
void simpleTest1() {
|
||||
printf("test: %s\n", __func__);
|
||||
size_t Nbytes = N * sizeof(int);
|
||||
printf("N=%zu Nbytes=%6.2fMB\n", N, Nbytes / 1024.0 / 1024.0);
|
||||
|
||||
int *A_d, *B_d, *C_d;
|
||||
int *A_h, *B_h, *C_h;
|
||||
|
||||
HipTest::initArrays (&A_d, &B_d, &C_d, &A_h, &B_h, &C_h, N, false);
|
||||
HipTest::initArrays(&A_d, &B_d, &C_d, &A_h, &B_h, &C_h, N, false);
|
||||
|
||||
printf ("A_d=%p B_d=%p C_d=%p A_h=%p B_h=%p C_h=%p\n", A_d, B_d, C_d, A_h, B_d, C_h);
|
||||
printf("A_d=%p B_d=%p C_d=%p A_h=%p B_h=%p C_h=%p\n", A_d, B_d, C_d, A_h, B_d, C_h);
|
||||
unsigned blocks = HipTest::setNumBlocks(blocksPerCU, threadsPerBlock, N);
|
||||
|
||||
HIPCHECK ( memcopy(A_d, A_h, Nbytes, hipMemcpyHostToDevice));
|
||||
HIPCHECK ( memcopy(B_d, B_h, Nbytes, hipMemcpyHostToDevice));
|
||||
HIPCHECK(memcopy(A_d, A_h, Nbytes, hipMemcpyHostToDevice));
|
||||
HIPCHECK(memcopy(B_d, B_h, Nbytes, hipMemcpyHostToDevice));
|
||||
|
||||
hipLaunchKernel(
|
||||
HipTest::vectorADD,
|
||||
dim3(blocks),
|
||||
dim3(threadsPerBlock),
|
||||
0,
|
||||
0,
|
||||
static_cast<const int*>(A_d),
|
||||
static_cast<const int*>(B_d),
|
||||
C_d,
|
||||
N);
|
||||
hipLaunchKernel(HipTest::vectorADD, dim3(blocks), dim3(threadsPerBlock), 0, 0,
|
||||
static_cast<const int*>(A_d), static_cast<const int*>(B_d), C_d, N);
|
||||
|
||||
HIPCHECK ( memcopy(C_h, C_d, Nbytes, hipMemcpyDeviceToHost));
|
||||
HIPCHECK(memcopy(C_h, C_d, Nbytes, hipMemcpyDeviceToHost));
|
||||
|
||||
HIPCHECK (hipDeviceSynchronize());
|
||||
HIPCHECK(hipDeviceSynchronize());
|
||||
|
||||
HipTest::checkVectorADD(A_h, B_h, C_h, N);
|
||||
|
||||
HipTest::freeArrays (A_d, B_d, C_d, A_h, B_h, C_h, false);
|
||||
HIPCHECK (hipDeviceReset());
|
||||
HipTest::freeArrays(A_d, B_d, C_d, A_h, B_h, C_h, false);
|
||||
HIPCHECK(hipDeviceReset());
|
||||
|
||||
printf (" %s success\n", __func__);
|
||||
printf(" %s success\n", __func__);
|
||||
}
|
||||
|
||||
|
||||
template <typename T>
|
||||
void simpleTest2(size_t numElements, bool usePinnedHost)
|
||||
{
|
||||
void simpleTest2(size_t numElements, bool usePinnedHost) {
|
||||
size_t sizeElements = numElements * sizeof(T);
|
||||
size_t alignment = 4096;
|
||||
printf ("test: %s<%s> numElements=%zu sizeElements=%zu bytes\n", __func__, TYPENAME(T), numElements, sizeElements);
|
||||
printf("test: %s<%s> numElements=%zu sizeElements=%zu bytes\n", __func__, TYPENAME(T),
|
||||
numElements, sizeElements);
|
||||
|
||||
T *A_d, *A_h1, *A_h2;
|
||||
|
||||
if (usePinnedHost) {
|
||||
HIPCHECK ( hipHostMalloc((void**)&A_h1, sizeElements, hipHostMallocDefault) );
|
||||
HIPCHECK ( hipHostMalloc((void**)&A_h2, sizeElements, hipHostMallocDefault) );
|
||||
HIPCHECK(hipHostMalloc((void**)&A_h1, sizeElements, hipHostMallocDefault));
|
||||
HIPCHECK(hipHostMalloc((void**)&A_h2, sizeElements, hipHostMallocDefault));
|
||||
} else {
|
||||
A_h1 = (T*)aligned_alloc(alignment, sizeElements);
|
||||
HIPASSERT(A_h1);
|
||||
@@ -107,12 +97,13 @@ void simpleTest2(size_t numElements, bool usePinnedHost)
|
||||
}
|
||||
|
||||
// Alloc device array:
|
||||
HIPCHECK ( hipMalloc(&A_d, sizeElements) );
|
||||
HIPCHECK(hipMalloc(&A_d, sizeElements));
|
||||
|
||||
|
||||
for (size_t i=0; i<numElements; i++) {
|
||||
A_h1[i] = 3.14f+ 1000*i;
|
||||
A_h2[i] = 12345678.0 + i; // init output with something distincctive, to ensure we replace it.
|
||||
for (size_t i = 0; i < numElements; i++) {
|
||||
A_h1[i] = 3.14f + 1000 * i;
|
||||
A_h2[i] =
|
||||
12345678.0 + i; // init output with something distincctive, to ensure we replace it.
|
||||
}
|
||||
|
||||
HIPCHECK(memcopy(A_d, A_h1, sizeElements, hipMemcpyHostToDevice));
|
||||
@@ -120,7 +111,7 @@ void simpleTest2(size_t numElements, bool usePinnedHost)
|
||||
HIPCHECK(memcopy(A_h2, A_d, sizeElements, hipMemcpyDeviceToHost));
|
||||
HIPCHECK(hipDeviceSynchronize());
|
||||
|
||||
for (size_t i=0; i<numElements; i++) {
|
||||
for (size_t i = 0; i < numElements; i++) {
|
||||
HIPASSERT(A_h1[i] == A_h2[i]);
|
||||
}
|
||||
|
||||
@@ -135,14 +126,13 @@ void simpleTest2(size_t numElements, bool usePinnedHost)
|
||||
}
|
||||
|
||||
|
||||
//Parse arguments specific to this test.
|
||||
void parseMyArguments(int argc, char *argv[])
|
||||
{
|
||||
// Parse arguments specific to this test.
|
||||
void parseMyArguments(int argc, char* argv[]) {
|
||||
int more_argc = HipTest::parseStandardArguments(argc, argv, false);
|
||||
|
||||
// parse args for this test:
|
||||
for (int i = 1; i < more_argc; i++) {
|
||||
const char *arg = argv[i];
|
||||
const char* arg = argv[i];
|
||||
|
||||
if (!strcmp(arg, "--async")) {
|
||||
p_async = true;
|
||||
@@ -154,31 +144,30 @@ void parseMyArguments(int argc, char *argv[])
|
||||
};
|
||||
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int main(int argc, char* argv[]) {
|
||||
parseMyArguments(argc, argv);
|
||||
|
||||
printf ("info: set device to %d, tests=%x\n", p_gpuDevice, p_tests);
|
||||
printf("info: set device to %d, tests=%x\n", p_gpuDevice, p_tests);
|
||||
HIPCHECK(hipSetDevice(p_gpuDevice));
|
||||
|
||||
|
||||
if (p_tests & 0x1) {
|
||||
printf ("\n\n=== tests&1\n");
|
||||
HIPCHECK ( hipDeviceReset() );
|
||||
printf("\n\n=== tests&1\n");
|
||||
HIPCHECK(hipDeviceReset());
|
||||
simpleTest1();
|
||||
printf ("===\n\n\n");
|
||||
printf("===\n\n\n");
|
||||
}
|
||||
|
||||
if (p_tests & 0x2) {
|
||||
printf ("\n\n=== tests&2 (copy ping-pong, pinned host)\n");
|
||||
simpleTest2<float>(N, true/*usePinnedHost*/);
|
||||
simpleTest2<char>(N, true/*usePinnedHost*/);
|
||||
printf("\n\n=== tests&2 (copy ping-pong, pinned host)\n");
|
||||
simpleTest2<float>(N, true /*usePinnedHost*/);
|
||||
simpleTest2<char>(N, true /*usePinnedHost*/);
|
||||
}
|
||||
|
||||
if (p_tests & 0x4) {
|
||||
printf ("\n\n=== tests&4 (copy ping-pong, unpinned host)\n");
|
||||
simpleTest2<char>(N, false/*usePinnedHost*/);
|
||||
simpleTest2<float>(N, false/*usePinnedHost*/);
|
||||
printf("\n\n=== tests&4 (copy ping-pong, unpinned host)\n");
|
||||
simpleTest2<char>(N, false /*usePinnedHost*/);
|
||||
simpleTest2<float>(N, false /*usePinnedHost*/);
|
||||
}
|
||||
|
||||
hipDeviceSynchronize();
|
||||
|
||||
+13
-14
@@ -29,33 +29,32 @@ THE SOFTWARE.
|
||||
#include <cstdio>
|
||||
#include "hip/hip_runtime.h"
|
||||
|
||||
__global__ void Kernel(hipLaunchParm lp,volatile float* hostRes)
|
||||
{
|
||||
__global__ void Kernel(hipLaunchParm lp, volatile float* hostRes) {
|
||||
int tid = threadIdx.x + blockIdx.x * blockDim.x;
|
||||
hostRes[tid] = tid + 1;
|
||||
__threadfence_system();
|
||||
// expecting that the data is getting flushed to host here!
|
||||
// time waster for-loop (sleep)
|
||||
for (int timeWater = 0; timeWater < 100000000; timeWater++);
|
||||
for (int timeWater = 0; timeWater < 100000000; timeWater++)
|
||||
;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
int main() {
|
||||
size_t blocks = 2;
|
||||
volatile float* hostRes;
|
||||
hipHostMalloc((void**)&hostRes,blocks*sizeof(float),hipHostMallocMapped);
|
||||
hostRes[0]=0;
|
||||
hostRes[1]=0;
|
||||
hipHostMalloc((void**)&hostRes, blocks * sizeof(float), hipHostMallocMapped);
|
||||
hostRes[0] = 0;
|
||||
hostRes[1] = 0;
|
||||
hipLaunchKernel(HIP_KERNEL_NAME(Kernel), dim3(1), dim3(blocks), 0, 0, hostRes);
|
||||
int eleCounter = 0;
|
||||
while (eleCounter < blocks)
|
||||
{
|
||||
while (eleCounter < blocks) {
|
||||
// blocks until the value changes
|
||||
while(hostRes[eleCounter] == 0);
|
||||
printf("%f\n", hostRes[eleCounter]);;
|
||||
while (hostRes[eleCounter] == 0)
|
||||
;
|
||||
printf("%f\n", hostRes[eleCounter]);
|
||||
;
|
||||
eleCounter++;
|
||||
}
|
||||
hipHostFree((void *)hostRes);
|
||||
hipHostFree((void*)hostRes);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
+14
-15
@@ -1,19 +1,19 @@
|
||||
/* Copyright (c) 2015-2016 Advanced Micro Devices, Inc. All rights reserved.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
|
||||
associated documentation files (the "Software"), to deal in the Software without restriction, including
|
||||
without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the
|
||||
following conditions:
|
||||
associated documentation files (the "Software"), to deal in the Software without restriction,
|
||||
including without limitation the rights to use, copy, modify, merge, publish, distribute,
|
||||
sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial
|
||||
portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
|
||||
LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO
|
||||
EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
|
||||
THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
|
||||
NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT
|
||||
OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
|
||||
/* HIT_START
|
||||
* BUILD: %t %s ../../test_common.cpp NVCC_OPTIONS -std=c++11
|
||||
@@ -31,11 +31,11 @@ THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
#include "hip/hip_runtime.h"
|
||||
using namespace std;
|
||||
|
||||
string getRes(){
|
||||
FILE *in;
|
||||
string getRes() {
|
||||
FILE* in;
|
||||
char buff[512], buff_2[512];
|
||||
string str = "./hipMemoryAllocateCoherent";
|
||||
if(!(in = popen(str.c_str(), "r"))){
|
||||
if (!(in = popen(str.c_str(), "r"))) {
|
||||
exit(1);
|
||||
}
|
||||
fgets(buff, sizeof(buff), in);
|
||||
@@ -47,14 +47,13 @@ string getRes(){
|
||||
}
|
||||
|
||||
int main() {
|
||||
setenv("HIP_COHERENT_HOST_ALLOC","1000,0,1",1);
|
||||
setenv("HIP_COHERENT_HOST_ALLOC", "1000,0,1", 1);
|
||||
string output = getRes();
|
||||
istringstream buffer(output);
|
||||
double res1, res2;
|
||||
buffer >> res1;
|
||||
buffer >> res2;
|
||||
if((res2-res1*2)>0.000001)
|
||||
exit(1);
|
||||
if ((res2 - res1 * 2) > 0.000001) exit(1);
|
||||
std::cout << "PASSED" << std::endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -38,34 +38,31 @@ THE SOFTWARE.
|
||||
#include "test_common.h"
|
||||
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
HipTest::parseStandardArguments(argc, argv, true);
|
||||
|
||||
HIPCHECK(hipSetDevice(p_gpuDevice));
|
||||
|
||||
size_t Nbytes = N*sizeof(char);
|
||||
size_t Nbytes = N * sizeof(char);
|
||||
|
||||
printf ("N=%zu memsetval=%2x device=%d\n", N, memsetval, p_gpuDevice);
|
||||
printf("N=%zu memsetval=%2x device=%d\n", N, memsetval, p_gpuDevice);
|
||||
|
||||
char *A_d;
|
||||
char *A_h;
|
||||
char* A_d;
|
||||
char* A_h;
|
||||
|
||||
HIPCHECK ( hipMalloc(&A_d, Nbytes) );
|
||||
HIPCHECK(hipMalloc(&A_d, Nbytes));
|
||||
A_h = (char*)malloc(Nbytes);
|
||||
|
||||
HIPCHECK ( hipMemset(A_d, memsetval, Nbytes) );
|
||||
HIPCHECK(hipMemset(A_d, memsetval, Nbytes));
|
||||
|
||||
HIPCHECK ( hipMemcpy(A_h, A_d, Nbytes, hipMemcpyDeviceToHost));
|
||||
HIPCHECK(hipMemcpy(A_h, A_d, Nbytes, hipMemcpyDeviceToHost));
|
||||
|
||||
for (int i=0; i<N; i++) {
|
||||
for (int i = 0; i < N; i++) {
|
||||
if (A_h[i] != memsetval) {
|
||||
failed("mismatch at index:%d computed:%02x, memsetval:%02x\n", i, (int)A_h[i], (int)memsetval);
|
||||
|
||||
failed("mismatch at index:%d computed:%02x, memsetval:%02x\n", i, (int)A_h[i],
|
||||
(int)memsetval);
|
||||
}
|
||||
}
|
||||
|
||||
passed();
|
||||
|
||||
}
|
||||
|
||||
@@ -29,77 +29,76 @@ THE SOFTWARE.
|
||||
#include "hip/hip_runtime.h"
|
||||
#include "test_common.h"
|
||||
|
||||
#define WIDTH 1024
|
||||
#define HEIGHT 1024
|
||||
#define WIDTH 1024
|
||||
#define HEIGHT 1024
|
||||
|
||||
#define NUM (WIDTH*HEIGHT)
|
||||
#define NUM (WIDTH * HEIGHT)
|
||||
|
||||
#define THREADS_PER_BLOCK_X 16
|
||||
#define THREADS_PER_BLOCK_Y 16
|
||||
#define THREADS_PER_BLOCK_Z 1
|
||||
#define THREADS_PER_BLOCK_X 16
|
||||
#define THREADS_PER_BLOCK_Y 16
|
||||
#define THREADS_PER_BLOCK_Z 1
|
||||
|
||||
int main() {
|
||||
int* hostA;
|
||||
int* hostB;
|
||||
|
||||
int *hostA;
|
||||
int *hostB;
|
||||
int* deviceA;
|
||||
int* deviceB;
|
||||
|
||||
int *deviceA;
|
||||
int *deviceB;
|
||||
int i;
|
||||
int errors;
|
||||
|
||||
int i;
|
||||
int errors;
|
||||
hostA = (int*)malloc(NUM * sizeof(int));
|
||||
hostB = (int*)malloc(NUM * sizeof(int));
|
||||
|
||||
hostA = (int *)malloc(NUM * sizeof(int));
|
||||
hostB = (int *)malloc(NUM * sizeof(int));
|
||||
// initialize the input data
|
||||
for (i = 0; i < NUM; i++) {
|
||||
hostB[i] = i;
|
||||
}
|
||||
|
||||
// initialize the input data
|
||||
for (i = 0; i < NUM; i++) {
|
||||
hostB[i] = i;
|
||||
}
|
||||
HIPCHECK(hipMalloc((void**)&deviceA, NUM * sizeof(int)));
|
||||
HIPCHECK(hipMalloc((void**)&deviceB, NUM * sizeof(int)));
|
||||
|
||||
HIPCHECK(hipMalloc((void**)&deviceA, NUM * sizeof(int)));
|
||||
HIPCHECK(hipMalloc((void**)&deviceB, NUM * sizeof(int)));
|
||||
|
||||
hipStream_t s;
|
||||
HIPCHECK(hipStreamCreate(&s));
|
||||
hipStream_t s;
|
||||
HIPCHECK(hipStreamCreate(&s));
|
||||
|
||||
|
||||
// hostB -> deviceB -> hostA
|
||||
// hostB -> deviceB -> hostA
|
||||
#define ASYNC 1
|
||||
#if ASYNC
|
||||
HIPCHECK(hipMemcpyAsync(deviceB, hostB, NUM*sizeof(int), hipMemcpyHostToDevice, s));
|
||||
HIPCHECK(hipMemcpyAsync(hostA, deviceB, NUM*sizeof(int), hipMemcpyDeviceToHost, s));
|
||||
HIPCHECK(hipMemcpyAsync(deviceB, hostB, NUM * sizeof(int), hipMemcpyHostToDevice, s));
|
||||
HIPCHECK(hipMemcpyAsync(hostA, deviceB, NUM * sizeof(int), hipMemcpyDeviceToHost, s));
|
||||
#else
|
||||
HIPCHECK(hipMemcpy(deviceB, hostB, NUM*sizeof(int), hipMemcpyHostToDevice));
|
||||
HIPCHECK(hipMemcpy(hostA, deviceB, NUM*sizeof(int), hipMemcpyDeviceToHost));
|
||||
HIPCHECK(hipMemcpy(deviceB, hostB, NUM * sizeof(int), hipMemcpyHostToDevice));
|
||||
HIPCHECK(hipMemcpy(hostA, deviceB, NUM * sizeof(int), hipMemcpyDeviceToHost));
|
||||
#endif
|
||||
|
||||
HIPCHECK(hipStreamSynchronize(s));
|
||||
HIPCHECK(hipDeviceSynchronize());
|
||||
HIPCHECK(hipStreamSynchronize(s));
|
||||
HIPCHECK(hipDeviceSynchronize());
|
||||
|
||||
// verify the results
|
||||
errors = 0;
|
||||
for (i = 0; i < NUM; i++) {
|
||||
if (hostA[i] != (hostB[i])) {
|
||||
errors++;
|
||||
// verify the results
|
||||
errors = 0;
|
||||
for (i = 0; i < NUM; i++) {
|
||||
if (hostA[i] != (hostB[i])) {
|
||||
errors++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
HIPCHECK(hipStreamDestroy(s));
|
||||
HIPCHECK(hipStreamDestroy(s));
|
||||
|
||||
HIPCHECK(hipFree(deviceA));
|
||||
HIPCHECK(hipFree(deviceB));
|
||||
HIPCHECK(hipFree(deviceA));
|
||||
HIPCHECK(hipFree(deviceB));
|
||||
|
||||
free(hostA);
|
||||
free(hostB);
|
||||
free(hostA);
|
||||
free(hostB);
|
||||
|
||||
//hipResetDefaultAccelerator();
|
||||
// hipResetDefaultAccelerator();
|
||||
|
||||
if(errors != 0){
|
||||
HIPASSERT(1 == 2);
|
||||
}else{
|
||||
passed();
|
||||
}
|
||||
if (errors != 0) {
|
||||
HIPASSERT(1 == 2);
|
||||
} else {
|
||||
passed();
|
||||
}
|
||||
|
||||
return errors;
|
||||
return errors;
|
||||
}
|
||||
|
||||
@@ -24,12 +24,12 @@ THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "hip/hip_runtime.h"
|
||||
#include"test_common.h"
|
||||
#include "test_common.h"
|
||||
|
||||
#define len 1024*1024
|
||||
#define len 1024 * 1024
|
||||
#define size len * sizeof(float)
|
||||
|
||||
int main(){
|
||||
int main() {
|
||||
float *Ad, *A;
|
||||
hipHostMalloc((void**)&A, size);
|
||||
hipMalloc((void**)&Ad, size);
|
||||
|
||||
@@ -35,15 +35,13 @@ THE SOFTWARE.
|
||||
#include <hc_am.hpp>
|
||||
#endif
|
||||
|
||||
#define USE_HCC_MEMTRACKER 0 /* Debug flag to show the memtracker periodically */
|
||||
#define USE_HCC_MEMTRACKER 0 /* Debug flag to show the memtracker periodically */
|
||||
|
||||
|
||||
int elementSizes[] = {1, 16, 1024, 524288, 16 * 1000 * 1000};
|
||||
int nSizes = sizeof(elementSizes) / sizeof(int);
|
||||
|
||||
int elementSizes[] = {1, 16, 1024, 524288, 16*1000*1000};
|
||||
int nSizes = sizeof(elementSizes) / sizeof(int);
|
||||
|
||||
int enablePeers(int dev0, int dev1)
|
||||
{
|
||||
int enablePeers(int dev0, int dev1) {
|
||||
int canAccessPeer01, canAccessPeer10;
|
||||
HIPCHECK(hipDeviceCanAccessPeer(&canAccessPeer01, dev0, dev1));
|
||||
HIPCHECK(hipDeviceCanAccessPeer(&canAccessPeer10, dev1, dev0));
|
||||
@@ -52,79 +50,78 @@ int enablePeers(int dev0, int dev1)
|
||||
}
|
||||
|
||||
HIPCHECK(hipSetDevice(dev0));
|
||||
HIPCHECK(hipDeviceEnablePeerAccess(dev1, 0/*flags*/));
|
||||
HIPCHECK(hipDeviceEnablePeerAccess(dev1, 0 /*flags*/));
|
||||
HIPCHECK(hipSetDevice(dev1));
|
||||
HIPCHECK(hipDeviceEnablePeerAccess(dev0, 0/*flags*/));
|
||||
HIPCHECK(hipDeviceEnablePeerAccess(dev0, 0 /*flags*/));
|
||||
|
||||
return 0;
|
||||
};
|
||||
|
||||
// Set value of array to specified 32-bit integer:
|
||||
__global__ void
|
||||
memsetIntKernel(int * ptr, const int val, size_t numElements)
|
||||
{
|
||||
__global__ void memsetIntKernel(int* ptr, const int val, size_t numElements) {
|
||||
int gid = (blockIdx.x * blockDim.x + threadIdx.x);
|
||||
int stride = blockDim.x * gridDim.x ;
|
||||
for (size_t i= gid; i< numElements; i+=stride){
|
||||
ptr[i] = val;
|
||||
int stride = blockDim.x * gridDim.x;
|
||||
for (size_t i = gid; i < numElements; i += stride) {
|
||||
ptr[i] = val;
|
||||
}
|
||||
};
|
||||
|
||||
__global__ void
|
||||
memcpyIntKernel(const int * src, int* dst, size_t numElements)
|
||||
{
|
||||
__global__ void memcpyIntKernel(const int* src, int* dst, size_t numElements) {
|
||||
int gid = (blockIdx.x * blockDim.x + threadIdx.x);
|
||||
int stride = blockDim.x * gridDim.x ;
|
||||
for (size_t i= gid; i< numElements; i+=stride){
|
||||
dst[i] = src[i];
|
||||
int stride = blockDim.x * gridDim.x;
|
||||
for (size_t i = gid; i < numElements; i += stride) {
|
||||
dst[i] = src[i];
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
// CHeck arrays in reverse order, to more easily detect cases where
|
||||
// the copy is "partially" done.
|
||||
void checkReverse(const int *ptr, int numElements, int expected) {
|
||||
for (int i=numElements-1; i>=0; i--) {
|
||||
void checkReverse(const int* ptr, int numElements, int expected) {
|
||||
for (int i = numElements - 1; i >= 0; i--) {
|
||||
if (ptr[i] != expected) {
|
||||
printf ("i=%d, ptr[](%d) != expected (%d)\n", i, ptr[i], expected);
|
||||
assert (ptr[i] == expected);
|
||||
printf("i=%d, ptr[](%d) != expected (%d)\n", i, ptr[i], expected);
|
||||
assert(ptr[i] == expected);
|
||||
}
|
||||
}
|
||||
|
||||
printf ("test: OK\n");
|
||||
printf("test: OK\n");
|
||||
}
|
||||
|
||||
|
||||
void runTestImpl(bool stepAIsCopy, bool hostSync, hipStream_t gpu0Stream, hipStream_t gpu1Stream, int numElements,
|
||||
int * dataGpu0_0, int * dataGpu0_1, int *dataGpu1, int *dataHost, int expected)
|
||||
{
|
||||
void runTestImpl(bool stepAIsCopy, bool hostSync, hipStream_t gpu0Stream, hipStream_t gpu1Stream,
|
||||
int numElements, int* dataGpu0_0, int* dataGpu0_1, int* dataGpu1, int* dataHost,
|
||||
int expected) {
|
||||
hipEvent_t e;
|
||||
if(!hostSync) {
|
||||
HIPCHECK(hipEventCreateWithFlags(&e,0));
|
||||
if (!hostSync) {
|
||||
HIPCHECK(hipEventCreateWithFlags(&e, 0));
|
||||
}
|
||||
const size_t sizeElements = numElements * sizeof(int);
|
||||
printf ("test: runTestImpl with %zu bytes %s with hostSync %s\n", sizeElements, stepAIsCopy ? "copy" : "kernel", hostSync ? "enabled" : "disabled");
|
||||
printf("test: runTestImpl with %zu bytes %s with hostSync %s\n", sizeElements,
|
||||
stepAIsCopy ? "copy" : "kernel", hostSync ? "enabled" : "disabled");
|
||||
|
||||
hipStream_t stepAStream = gpu0Stream;
|
||||
|
||||
if (stepAIsCopy) {
|
||||
HIPCHECK(hipMemcpyAsync(dataGpu1, dataGpu0_0, sizeElements, hipMemcpyDeviceToDevice, stepAStream));
|
||||
HIPCHECK(hipMemcpyAsync(dataGpu1, dataGpu0_0, sizeElements, hipMemcpyDeviceToDevice,
|
||||
stepAStream));
|
||||
} else {
|
||||
unsigned blocks = HipTest::setNumBlocks(blocksPerCU, threadsPerBlock, numElements);
|
||||
hipLaunchKernelGGL(memcpyIntKernel, dim3(blocks), dim3(threadsPerBlock), 0, gpu0Stream,
|
||||
dataGpu0_0, dataGpu1, numElements);
|
||||
dataGpu0_0, dataGpu1, numElements);
|
||||
}
|
||||
|
||||
if(!hostSync) {
|
||||
if (!hostSync) {
|
||||
HIPCHECK(hipEventRecord(e, stepAStream));
|
||||
HIPCHECK(hipStreamWaitEvent(gpu1Stream, e, 0));
|
||||
} else {
|
||||
HIPCHECK(hipStreamSynchronize(stepAStream));
|
||||
}
|
||||
|
||||
HIPCHECK(hipMemcpyAsync(dataGpu0_1, dataGpu1, sizeElements, hipMemcpyDeviceToDevice, gpu1Stream));
|
||||
HIPCHECK(
|
||||
hipMemcpyAsync(dataGpu0_1, dataGpu1, sizeElements, hipMemcpyDeviceToDevice, gpu1Stream));
|
||||
|
||||
if(!hostSync) {
|
||||
if (!hostSync) {
|
||||
HIPCHECK(hipEventRecord(e, gpu1Stream));
|
||||
} else {
|
||||
HIPCHECK(hipStreamSynchronize(gpu1Stream));
|
||||
@@ -134,16 +131,15 @@ void runTestImpl(bool stepAIsCopy, bool hostSync, hipStream_t gpu0Stream, hipStr
|
||||
HIPCHECK(hipStreamSynchronize(gpu0Stream));
|
||||
|
||||
checkReverse(dataHost, numElements, expected);
|
||||
if(!hostSync) {
|
||||
if (!hostSync) {
|
||||
HIPCHECK(hipEventDestroy(e));
|
||||
}
|
||||
}
|
||||
|
||||
void testMultiGpu(int dev0, int dev1, int numElements, bool hostSync)
|
||||
{
|
||||
void testMultiGpu(int dev0, int dev1, int numElements, bool hostSync) {
|
||||
const size_t sizeElements = numElements * sizeof(int);
|
||||
|
||||
int * dataGpu0_0, * dataGpu0_1, *dataGpu1, *dataHost;
|
||||
int *dataGpu0_0, *dataGpu0_1, *dataGpu1, *dataHost;
|
||||
hipStream_t gpu0Stream, gpu1Stream;
|
||||
const int expected = 42;
|
||||
unsigned blocks = HipTest::setNumBlocks(blocksPerCU, threadsPerBlock, numElements);
|
||||
@@ -172,8 +168,9 @@ void testMultiGpu(int dev0, int dev1, int numElements, bool hostSync)
|
||||
hc::am_memtracker_print(0x0);
|
||||
#endif
|
||||
|
||||
printf (" test: init complete\n");
|
||||
runTestImpl(true, hostSync, gpu0Stream, gpu1Stream, numElements, dataGpu0_0,dataGpu0_1, dataGpu1, dataHost, expected);
|
||||
printf(" test: init complete\n");
|
||||
runTestImpl(true, hostSync, gpu0Stream, gpu1Stream, numElements, dataGpu0_0, dataGpu0_1,
|
||||
dataGpu1, dataHost, expected);
|
||||
|
||||
HIPCHECK(hipFree(dataGpu0_0));
|
||||
HIPCHECK(hipFree(dataGpu0_1));
|
||||
@@ -184,8 +181,7 @@ void testMultiGpu(int dev0, int dev1, int numElements, bool hostSync)
|
||||
HIPCHECK(hipStreamDestroy(gpu1Stream));
|
||||
};
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int main(int argc, char* argv[]) {
|
||||
HipTest::parseStandardArguments(argc, argv, true);
|
||||
|
||||
|
||||
@@ -199,14 +195,14 @@ int main(int argc, char *argv[])
|
||||
passed();
|
||||
}
|
||||
|
||||
if (enablePeers(dev0,dev1) == -1) {
|
||||
printf ("warning : could not find peer gpus\n");
|
||||
if (enablePeers(dev0, dev1) == -1) {
|
||||
printf("warning : could not find peer gpus\n");
|
||||
return -1;
|
||||
};
|
||||
|
||||
for(int index = 0;index < nSizes;index++) {
|
||||
testMultiGpu(dev0, dev1, elementSizes[index] , false /*GPU Synchronization*/);
|
||||
testMultiGpu(dev0, dev1, elementSizes[index] , true /*Host Synchronization*/);
|
||||
for (int index = 0; index < nSizes; index++) {
|
||||
testMultiGpu(dev0, dev1, elementSizes[index], false /*GPU Synchronization*/);
|
||||
testMultiGpu(dev0, dev1, elementSizes[index], true /*Host Synchronization*/);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -23,14 +23,13 @@ THE SOFTWARE.
|
||||
* HIT_END
|
||||
*/
|
||||
|
||||
#include<hip/hip_runtime_api.h>
|
||||
#include<iostream>
|
||||
#include"test_common.h"
|
||||
#include <hip/hip_runtime_api.h>
|
||||
#include <iostream>
|
||||
#include "test_common.h"
|
||||
|
||||
int main(){
|
||||
hipFuncCache_t cacheConfig;
|
||||
void *func;
|
||||
hipFuncSetCacheConfig(func, cacheConfig);
|
||||
passed();
|
||||
int main() {
|
||||
hipFuncCache_t cacheConfig;
|
||||
void* func;
|
||||
hipFuncSetCacheConfig(func, cacheConfig);
|
||||
passed();
|
||||
}
|
||||
|
||||
|
||||
@@ -19,79 +19,76 @@ THE SOFTWARE.
|
||||
|
||||
#include "hip/hip_runtime.h"
|
||||
#include "hip/hip_runtime_api.h"
|
||||
#include<iostream>
|
||||
#include<fstream>
|
||||
#include<vector>
|
||||
#include<thread>
|
||||
#include<chrono>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <vector>
|
||||
#include <thread>
|
||||
#include <chrono>
|
||||
|
||||
#include "test_common.h"
|
||||
|
||||
#define LEN 64
|
||||
#define SIZE LEN<<2
|
||||
#define SIZE LEN << 2
|
||||
|
||||
#define fileName "vcpy_kernel.code"
|
||||
#define kernel_name "hello_world"
|
||||
|
||||
__global__ void Cpy(hipLaunchParm lp, float *Ad, float* Bd){
|
||||
int tx = threadIdx.x;
|
||||
Bd[tx] = Ad[tx];
|
||||
__global__ void Cpy(hipLaunchParm lp, float* Ad, float* Bd) {
|
||||
int tx = threadIdx.x;
|
||||
Bd[tx] = Ad[tx];
|
||||
}
|
||||
|
||||
int main(){
|
||||
float *A, *B, *Ad, *Bd;
|
||||
A = new float[LEN];
|
||||
B = new float[LEN];
|
||||
int main() {
|
||||
float *A, *B, *Ad, *Bd;
|
||||
A = new float[LEN];
|
||||
B = new float[LEN];
|
||||
|
||||
for(uint32_t i=0;i<LEN;i++){
|
||||
A[i] = i*1.0f;
|
||||
B[i] = 0.0f;
|
||||
}
|
||||
for (uint32_t i = 0; i < LEN; i++) {
|
||||
A[i] = i * 1.0f;
|
||||
B[i] = 0.0f;
|
||||
}
|
||||
|
||||
HIPCHECK(hipMalloc((void**)&Ad, SIZE));
|
||||
HIPCHECK(hipMalloc((void**)&Bd, SIZE));
|
||||
HIPCHECK(hipMalloc((void**)&Ad, SIZE));
|
||||
HIPCHECK(hipMalloc((void**)&Bd, SIZE));
|
||||
|
||||
HIPCHECK(hipMemcpy(Ad, A, SIZE, hipMemcpyHostToDevice));
|
||||
HIPCHECK(hipMemcpy(Bd, B, SIZE, hipMemcpyHostToDevice));
|
||||
hipModule_t Module;
|
||||
hipFunction_t Function;
|
||||
HIPCHECK(hipModuleLoad(&Module, fileName));
|
||||
HIPCHECK(hipModuleGetFunction(&Function, Module, kernel_name));
|
||||
hipFunction_t f;
|
||||
HIPCHECK(hipModuleGetFunction(&f, Module, kernel_name));
|
||||
assert(f == Function);
|
||||
hipStream_t stream;
|
||||
HIPCHECK(hipStreamCreate(&stream));
|
||||
void *args[2] = {&Ad, &Bd};
|
||||
HIPCHECK(hipMemcpy(Ad, A, SIZE, hipMemcpyHostToDevice));
|
||||
HIPCHECK(hipMemcpy(Bd, B, SIZE, hipMemcpyHostToDevice));
|
||||
hipModule_t Module;
|
||||
hipFunction_t Function;
|
||||
HIPCHECK(hipModuleLoad(&Module, fileName));
|
||||
HIPCHECK(hipModuleGetFunction(&Function, Module, kernel_name));
|
||||
hipFunction_t f;
|
||||
HIPCHECK(hipModuleGetFunction(&f, Module, kernel_name));
|
||||
assert(f == Function);
|
||||
hipStream_t stream;
|
||||
HIPCHECK(hipStreamCreate(&stream));
|
||||
void* args[2] = {&Ad, &Bd};
|
||||
|
||||
std::vector<void*>argBuffer(5);
|
||||
memcpy(&argBuffer[3], &Ad, sizeof(void*));
|
||||
memcpy(&argBuffer[4], &Bd, sizeof(void*));
|
||||
std::vector<void*> argBuffer(5);
|
||||
memcpy(&argBuffer[3], &Ad, sizeof(void*));
|
||||
memcpy(&argBuffer[4], &Bd, sizeof(void*));
|
||||
|
||||
size_t size = argBuffer.size()*sizeof(void*);
|
||||
size_t size = argBuffer.size() * sizeof(void*);
|
||||
|
||||
void *config[] = {
|
||||
HIP_LAUNCH_PARAM_BUFFER_POINTER, &argBuffer[0],
|
||||
HIP_LAUNCH_PARAM_BUFFER_SIZE, &size,
|
||||
HIP_LAUNCH_PARAM_END
|
||||
};
|
||||
void* config[] = {HIP_LAUNCH_PARAM_BUFFER_POINTER, &argBuffer[0], HIP_LAUNCH_PARAM_BUFFER_SIZE,
|
||||
&size, HIP_LAUNCH_PARAM_END};
|
||||
|
||||
hipModuleLaunchKernel(Function, 1, 1, 1, LEN, 1, 1, 0, stream, NULL, (void**)&config);
|
||||
hipModuleLaunchKernel(Function, 1, 1, 1, LEN, 1, 1, 0, stream, NULL, (void**)&config);
|
||||
|
||||
HIPCHECK(hipStreamDestroy(stream));
|
||||
HIPCHECK(hipStreamDestroy(stream));
|
||||
|
||||
HIPCHECK(hipMemcpy(B, Bd, SIZE, hipMemcpyDeviceToHost));
|
||||
HIPCHECK(hipMemcpy(B, Bd, SIZE, hipMemcpyDeviceToHost));
|
||||
|
||||
for(uint32_t i=0;i<LEN;i++){
|
||||
assert(A[i] == B[i]);
|
||||
}
|
||||
for (uint32_t i = 0; i < LEN; i++) {
|
||||
assert(A[i] == B[i]);
|
||||
}
|
||||
|
||||
std::vector<hipFunction_t> vec(1024*1024*64);
|
||||
for(unsigned i=0;i<1024*1024*64;i++) {
|
||||
hipFunction_t func;
|
||||
hipModuleGetFunction(&func, Module, kernel_name);
|
||||
vec[i] = func;
|
||||
}
|
||||
passed();
|
||||
return 0;
|
||||
std::vector<hipFunction_t> vec(1024 * 1024 * 64);
|
||||
for (unsigned i = 0; i < 1024 * 1024 * 64; i++) {
|
||||
hipFunction_t func;
|
||||
hipModuleGetFunction(&func, Module, kernel_name);
|
||||
vec[i] = func;
|
||||
}
|
||||
passed();
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -19,13 +19,12 @@ THE SOFTWARE.
|
||||
|
||||
#include "hip/hip_runtime.h"
|
||||
#include "hip/hip_runtime_api.h"
|
||||
#include<iostream>
|
||||
#include <iostream>
|
||||
|
||||
#define fileName "vcpy_isa.co"
|
||||
|
||||
int main(){
|
||||
int main() {
|
||||
hipModule_t module;
|
||||
hipModuleLoad(&module, fileName);
|
||||
hipModuleUnload(module);
|
||||
}
|
||||
|
||||
|
||||
@@ -22,9 +22,7 @@ THE SOFTWARE.
|
||||
|
||||
#include "hip/hip_runtime.h"
|
||||
|
||||
extern "C" __global__ void hello_world(hipLaunchParm lp, float *a, float *b)
|
||||
{
|
||||
extern "C" __global__ void hello_world(hipLaunchParm lp, float* a, float* b) {
|
||||
int tx = threadIdx.x;
|
||||
b[tx] = a[tx];
|
||||
}
|
||||
|
||||
|
||||
+37
-40
@@ -11,25 +11,24 @@
|
||||
|
||||
|
||||
// Create a lot of streams and then destroy 'em.
|
||||
void createThenDestroyStreams(int iterations, int burstSize)
|
||||
{
|
||||
hipStream_t *streams = new hipStream_t[burstSize];
|
||||
void createThenDestroyStreams(int iterations, int burstSize) {
|
||||
hipStream_t* streams = new hipStream_t[burstSize];
|
||||
|
||||
for (int i=0; i<iterations; i++) {
|
||||
for (int i = 0; i < iterations; i++) {
|
||||
if (p_verbose & 0x1) {
|
||||
printf ("%s iter=%d, create %d then destroy %d\n", __func__, i, burstSize, burstSize);
|
||||
printf("%s iter=%d, create %d then destroy %d\n", __func__, i, burstSize, burstSize);
|
||||
}
|
||||
for (int j=0; j<burstSize; j++) {
|
||||
for (int j = 0; j < burstSize; j++) {
|
||||
if (p_verbose & 0x2) {
|
||||
printf (" %d.%d streamCreate\n", i, j);
|
||||
printf(" %d.%d streamCreate\n", i, j);
|
||||
}
|
||||
HIPCHECK( hipStreamCreate(&streams[j]));
|
||||
HIPCHECK(hipStreamCreate(&streams[j]));
|
||||
}
|
||||
for (int j=0; j<burstSize; j++) {
|
||||
for (int j = 0; j < burstSize; j++) {
|
||||
if (p_verbose & 0x2) {
|
||||
printf (" %d.%d streamDestroy\n", i, j);
|
||||
printf(" %d.%d streamDestroy\n", i, j);
|
||||
}
|
||||
HIPCHECK( hipStreamDestroy(streams[j]));
|
||||
HIPCHECK(hipStreamDestroy(streams[j]));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,11 +36,11 @@ void createThenDestroyStreams(int iterations, int burstSize)
|
||||
}
|
||||
|
||||
|
||||
void waitStreams(int iterations)
|
||||
{
|
||||
void waitStreams(int iterations) {
|
||||
// Repeatedly sync and wait for all streams to complete.
|
||||
// TO make this interesting, the test has other threads repeatedly adding and removing streams to the device.
|
||||
for (int i=0; i<iterations; i++) {
|
||||
// TO make this interesting, the test has other threads repeatedly adding and removing streams
|
||||
// to the device.
|
||||
for (int i = 0; i < iterations; i++) {
|
||||
HIPCHECK(hipDeviceSynchronize());
|
||||
}
|
||||
}
|
||||
@@ -50,22 +49,21 @@ void waitStreams(int iterations)
|
||||
// Create 3 streams, all creating and destroying streams on the same device.
|
||||
// Some create many queue, some not many.
|
||||
//
|
||||
void multiThread_pyramid(bool serialize, int iters)
|
||||
{
|
||||
printf ("%s creating %d streams\n", __func__, iters*100);
|
||||
std::thread t1 (createThenDestroyStreams, iters*1, 100);
|
||||
void multiThread_pyramid(bool serialize, int iters) {
|
||||
printf("%s creating %d streams\n", __func__, iters * 100);
|
||||
std::thread t1(createThenDestroyStreams, iters * 1, 100);
|
||||
if (serialize) {
|
||||
t1.join();
|
||||
printf("t1 done\n");
|
||||
}
|
||||
|
||||
std::thread t2 (createThenDestroyStreams, iters*10, 10);
|
||||
std::thread t2(createThenDestroyStreams, iters * 10, 10);
|
||||
if (serialize) {
|
||||
t2.join();
|
||||
printf("t2 done\n");
|
||||
}
|
||||
|
||||
std::thread t3 (createThenDestroyStreams, iters*100, 1);
|
||||
std::thread t3(createThenDestroyStreams, iters * 100, 1);
|
||||
if (serialize) {
|
||||
t3.join();
|
||||
printf("t3 done\n");
|
||||
@@ -76,69 +74,68 @@ void multiThread_pyramid(bool serialize, int iters)
|
||||
t2.join();
|
||||
t3.join();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
// Create 3 streams, all creating and destroying streams on the same device.
|
||||
// Try to keep number of streams near zero, to cause problems.
|
||||
void multiThread_nearzero(bool serialize, int iters)
|
||||
{
|
||||
printf ("%s creating %d streams x 3 threads\n", __func__, iters);
|
||||
std::thread t1 (createThenDestroyStreams, iters, 1);
|
||||
void multiThread_nearzero(bool serialize, int iters) {
|
||||
printf("%s creating %d streams x 3 threads\n", __func__, iters);
|
||||
std::thread t1(createThenDestroyStreams, iters, 1);
|
||||
if (serialize) {
|
||||
t1.join();
|
||||
printf("t1 done\n");
|
||||
}
|
||||
|
||||
std::thread t2 (createThenDestroyStreams, iters, 1);
|
||||
std::thread t2(createThenDestroyStreams, iters, 1);
|
||||
if (serialize) {
|
||||
t2.join();
|
||||
printf("t2 done\n");
|
||||
}
|
||||
|
||||
std::thread t3 (waitStreams, iters*50);
|
||||
std::thread t3(waitStreams, iters * 50);
|
||||
if (serialize) {
|
||||
t3.join();
|
||||
printf("t3 done\n");
|
||||
}
|
||||
|
||||
if (!serialize) {
|
||||
t1.join(); printf ("t1 done\n");
|
||||
t2.join(); printf ("t2 done\n");
|
||||
t3.join(); printf ("t3 done\n");
|
||||
t1.join();
|
||||
printf("t1 done\n");
|
||||
t2.join();
|
||||
printf("t2 done\n");
|
||||
t3.join();
|
||||
printf("t3 done\n");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int main(int argc, char* argv[]) {
|
||||
HipTest::parseStandardArguments(argc, argv, true);
|
||||
|
||||
// Serial version, just call once:
|
||||
if (p_tests & 0x1) {
|
||||
printf ("\ntest 0x1 : serial createThenDestroyStreams(10) \n");
|
||||
printf("\ntest 0x1 : serial createThenDestroyStreams(10) \n");
|
||||
createThenDestroyStreams(10, 10);
|
||||
};
|
||||
|
||||
/*disable, this takess a while and if the next one works then no need to run serial*/
|
||||
if (1 && (p_tests & 0x2)) {
|
||||
printf ("\ntest 0x2 : serialized multiThread_pyramid(1) \n");
|
||||
printf("\ntest 0x2 : serialized multiThread_pyramid(1) \n");
|
||||
multiThread_pyramid(true, 3);
|
||||
}
|
||||
|
||||
if (p_tests & 0x4) {
|
||||
printf ("\ntest 0x4 : parallel multiThread_pyramid(1) \n");
|
||||
printf("\ntest 0x4 : parallel multiThread_pyramid(1) \n");
|
||||
multiThread_pyramid(false, 3);
|
||||
}
|
||||
|
||||
//if (p_tests & 0x8) {
|
||||
// if (p_tests & 0x8) {
|
||||
// printf ("test 0x8 : multiThread_pyramid(100) \n");
|
||||
// multiThread_pyramid(false, 100);
|
||||
// }
|
||||
// }
|
||||
|
||||
if (p_tests & 0x10) {
|
||||
printf ("\ntest 0x10 : parallel multiThread_nearzero(1000) \n");
|
||||
printf("\ntest 0x10 : parallel multiThread_nearzero(1000) \n");
|
||||
multiThread_nearzero(false, 1000);
|
||||
}
|
||||
|
||||
|
||||
+75
-87
@@ -29,106 +29,91 @@ THE SOFTWARE.
|
||||
#include "hip/hip_runtime.h"
|
||||
#include "test_common.h"
|
||||
|
||||
int p_iters=10;
|
||||
int p_iters = 10;
|
||||
|
||||
void printSep()
|
||||
{
|
||||
printf ("======================================================================================\n");
|
||||
void printSep() {
|
||||
printf(
|
||||
"======================================================================================\n");
|
||||
}
|
||||
|
||||
//---
|
||||
// Test simple H2D copies and back.
|
||||
// Designed to stress a small number of simple smoke tests
|
||||
|
||||
template<
|
||||
typename T=float,
|
||||
class P=HipTest::Unpinned,
|
||||
class C=HipTest::Memcpy
|
||||
>
|
||||
void simpleVectorAdd(size_t numElements, int iters, hipStream_t stream)
|
||||
{
|
||||
using HipTest::MemTraits;
|
||||
template <typename T = float, class P = HipTest::Unpinned, class C = HipTest::Memcpy>
|
||||
void simpleVectorAdd(size_t numElements, int iters, hipStream_t stream) {
|
||||
using HipTest::MemTraits;
|
||||
|
||||
std::thread::id pid = std::this_thread::get_id();
|
||||
std::thread::id pid = std::this_thread::get_id();
|
||||
|
||||
printf ("test: %s <%s> %s %s\n", __func__, TYPENAME(T), P::str(), C::str());
|
||||
size_t Nbytes = numElements*sizeof(T);
|
||||
printf ("numElements=%zu Nbytes=%6.2fMB\n", numElements, Nbytes/1024.0/1024.0);
|
||||
printf("test: %s <%s> %s %s\n", __func__, TYPENAME(T), P::str(), C::str());
|
||||
size_t Nbytes = numElements * sizeof(T);
|
||||
printf("numElements=%zu Nbytes=%6.2fMB\n", numElements, Nbytes / 1024.0 / 1024.0);
|
||||
|
||||
T *A_d, *B_d, *C_d;
|
||||
T *A_h, *B_h, *C_h;
|
||||
|
||||
HipTest::initArrays (&A_d, &B_d, &C_d, &A_h, &B_h, &C_h, N, P::isPinned);
|
||||
for (size_t i=0; i<numElements; i++) {
|
||||
A_h[i] = 1000.0f;
|
||||
B_h[i] = 2000.0f;
|
||||
C_h[i] = -1;
|
||||
}
|
||||
HipTest::initArrays(&A_d, &B_d, &C_d, &A_h, &B_h, &C_h, N, P::isPinned);
|
||||
for (size_t i = 0; i < numElements; i++) {
|
||||
A_h[i] = 1000.0f;
|
||||
B_h[i] = 2000.0f;
|
||||
C_h[i] = -1;
|
||||
}
|
||||
|
||||
|
||||
MemTraits<C>::Copy(B_d, B_h, Nbytes, hipMemcpyHostToDevice, stream);
|
||||
MemTraits<C>::Copy(A_d, A_h, Nbytes, hipMemcpyHostToDevice, stream);
|
||||
MemTraits<C>::Copy(C_d, C_h, Nbytes, hipMemcpyHostToDevice, stream);
|
||||
HIPCHECK (hipDeviceSynchronize());
|
||||
MemTraits<C>::Copy(B_d, B_h, Nbytes, hipMemcpyHostToDevice, stream);
|
||||
MemTraits<C>::Copy(A_d, A_h, Nbytes, hipMemcpyHostToDevice, stream);
|
||||
MemTraits<C>::Copy(C_d, C_h, Nbytes, hipMemcpyHostToDevice, stream);
|
||||
HIPCHECK(hipDeviceSynchronize());
|
||||
|
||||
for (size_t i=0; i<numElements; i++) {
|
||||
A_h[i] = 1.0f;
|
||||
B_h[i] = 2.0f;
|
||||
C_h[i] = -1;
|
||||
}
|
||||
for (size_t i = 0; i < numElements; i++) {
|
||||
A_h[i] = 1.0f;
|
||||
B_h[i] = 2.0f;
|
||||
C_h[i] = -1;
|
||||
}
|
||||
|
||||
|
||||
for (int i = 0; i < iters; i++) {
|
||||
unsigned blocks = HipTest::setNumBlocks(blocksPerCU, threadsPerBlock, numElements);
|
||||
|
||||
for (int i=0; i<iters; i++) {
|
||||
MemTraits<C>::Copy(A_d, A_h, Nbytes, hipMemcpyHostToDevice, stream);
|
||||
MemTraits<C>::Copy(B_d, B_h, Nbytes, hipMemcpyHostToDevice, stream);
|
||||
|
||||
unsigned blocks = HipTest::setNumBlocks(blocksPerCU, threadsPerBlock, numElements);
|
||||
// HIPCHECK(hipStreamSynchronize(stream));
|
||||
|
||||
MemTraits<C>::Copy(A_d, A_h, Nbytes, hipMemcpyHostToDevice, stream);
|
||||
MemTraits<C>::Copy(B_d, B_h, Nbytes, hipMemcpyHostToDevice, stream);
|
||||
// This is the null stream?
|
||||
// hipLaunchKernel(HipTest::vectorADD, dim3(blocks), dim3(threadsPerBlock), 0, 0, A_d, B_d,
|
||||
// C_d, numElements);
|
||||
hipLaunchKernel(HipTest::vectorADDReverse, dim3(blocks), dim3(threadsPerBlock), 0, 0,
|
||||
static_cast<const T*>(A_d), static_cast<const T*>(B_d), C_d, numElements);
|
||||
|
||||
//HIPCHECK(hipStreamSynchronize(stream));
|
||||
MemTraits<C>::Copy(C_h, C_d, Nbytes, hipMemcpyDeviceToHost, stream);
|
||||
|
||||
// This is the null stream?
|
||||
//hipLaunchKernel(HipTest::vectorADD, dim3(blocks), dim3(threadsPerBlock), 0, 0, A_d, B_d, C_d, numElements);
|
||||
hipLaunchKernel(
|
||||
HipTest::vectorADDReverse,
|
||||
dim3(blocks),
|
||||
dim3(threadsPerBlock),
|
||||
0,
|
||||
0,
|
||||
static_cast<const T*>(A_d),
|
||||
static_cast<const T*>(B_d),
|
||||
C_d,
|
||||
numElements);
|
||||
HIPCHECK(hipDeviceSynchronize());
|
||||
|
||||
MemTraits<C>::Copy(C_h, C_d, Nbytes, hipMemcpyDeviceToHost, stream);
|
||||
|
||||
HIPCHECK (hipDeviceSynchronize());
|
||||
|
||||
HipTest::checkVectorADD(A_h, B_h, C_h, numElements);
|
||||
}
|
||||
|
||||
HipTest::freeArrays (A_d, B_d, C_d, A_h, B_h, C_h, P::isPinned);
|
||||
std::cout <<" pid" << pid << " success\n";
|
||||
HIPCHECK (hipDeviceSynchronize());
|
||||
HipTest::checkVectorADD(A_h, B_h, C_h, numElements);
|
||||
}
|
||||
|
||||
HipTest::freeArrays(A_d, B_d, C_d, A_h, B_h, C_h, P::isPinned);
|
||||
std::cout << " pid" << pid << " success\n";
|
||||
HIPCHECK(hipDeviceSynchronize());
|
||||
}
|
||||
|
||||
template<typename T, class C>
|
||||
void test_multiThread_1(std::string testName, hipStream_t stream0, hipStream_t stream1, bool serialize)
|
||||
{
|
||||
printSep();
|
||||
printf ("%s\n", __func__);
|
||||
std::cout << testName << std::endl;
|
||||
template <typename T, class C>
|
||||
void test_multiThread_1(std::string testName, hipStream_t stream0, hipStream_t stream1,
|
||||
bool serialize) {
|
||||
printSep();
|
||||
printf("%s\n", __func__);
|
||||
std::cout << testName << std::endl;
|
||||
|
||||
size_t numElements = N;
|
||||
size_t numElements = N;
|
||||
|
||||
// Test 2 threads operating on same stream:
|
||||
std::thread t1 (simpleVectorAdd<T, HipTest::Pinned, C>, numElements, p_iters/*iters*/, stream0);
|
||||
// Test 2 threads operating on same stream:
|
||||
std::thread t1(simpleVectorAdd<T, HipTest::Pinned, C>, numElements, p_iters /*iters*/, stream0);
|
||||
if (serialize) {
|
||||
t1.join();
|
||||
}
|
||||
std::thread t2 (simpleVectorAdd<T, HipTest::Pinned, C>, numElements, p_iters/*iters*/, stream1);
|
||||
std::thread t2(simpleVectorAdd<T, HipTest::Pinned, C>, numElements, p_iters /*iters*/, stream1);
|
||||
if (serialize) {
|
||||
t2.join();
|
||||
}
|
||||
@@ -138,48 +123,51 @@ void test_multiThread_1(std::string testName, hipStream_t stream0, hipStream_t s
|
||||
t2.join();
|
||||
}
|
||||
|
||||
HIPCHECK(hipDeviceSynchronize());
|
||||
HIPCHECK(hipDeviceSynchronize());
|
||||
};
|
||||
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
N = 8000000;
|
||||
int main(int argc, char* argv[]) {
|
||||
N = 8000000;
|
||||
HipTest::parseStandardArguments(argc, argv, true);
|
||||
|
||||
printf ("info: set device to %d\n", p_gpuDevice);
|
||||
printf("info: set device to %d\n", p_gpuDevice);
|
||||
HIPCHECK(hipSetDevice(p_gpuDevice));
|
||||
|
||||
|
||||
if (p_tests & 0x1) {
|
||||
HIPCHECK ( hipDeviceReset() );
|
||||
HIPCHECK(hipDeviceReset());
|
||||
|
||||
hipStream_t stream;
|
||||
HIPCHECK (hipStreamCreate(&stream));
|
||||
HIPCHECK(hipStreamCreate(&stream));
|
||||
|
||||
simpleVectorAdd<float, HipTest::Pinned, HipTest::MemcpyAsync> (N/*mb*/, 10/*iters*/, stream);
|
||||
simpleVectorAdd<float, HipTest::Pinned, HipTest::Memcpy> (N/*mb*/, 10/*iters*/, stream);
|
||||
simpleVectorAdd<float, HipTest::Pinned, HipTest::MemcpyAsync>(N /*mb*/, 10 /*iters*/,
|
||||
stream);
|
||||
simpleVectorAdd<float, HipTest::Pinned, HipTest::Memcpy>(N /*mb*/, 10 /*iters*/, stream);
|
||||
|
||||
HIPCHECK(hipStreamDestroy(stream));
|
||||
}
|
||||
|
||||
|
||||
hipStream_t stream0, stream1;
|
||||
HIPCHECK (hipStreamCreate(&stream0));
|
||||
HIPCHECK (hipStreamCreate(&stream1));
|
||||
HIPCHECK(hipStreamCreate(&stream0));
|
||||
HIPCHECK(hipStreamCreate(&stream1));
|
||||
|
||||
if (p_tests & 0x2) {
|
||||
// Easy tests to verify the test works - these don't allow overlap between the threads:
|
||||
test_multiThread_1<float, HipTest::MemcpyAsync> ("Multithread NULL with serialized", NULL, NULL, true);
|
||||
test_multiThread_1<float, HipTest::MemcpyAsync> ("Multithread two streams serialized", stream0, stream1, true);
|
||||
// Easy tests to verify the test works - these don't allow overlap between the threads:
|
||||
test_multiThread_1<float, HipTest::MemcpyAsync>("Multithread NULL with serialized", NULL,
|
||||
NULL, true);
|
||||
test_multiThread_1<float, HipTest::MemcpyAsync>("Multithread two streams serialized",
|
||||
stream0, stream1, true);
|
||||
}
|
||||
|
||||
if (p_tests & 0x4) {
|
||||
//test_multiThread_1<float, HipTest::MemcpyAsync> ("Multithread with NULL stream", NULL, NULL, false);
|
||||
//test_multiThread_1<float, HipTest::MemcpyAsync> ("Multithread with two streams", stream0, stream1, false);
|
||||
test_multiThread_1<float, HipTest::MemcpyAsync> ("Multithread with one stream", stream0, stream0, false);
|
||||
}
|
||||
// test_multiThread_1<float, HipTest::MemcpyAsync> ("Multithread with NULL stream", NULL,
|
||||
// NULL, false); test_multiThread_1<float, HipTest::MemcpyAsync> ("Multithread with two
|
||||
// streams", stream0, stream1, false);
|
||||
test_multiThread_1<float, HipTest::MemcpyAsync>("Multithread with one stream", stream0,
|
||||
stream0, false);
|
||||
}
|
||||
|
||||
passed();
|
||||
|
||||
}
|
||||
|
||||
+69
-73
@@ -26,70 +26,69 @@ THE SOFTWARE.
|
||||
* HIT_END
|
||||
*/
|
||||
|
||||
#include<iostream>
|
||||
#include"test_common.h"
|
||||
#include<thread>
|
||||
#include <iostream>
|
||||
#include "test_common.h"
|
||||
#include <thread>
|
||||
#define N 1000
|
||||
|
||||
|
||||
|
||||
template<typename T>
|
||||
__global__ void Inc(hipLaunchParm lp, T *Array){
|
||||
int tx = threadIdx.x + blockIdx.x * blockDim.x;
|
||||
Array[tx] = Array[tx] + T(1);
|
||||
template <typename T>
|
||||
__global__ void Inc(hipLaunchParm lp, T* Array) {
|
||||
int tx = threadIdx.x + blockIdx.x * blockDim.x;
|
||||
Array[tx] = Array[tx] + T(1);
|
||||
}
|
||||
|
||||
void run1(size_t size, hipStream_t stream){
|
||||
float *Ah, *Bh, *Cd, *Dd, *Eh;
|
||||
void run1(size_t size, hipStream_t stream) {
|
||||
float *Ah, *Bh, *Cd, *Dd, *Eh;
|
||||
|
||||
HIPCHECK(hipHostMalloc((void**)&Ah, size, hipHostMallocDefault));
|
||||
HIPCHECK(hipHostMalloc((void**)&Bh, size, hipHostMallocDefault));
|
||||
HIPCHECK(hipMalloc(&Cd, size));
|
||||
HIPCHECK(hipMalloc(&Dd, size));
|
||||
HIPCHECK(hipHostMalloc((void**)&Eh, size, hipHostMallocDefault));
|
||||
HIPCHECK(hipHostMalloc((void**)&Ah, size, hipHostMallocDefault));
|
||||
HIPCHECK(hipHostMalloc((void**)&Bh, size, hipHostMallocDefault));
|
||||
HIPCHECK(hipMalloc(&Cd, size));
|
||||
HIPCHECK(hipMalloc(&Dd, size));
|
||||
HIPCHECK(hipHostMalloc((void**)&Eh, size, hipHostMallocDefault));
|
||||
|
||||
for(int i=0;i<N;i++){
|
||||
Ah[i] = 1.0f;
|
||||
}
|
||||
for (int i = 0; i < N; i++) {
|
||||
Ah[i] = 1.0f;
|
||||
}
|
||||
|
||||
HIPCHECK(hipMemcpyAsync(Bh, Ah, size, hipMemcpyHostToHost, stream));
|
||||
HIPCHECK(hipMemcpyAsync(Cd, Bh, size, hipMemcpyHostToDevice, stream));
|
||||
hipLaunchKernel(HIP_KERNEL_NAME(Inc), dim3(N/500), dim3(500), 0, stream, Cd);
|
||||
HIPCHECK(hipMemcpyAsync(Dd, Cd, size, hipMemcpyDeviceToDevice, stream));
|
||||
HIPCHECK(hipMemcpyAsync(Eh, Dd, size, hipMemcpyDeviceToHost, stream));
|
||||
HIPCHECK(hipDeviceSynchronize());
|
||||
HIPASSERT(Eh[10] == Ah[10] + 1.0f);
|
||||
HIPCHECK(hipMemcpyAsync(Bh, Ah, size, hipMemcpyHostToHost, stream));
|
||||
HIPCHECK(hipMemcpyAsync(Cd, Bh, size, hipMemcpyHostToDevice, stream));
|
||||
hipLaunchKernel(HIP_KERNEL_NAME(Inc), dim3(N / 500), dim3(500), 0, stream, Cd);
|
||||
HIPCHECK(hipMemcpyAsync(Dd, Cd, size, hipMemcpyDeviceToDevice, stream));
|
||||
HIPCHECK(hipMemcpyAsync(Eh, Dd, size, hipMemcpyDeviceToHost, stream));
|
||||
HIPCHECK(hipDeviceSynchronize());
|
||||
HIPASSERT(Eh[10] == Ah[10] + 1.0f);
|
||||
}
|
||||
|
||||
|
||||
void run(size_t size, hipStream_t stream1, hipStream_t stream2){
|
||||
float *Ah, *Bh, *Cd, *Dd, *Eh;
|
||||
float *Ahh, *Bhh, *Cdd, *Ddd, *Ehh;
|
||||
void run(size_t size, hipStream_t stream1, hipStream_t stream2) {
|
||||
float *Ah, *Bh, *Cd, *Dd, *Eh;
|
||||
float *Ahh, *Bhh, *Cdd, *Ddd, *Ehh;
|
||||
|
||||
HIPCHECK(hipHostMalloc((void**)&Ah, size, hipHostMallocDefault));
|
||||
HIPCHECK(hipHostMalloc((void**)&Bh, size, hipHostMallocDefault));
|
||||
HIPCHECK(hipMalloc(&Cd, size));
|
||||
HIPCHECK(hipMalloc(&Dd, size));
|
||||
HIPCHECK(hipHostMalloc((void**)&Eh, size, hipHostMallocDefault));
|
||||
HIPCHECK(hipHostMalloc((void**)&Ahh, size, hipHostMallocDefault));
|
||||
HIPCHECK(hipHostMalloc((void**)&Bhh, size, hipHostMallocDefault));
|
||||
HIPCHECK(hipMalloc(&Cdd, size));
|
||||
HIPCHECK(hipMalloc(&Ddd, size));
|
||||
HIPCHECK(hipHostMalloc((void**)&Ehh, size, hipHostMallocDefault));
|
||||
HIPCHECK(hipHostMalloc((void**)&Ah, size, hipHostMallocDefault));
|
||||
HIPCHECK(hipHostMalloc((void**)&Bh, size, hipHostMallocDefault));
|
||||
HIPCHECK(hipMalloc(&Cd, size));
|
||||
HIPCHECK(hipMalloc(&Dd, size));
|
||||
HIPCHECK(hipHostMalloc((void**)&Eh, size, hipHostMallocDefault));
|
||||
HIPCHECK(hipHostMalloc((void**)&Ahh, size, hipHostMallocDefault));
|
||||
HIPCHECK(hipHostMalloc((void**)&Bhh, size, hipHostMallocDefault));
|
||||
HIPCHECK(hipMalloc(&Cdd, size));
|
||||
HIPCHECK(hipMalloc(&Ddd, size));
|
||||
HIPCHECK(hipHostMalloc((void**)&Ehh, size, hipHostMallocDefault));
|
||||
|
||||
HIPCHECK(hipMemcpyAsync(Bh, Ah, size, hipMemcpyHostToHost, stream1));
|
||||
HIPCHECK(hipMemcpyAsync(Bhh, Ahh, size, hipMemcpyHostToHost, stream2));
|
||||
HIPCHECK(hipMemcpyAsync(Cd, Bh, size, hipMemcpyHostToDevice, stream1));
|
||||
HIPCHECK(hipMemcpyAsync(Cdd, Bhh, size, hipMemcpyHostToDevice, stream2));
|
||||
hipLaunchKernel(HIP_KERNEL_NAME(Inc), dim3(N/500), dim3(500), 0, stream1, Cd);
|
||||
hipLaunchKernel(HIP_KERNEL_NAME(Inc), dim3(N/500), dim3(500), 0, stream2, Cdd);
|
||||
HIPCHECK(hipMemcpyAsync(Dd, Cd, size, hipMemcpyDeviceToDevice, stream1));
|
||||
HIPCHECK(hipMemcpyAsync(Ddd, Cdd, size, hipMemcpyDeviceToDevice, stream2));
|
||||
HIPCHECK(hipMemcpyAsync(Eh, Dd, size, hipMemcpyDeviceToHost, stream1));
|
||||
HIPCHECK(hipMemcpyAsync(Ehh, Ddd, size, hipMemcpyDeviceToHost, stream2));
|
||||
HIPCHECK(hipDeviceSynchronize());
|
||||
HIPASSERT(Eh[10] = Ah[10] + 1.0f);
|
||||
HIPASSERT(Ehh[10] = Ahh[10] + 1.0f);
|
||||
HIPCHECK(hipMemcpyAsync(Bh, Ah, size, hipMemcpyHostToHost, stream1));
|
||||
HIPCHECK(hipMemcpyAsync(Bhh, Ahh, size, hipMemcpyHostToHost, stream2));
|
||||
HIPCHECK(hipMemcpyAsync(Cd, Bh, size, hipMemcpyHostToDevice, stream1));
|
||||
HIPCHECK(hipMemcpyAsync(Cdd, Bhh, size, hipMemcpyHostToDevice, stream2));
|
||||
hipLaunchKernel(HIP_KERNEL_NAME(Inc), dim3(N / 500), dim3(500), 0, stream1, Cd);
|
||||
hipLaunchKernel(HIP_KERNEL_NAME(Inc), dim3(N / 500), dim3(500), 0, stream2, Cdd);
|
||||
HIPCHECK(hipMemcpyAsync(Dd, Cd, size, hipMemcpyDeviceToDevice, stream1));
|
||||
HIPCHECK(hipMemcpyAsync(Ddd, Cdd, size, hipMemcpyDeviceToDevice, stream2));
|
||||
HIPCHECK(hipMemcpyAsync(Eh, Dd, size, hipMemcpyDeviceToHost, stream1));
|
||||
HIPCHECK(hipMemcpyAsync(Ehh, Ddd, size, hipMemcpyDeviceToHost, stream2));
|
||||
HIPCHECK(hipDeviceSynchronize());
|
||||
HIPASSERT(Eh[10] = Ah[10] + 1.0f);
|
||||
HIPASSERT(Ehh[10] = Ahh[10] + 1.0f);
|
||||
|
||||
HIPCHECK(hipHostFree(Ah));
|
||||
HIPCHECK(hipHostFree(Bh));
|
||||
@@ -103,31 +102,28 @@ void run(size_t size, hipStream_t stream1, hipStream_t stream2){
|
||||
HIPCHECK(hipFree(Ddd));
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int main(int argc, char** argv) {
|
||||
iterations = 100;
|
||||
|
||||
HipTest::parseStandardArguments(argc, argv, true);
|
||||
HipTest::parseStandardArguments(argc, argv, true);
|
||||
|
||||
|
||||
hipStream_t stream[3];
|
||||
for(int i=0;i<3;i++){
|
||||
HIPCHECK(hipStreamCreate(&stream[i]));
|
||||
}
|
||||
|
||||
const size_t size = N * sizeof(float);
|
||||
|
||||
for (int i=0; i< iterations; i++) {
|
||||
|
||||
std::thread t1(run1, size, stream[0]);
|
||||
std::thread t2(run1, size, stream[0]);
|
||||
std::thread t3(run, size, stream[1], stream[2]);
|
||||
t1.join();
|
||||
// std::cout<<"T1"<<std::endl;
|
||||
t2.join();
|
||||
// std::cout<<"T2"<<std::endl;
|
||||
t3.join();
|
||||
hipStream_t stream[3];
|
||||
for (int i = 0; i < 3; i++) {
|
||||
HIPCHECK(hipStreamCreate(&stream[i]));
|
||||
}
|
||||
passed();
|
||||
}
|
||||
|
||||
const size_t size = N * sizeof(float);
|
||||
|
||||
for (int i = 0; i < iterations; i++) {
|
||||
std::thread t1(run1, size, stream[0]);
|
||||
std::thread t2(run1, size, stream[0]);
|
||||
std::thread t3(run, size, stream[1], stream[2]);
|
||||
t1.join();
|
||||
// std::cout<<"T1"<<std::endl;
|
||||
t2.join();
|
||||
// std::cout<<"T2"<<std::endl;
|
||||
t3.join();
|
||||
}
|
||||
passed();
|
||||
}
|
||||
|
||||
@@ -22,46 +22,46 @@ THE SOFTWARE.
|
||||
* HIT_END
|
||||
*/
|
||||
|
||||
#include<iostream>
|
||||
#include"test_common.h"
|
||||
#include"hip/math_functions.h"
|
||||
#include <iostream>
|
||||
#include "test_common.h"
|
||||
#include "hip/math_functions.h"
|
||||
|
||||
const int NN = 1 << 21;
|
||||
|
||||
__global__ void kernel(hipLaunchParm lp, float *x, float *y, int n){
|
||||
int tid = threadIdx.x;
|
||||
if(tid < 1){
|
||||
for(int i=0;i<n;i++){
|
||||
x[i] = sqrt(powf(3.14159,i));
|
||||
}
|
||||
y[tid] = y[tid] + 1.0f;
|
||||
}
|
||||
__global__ void kernel(hipLaunchParm lp, float* x, float* y, int n) {
|
||||
int tid = threadIdx.x;
|
||||
if (tid < 1) {
|
||||
for (int i = 0; i < n; i++) {
|
||||
x[i] = sqrt(powf(3.14159, i));
|
||||
}
|
||||
y[tid] = y[tid] + 1.0f;
|
||||
}
|
||||
}
|
||||
|
||||
__global__ void nKernel(hipLaunchParm lp, float *y){
|
||||
int tid = threadIdx.x;
|
||||
y[tid] = y[tid] + 1.0f;
|
||||
__global__ void nKernel(hipLaunchParm lp, float* y) {
|
||||
int tid = threadIdx.x;
|
||||
y[tid] = y[tid] + 1.0f;
|
||||
}
|
||||
|
||||
int main(){
|
||||
const int num_streams = 8;
|
||||
hipStream_t streams[num_streams];
|
||||
float *data[num_streams], *yd, *xd;
|
||||
float y = 1.0f, x = 1.0f;
|
||||
HIPCHECK(hipMalloc((void**)&yd, sizeof(float)));
|
||||
HIPCHECK(hipMalloc((void**)&xd, sizeof(float)));
|
||||
HIPCHECK(hipMemcpy(yd, &y, sizeof(float), hipMemcpyHostToDevice));
|
||||
HIPCHECK(hipMemcpy(xd, &x, sizeof(float), hipMemcpyHostToDevice));
|
||||
for(int i=0;i<num_streams;i++){
|
||||
HIPCHECK(hipStreamCreate(&streams[i]));
|
||||
HIPCHECK(hipMalloc(&data[i], NN * sizeof(float)));
|
||||
hipLaunchKernel(HIP_KERNEL_NAME(kernel), dim3(1), dim3(1), 0, streams[i], data[i], xd, N);
|
||||
hipLaunchKernel(HIP_KERNEL_NAME(nKernel), dim3(1), dim3(1), 0, 0, yd);
|
||||
}
|
||||
int main() {
|
||||
const int num_streams = 8;
|
||||
hipStream_t streams[num_streams];
|
||||
float *data[num_streams], *yd, *xd;
|
||||
float y = 1.0f, x = 1.0f;
|
||||
HIPCHECK(hipMalloc((void**)&yd, sizeof(float)));
|
||||
HIPCHECK(hipMalloc((void**)&xd, sizeof(float)));
|
||||
HIPCHECK(hipMemcpy(yd, &y, sizeof(float), hipMemcpyHostToDevice));
|
||||
HIPCHECK(hipMemcpy(xd, &x, sizeof(float), hipMemcpyHostToDevice));
|
||||
for (int i = 0; i < num_streams; i++) {
|
||||
HIPCHECK(hipStreamCreate(&streams[i]));
|
||||
HIPCHECK(hipMalloc(&data[i], NN * sizeof(float)));
|
||||
hipLaunchKernel(HIP_KERNEL_NAME(kernel), dim3(1), dim3(1), 0, streams[i], data[i], xd, N);
|
||||
hipLaunchKernel(HIP_KERNEL_NAME(nKernel), dim3(1), dim3(1), 0, 0, yd);
|
||||
}
|
||||
|
||||
HIPCHECK(hipMemcpy(&x, xd, sizeof(float), hipMemcpyDeviceToHost));
|
||||
HIPCHECK(hipMemcpy(&y, yd, sizeof(float), hipMemcpyDeviceToHost));
|
||||
std::cout<<x<<" "<<y<<std::endl;
|
||||
HIPASSERT(x == y);
|
||||
passed();
|
||||
HIPCHECK(hipMemcpy(&x, xd, sizeof(float), hipMemcpyDeviceToHost));
|
||||
HIPCHECK(hipMemcpy(&y, yd, sizeof(float), hipMemcpyDeviceToHost));
|
||||
std::cout << x << " " << y << std::endl;
|
||||
HIPASSERT(x == y);
|
||||
passed();
|
||||
}
|
||||
|
||||
@@ -24,46 +24,46 @@ THE SOFTWARE.
|
||||
|
||||
//#define HIP_API_PER_THREAD_DEFAULT_STREAM
|
||||
|
||||
#include<iostream>
|
||||
#include"test_common.h"
|
||||
#include"hip/math_functions.h"
|
||||
#include <iostream>
|
||||
#include "test_common.h"
|
||||
#include "hip/math_functions.h"
|
||||
|
||||
const int NN = 1 << 21;
|
||||
|
||||
__global__ void kernel(hipLaunchParm lp, float *x, float *y, int n){
|
||||
int tid = threadIdx.x;
|
||||
if(tid < 1){
|
||||
for(int i=0;i<n;i++){
|
||||
x[i] = sqrt(powf(3.14159,i));
|
||||
}
|
||||
y[tid] = y[tid] + 1.0f;
|
||||
}
|
||||
__global__ void kernel(hipLaunchParm lp, float* x, float* y, int n) {
|
||||
int tid = threadIdx.x;
|
||||
if (tid < 1) {
|
||||
for (int i = 0; i < n; i++) {
|
||||
x[i] = sqrt(powf(3.14159, i));
|
||||
}
|
||||
y[tid] = y[tid] + 1.0f;
|
||||
}
|
||||
}
|
||||
|
||||
__global__ void nKernel(hipLaunchParm lp, float *y){
|
||||
int tid = threadIdx.x;
|
||||
y[tid] = y[tid] + 1.0f;
|
||||
__global__ void nKernel(hipLaunchParm lp, float* y) {
|
||||
int tid = threadIdx.x;
|
||||
y[tid] = y[tid] + 1.0f;
|
||||
}
|
||||
|
||||
int main(){
|
||||
const int num_streams = 8;
|
||||
hipStream_t streams[num_streams];
|
||||
float *data[num_streams], *yd, *xd;
|
||||
float y = 1.0f, x = 1.0f;
|
||||
HIPCHECK(hipMalloc((void**)&yd, sizeof(float)));
|
||||
HIPCHECK(hipMalloc((void**)&xd, sizeof(float)));
|
||||
HIPCHECK(hipMemcpy(yd, &y, sizeof(float), hipMemcpyHostToDevice));
|
||||
HIPCHECK(hipMemcpy(xd, &x, sizeof(float), hipMemcpyHostToDevice));
|
||||
for(int i=0;i<num_streams;i++){
|
||||
HIPCHECK(hipStreamCreate(&streams[i]));
|
||||
HIPCHECK(hipMalloc(&data[i], NN * sizeof(float)));
|
||||
hipLaunchKernel(HIP_KERNEL_NAME(kernel), dim3(1), dim3(1), 0, streams[i], data[i], xd, N);
|
||||
hipLaunchKernel(HIP_KERNEL_NAME(nKernel), dim3(1), dim3(1), 0, 0, yd);
|
||||
}
|
||||
int main() {
|
||||
const int num_streams = 8;
|
||||
hipStream_t streams[num_streams];
|
||||
float *data[num_streams], *yd, *xd;
|
||||
float y = 1.0f, x = 1.0f;
|
||||
HIPCHECK(hipMalloc((void**)&yd, sizeof(float)));
|
||||
HIPCHECK(hipMalloc((void**)&xd, sizeof(float)));
|
||||
HIPCHECK(hipMemcpy(yd, &y, sizeof(float), hipMemcpyHostToDevice));
|
||||
HIPCHECK(hipMemcpy(xd, &x, sizeof(float), hipMemcpyHostToDevice));
|
||||
for (int i = 0; i < num_streams; i++) {
|
||||
HIPCHECK(hipStreamCreate(&streams[i]));
|
||||
HIPCHECK(hipMalloc(&data[i], NN * sizeof(float)));
|
||||
hipLaunchKernel(HIP_KERNEL_NAME(kernel), dim3(1), dim3(1), 0, streams[i], data[i], xd, N);
|
||||
hipLaunchKernel(HIP_KERNEL_NAME(nKernel), dim3(1), dim3(1), 0, 0, yd);
|
||||
}
|
||||
|
||||
HIPCHECK(hipMemcpy(&x, xd, sizeof(float), hipMemcpyDeviceToHost));
|
||||
HIPCHECK(hipMemcpy(&y, yd, sizeof(float), hipMemcpyDeviceToHost));
|
||||
std::cout<<x<<" "<<y<<std::endl;
|
||||
HIPASSERT(x<y);
|
||||
passed();
|
||||
HIPCHECK(hipMemcpy(&x, xd, sizeof(float), hipMemcpyDeviceToHost));
|
||||
HIPCHECK(hipMemcpy(&y, yd, sizeof(float), hipMemcpyDeviceToHost));
|
||||
std::cout << x << " " << y << std::endl;
|
||||
HIPASSERT(x < y);
|
||||
passed();
|
||||
}
|
||||
|
||||
@@ -27,39 +27,31 @@ THE SOFTWARE.
|
||||
#include "hip/hip_runtime.h"
|
||||
#include "test_common.h"
|
||||
#include <vector>
|
||||
unsigned p_streams =16;
|
||||
int p_repeat = 10;
|
||||
int p_db = 0;
|
||||
unsigned p_streams = 16;
|
||||
int p_repeat = 10;
|
||||
int p_db = 0;
|
||||
|
||||
|
||||
template <typename T>
|
||||
__global__ void
|
||||
vectorADDRepeat(hipLaunchParm lp,
|
||||
const T *A_d,
|
||||
const T *B_d,
|
||||
T *C_d,
|
||||
size_t NELEM,
|
||||
int repeat)
|
||||
{
|
||||
__global__ void vectorADDRepeat(hipLaunchParm lp, const T* A_d, const T* B_d, T* C_d, size_t NELEM,
|
||||
int repeat) {
|
||||
size_t offset = (blockIdx.x * blockDim.x + threadIdx.x);
|
||||
size_t stride = blockDim.x * gridDim.x ;
|
||||
size_t stride = blockDim.x * gridDim.x;
|
||||
|
||||
for (int j=1; j<=repeat;j++) {
|
||||
for (size_t i=offset; i<NELEM; i+=stride) {
|
||||
C_d[i] = A_d[i]*j + B_d[i]*j;
|
||||
for (int j = 1; j <= repeat; j++) {
|
||||
for (size_t i = offset; i < NELEM; i += stride) {
|
||||
C_d[i] = A_d[i] * j + B_d[i] * j;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//------
|
||||
// Structure for one stream - includes the stream + data buffers that are used by the stream.
|
||||
template <typename T>
|
||||
class Streamer {
|
||||
public:
|
||||
Streamer(size_t numElements, bool useNullStream=false);
|
||||
public:
|
||||
Streamer(size_t numElements, bool useNullStream = false);
|
||||
~Streamer();
|
||||
void enqueAsync();
|
||||
void queryUntilComplete();
|
||||
@@ -69,26 +61,24 @@ public:
|
||||
void D2H();
|
||||
|
||||
|
||||
public:
|
||||
T *_A_h;
|
||||
T *_B_h;
|
||||
T *_C_h;
|
||||
public:
|
||||
T* _A_h;
|
||||
T* _B_h;
|
||||
T* _C_h;
|
||||
|
||||
T *_A_d;
|
||||
T *_B_d;
|
||||
T *_C_d;
|
||||
T* _A_d;
|
||||
T* _B_d;
|
||||
T* _C_d;
|
||||
|
||||
hipStream_t _stream;
|
||||
hipEvent_t _event;
|
||||
hipEvent_t _event;
|
||||
|
||||
size_t _numElements;
|
||||
size_t _numElements;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
Streamer<T>::Streamer(size_t numElements, bool useNullStream) :
|
||||
_numElements(numElements)
|
||||
{
|
||||
HipTest::initArrays (&_A_d, &_B_d, &_C_d, &_A_h, &_B_h, &_C_h, numElements, true);
|
||||
Streamer<T>::Streamer(size_t numElements, bool useNullStream) : _numElements(numElements) {
|
||||
HipTest::initArrays(&_A_d, &_B_d, &_C_d, &_A_h, &_B_h, &_C_h, numElements, true);
|
||||
|
||||
if (useNullStream) {
|
||||
_stream = 0x0;
|
||||
@@ -98,82 +88,65 @@ Streamer<T>::Streamer(size_t numElements, bool useNullStream) :
|
||||
HIPCHECK(hipEventCreate(&_event));
|
||||
|
||||
H2D();
|
||||
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
void Streamer<T>::H2D()
|
||||
{
|
||||
HIPCHECK(hipMemcpy(_A_d, _A_h, _numElements*sizeof(T), hipMemcpyHostToDevice));
|
||||
HIPCHECK(hipMemcpy(_B_d, _B_h, _numElements*sizeof(T), hipMemcpyHostToDevice));
|
||||
void Streamer<T>::H2D() {
|
||||
HIPCHECK(hipMemcpy(_A_d, _A_h, _numElements * sizeof(T), hipMemcpyHostToDevice));
|
||||
HIPCHECK(hipMemcpy(_B_d, _B_h, _numElements * sizeof(T), hipMemcpyHostToDevice));
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void Streamer<T>::D2H()
|
||||
{
|
||||
HIPCHECK(hipMemcpy(_C_h, _C_d, _numElements*sizeof(T), hipMemcpyDeviceToHost));
|
||||
void Streamer<T>::D2H() {
|
||||
HIPCHECK(hipMemcpy(_C_h, _C_d, _numElements * sizeof(T), hipMemcpyDeviceToHost));
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void Streamer<T>::reset()
|
||||
{
|
||||
void Streamer<T>::reset() {
|
||||
HipTest::setDefaultData(_numElements, _A_h, _B_h, _C_h);
|
||||
H2D();
|
||||
|
||||
}
|
||||
|
||||
|
||||
template <typename T>
|
||||
void Streamer<T>::enqueAsync()
|
||||
{
|
||||
printf ("testing: %s numElements=%zu size=%6.2fMB\n", __func__, _numElements, _numElements * sizeof(T) / 1024.0/1024.0);
|
||||
void Streamer<T>::enqueAsync() {
|
||||
printf("testing: %s numElements=%zu size=%6.2fMB\n", __func__, _numElements,
|
||||
_numElements * sizeof(T) / 1024.0 / 1024.0);
|
||||
unsigned blocks = HipTest::setNumBlocks(blocksPerCU, threadsPerBlock, _numElements);
|
||||
hipLaunchKernel(
|
||||
vectorADDRepeat,
|
||||
dim3(blocks),
|
||||
dim3(threadsPerBlock),
|
||||
0,
|
||||
_stream,
|
||||
static_cast<const T*>(_A_d),
|
||||
static_cast<const T*>(_B_d),
|
||||
_C_d,
|
||||
_numElements,
|
||||
p_repeat);
|
||||
|
||||
hipLaunchKernel(vectorADDRepeat, dim3(blocks), dim3(threadsPerBlock), 0, _stream,
|
||||
static_cast<const T*>(_A_d), static_cast<const T*>(_B_d), _C_d, _numElements,
|
||||
p_repeat);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void Streamer<T>::queryUntilComplete()
|
||||
{
|
||||
void Streamer<T>::queryUntilComplete() {
|
||||
int numQueries = 0;
|
||||
hipError_t e = hipSuccess;
|
||||
do {
|
||||
numQueries++;
|
||||
e = hipStreamQuery(_stream);
|
||||
} while (e != hipSuccess) ;
|
||||
} while (e != hipSuccess);
|
||||
|
||||
printf ("completed after %d queries\n", numQueries);
|
||||
printf("completed after %d queries\n", numQueries);
|
||||
};
|
||||
|
||||
|
||||
|
||||
//---
|
||||
//Parse arguments specific to this test.
|
||||
void parseMyArguments(int argc, char *argv[])
|
||||
{
|
||||
// Parse arguments specific to this test.
|
||||
void parseMyArguments(int argc, char* argv[]) {
|
||||
int more_argc = HipTest::parseStandardArguments(argc, argv, false);
|
||||
|
||||
// parse args for this test:
|
||||
for (int i = 1; i < more_argc; i++) {
|
||||
const char *arg = argv[i];
|
||||
const char* arg = argv[i];
|
||||
|
||||
if (!strcmp(arg, "--streams")) {
|
||||
if (++i >= argc || !HipTest::parseUInt(argv[i], &p_streams)) {
|
||||
failed("Bad streams argument");
|
||||
failed("Bad streams argument");
|
||||
}
|
||||
} else if (!strcmp(arg, "--repeat") || (!strcmp(arg, "-r"))) {
|
||||
if (++i >= argc || !HipTest::parseInt(argv[i], &p_repeat)) {
|
||||
failed("Bad repeat argument");
|
||||
failed("Bad repeat argument");
|
||||
}
|
||||
} else {
|
||||
failed("Bad argument '%s'", arg);
|
||||
@@ -182,70 +155,61 @@ void parseMyArguments(int argc, char *argv[])
|
||||
};
|
||||
|
||||
|
||||
void
|
||||
printBuffer(std::string name, int *f, size_t numElements)
|
||||
{
|
||||
void printBuffer(std::string name, int* f, size_t numElements) {
|
||||
std::cout << name << "\n";
|
||||
for (size_t i=0; i<numElements; i++) {
|
||||
printf ("%5zu: %d\n", i, f[i]);
|
||||
for (size_t i = 0; i < numElements; i++) {
|
||||
printf("%5zu: %d\n", i, f[i]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//---
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int main(int argc, char* argv[]) {
|
||||
HipTest::parseStandardArguments(argc, argv, false);
|
||||
parseMyArguments(argc, argv);
|
||||
|
||||
typedef Streamer<int> IntStreamer;
|
||||
|
||||
std::vector<IntStreamer *> streamers;
|
||||
std::vector<IntStreamer*> streamers;
|
||||
|
||||
size_t numElements = N;
|
||||
|
||||
int *expected_H = (int*)malloc(numElements*sizeof(int));
|
||||
int* expected_H = (int*)malloc(numElements * sizeof(int));
|
||||
|
||||
|
||||
auto nullStreamer = new IntStreamer(numElements, true);
|
||||
|
||||
// Expected resultr - last streamer runs vectorADDRepeat, then nullstreamer adds lastStreamer->_C_d + lastStreamer->_C_d
|
||||
for (size_t i=0; i<numElements; i++) {
|
||||
expected_H[i] = ((nullStreamer->_A_h[i])*p_repeat + (nullStreamer->_B_h[i]) * p_repeat) *2;
|
||||
// Expected resultr - last streamer runs vectorADDRepeat, then nullstreamer adds
|
||||
// lastStreamer->_C_d + lastStreamer->_C_d
|
||||
for (size_t i = 0; i < numElements; i++) {
|
||||
expected_H[i] =
|
||||
((nullStreamer->_A_h[i]) * p_repeat + (nullStreamer->_B_h[i]) * p_repeat) * 2;
|
||||
}
|
||||
|
||||
|
||||
for (int i=0; i<p_streams; i++) {
|
||||
IntStreamer * s = new IntStreamer(numElements);
|
||||
for (int i = 0; i < p_streams; i++) {
|
||||
IntStreamer* s = new IntStreamer(numElements);
|
||||
streamers.push_back(s);
|
||||
}
|
||||
unsigned blocks = HipTest::setNumBlocks(blocksPerCU, threadsPerBlock, numElements);
|
||||
|
||||
for (int s=1; s<p_streams; s++) {
|
||||
if (p_tests & (1<<s)) {
|
||||
printf ("==> Test %x runAsnc, #streams=%d\n", (1<<s), s);
|
||||
for (int s = 1; s < p_streams; s++) {
|
||||
if (p_tests & (1 << s)) {
|
||||
printf("==> Test %x runAsnc, #streams=%d\n", (1 << s), s);
|
||||
nullStreamer->reset();
|
||||
|
||||
for (int i=0; i<s; i++) {
|
||||
for (int i = 0; i < s; i++) {
|
||||
streamers[i]->enqueAsync();
|
||||
}
|
||||
|
||||
auto lastStreamer = streamers[s - 1];
|
||||
|
||||
// Dispatch to NULL stream, should wait for prior async activity to complete before beginning:
|
||||
hipLaunchKernel(
|
||||
vectorADDRepeat,
|
||||
dim3(blocks),
|
||||
dim3(threadsPerBlock),
|
||||
0,
|
||||
0/*nullstream*/,
|
||||
static_cast<const int*>(lastStreamer->_C_d),
|
||||
static_cast<const int*>(lastStreamer->_C_d),
|
||||
nullStreamer->_C_d,
|
||||
numElements,
|
||||
1/*repeat*/);
|
||||
// Dispatch to NULL stream, should wait for prior async activity to complete before
|
||||
// beginning:
|
||||
hipLaunchKernel(vectorADDRepeat, dim3(blocks), dim3(threadsPerBlock), 0,
|
||||
0 /*nullstream*/, static_cast<const int*>(lastStreamer->_C_d),
|
||||
static_cast<const int*>(lastStreamer->_C_d), nullStreamer->_C_d,
|
||||
numElements, 1 /*repeat*/);
|
||||
|
||||
|
||||
if (p_db) {
|
||||
@@ -263,12 +227,12 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
|
||||
|
||||
for (int s=1; s<p_streams; s+=2) {
|
||||
unsigned tmask = (0x10000 | (1<<s));
|
||||
for (int s = 1; s < p_streams; s += 2) {
|
||||
unsigned tmask = (0x10000 | (1 << s));
|
||||
if (p_tests & tmask) {
|
||||
nullStreamer->reset();
|
||||
printf ("==> Test %x runAsnc-odd-only, #streams=%d\n", tmask, s);
|
||||
for (int i=0; i<s; i++) {
|
||||
printf("==> Test %x runAsnc-odd-only, #streams=%d\n", tmask, s);
|
||||
for (int i = 0; i < s; i++) {
|
||||
// RUn just odd streams so we have some empty ones to examine/optimize:
|
||||
if (i & 0x1) {
|
||||
streamers[i]->enqueAsync();
|
||||
@@ -276,18 +240,12 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
auto lastStreamer = streamers[s - 1];
|
||||
|
||||
// Dispatch to NULL stream, should wait for prior async activity to complete before beginning:
|
||||
hipLaunchKernel(
|
||||
vectorADDRepeat,
|
||||
dim3(blocks),
|
||||
dim3(threadsPerBlock),
|
||||
0,
|
||||
0/*nullstream*/,
|
||||
static_cast<const int*>(lastStreamer->_C_d),
|
||||
static_cast<const int*>(lastStreamer->_C_d),
|
||||
nullStreamer->_C_d,
|
||||
numElements,
|
||||
1/*repeat*/);
|
||||
// Dispatch to NULL stream, should wait for prior async activity to complete before
|
||||
// beginning:
|
||||
hipLaunchKernel(vectorADDRepeat, dim3(blocks), dim3(threadsPerBlock), 0,
|
||||
0 /*nullstream*/, static_cast<const int*>(lastStreamer->_C_d),
|
||||
static_cast<const int*>(lastStreamer->_C_d), nullStreamer->_C_d,
|
||||
numElements, 1 /*repeat*/);
|
||||
|
||||
nullStreamer->D2H();
|
||||
|
||||
@@ -298,26 +256,28 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
|
||||
// Expected resultr - last streamer runs vectorADDRepeat
|
||||
for (size_t i=0; i<numElements; i++) {
|
||||
expected_H[i] = ((nullStreamer->_A_h[i])*p_repeat + (nullStreamer->_B_h[i]) * p_repeat);
|
||||
for (size_t i = 0; i < numElements; i++) {
|
||||
expected_H[i] = ((nullStreamer->_A_h[i]) * p_repeat + (nullStreamer->_B_h[i]) * p_repeat);
|
||||
}
|
||||
|
||||
if (p_tests & 0x20000) {
|
||||
|
||||
assert (p_streams >=2); // need a couple streams in order to run this test.
|
||||
assert(p_streams >= 2); // need a couple streams in order to run this test.
|
||||
nullStreamer->reset();
|
||||
printf ("\n==> Test hipStreamSynchronize with defaultStream \n");
|
||||
printf("\n==> Test hipStreamSynchronize with defaultStream \n");
|
||||
|
||||
// Enqueue a long-running job to stream1
|
||||
streamers[0]->enqueAsync();
|
||||
|
||||
// Check to see if synchronizing on a null stream synchronizes all other streams or just the null stream.
|
||||
// This function follows null stream semantics and will wait for all other blocking streams before returning.
|
||||
// This will wait on the host
|
||||
// Check to see if synchronizing on a null stream synchronizes all other streams or just the
|
||||
// null stream. This function follows null stream semantics and will wait for all other
|
||||
// blocking streams before returning. This will wait on the host
|
||||
HIPCHECK(hipStreamSynchronize(0));
|
||||
|
||||
// Copy with stream1, this could go async if the streamSync doesn't synchronize ALL the streams.
|
||||
HIPCHECK(hipMemcpyAsync(streamers[0]->_C_h, streamers[0]->_C_d, streamers[0]->_numElements*sizeof(int), hipMemcpyDeviceToHost, streamers[1]->_stream));
|
||||
// Copy with stream1, this could go async if the streamSync doesn't synchronize ALL the
|
||||
// streams.
|
||||
HIPCHECK(hipMemcpyAsync(streamers[0]->_C_h, streamers[0]->_C_d,
|
||||
streamers[0]->_numElements * sizeof(int), hipMemcpyDeviceToHost,
|
||||
streamers[1]->_stream));
|
||||
|
||||
|
||||
HIPCHECK(hipDeviceSynchronize());
|
||||
|
||||
@@ -24,97 +24,93 @@ THE SOFTWARE.
|
||||
#define NUM_STREAMS 4
|
||||
|
||||
/*
|
||||
* H2H - 1
|
||||
* H2D - 2
|
||||
* KER - 3
|
||||
* D2D - 4
|
||||
* D2H - 5
|
||||
*/
|
||||
* H2H - 1
|
||||
* H2D - 2
|
||||
* KER - 3
|
||||
* D2D - 4
|
||||
* D2H - 5
|
||||
*/
|
||||
|
||||
template<typename T>
|
||||
void H2HAsync(T *Dst, T *Src, size_t size, hipStream_t stream){
|
||||
HIPCHECK(hipMemcpyAsync(Dst, Src, size, hipMemcpyHostToHost, stream));
|
||||
template <typename T>
|
||||
void H2HAsync(T* Dst, T* Src, size_t size, hipStream_t stream) {
|
||||
HIPCHECK(hipMemcpyAsync(Dst, Src, size, hipMemcpyHostToHost, stream));
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void H2DAsync(T *Dst, T *Src, size_t size, hipStream_t stream){
|
||||
HIPCHECK(hipMemcpyAsync(Dst, Src, size, hipMemcpyHostToDevice, stream));
|
||||
template <typename T>
|
||||
void H2DAsync(T* Dst, T* Src, size_t size, hipStream_t stream) {
|
||||
HIPCHECK(hipMemcpyAsync(Dst, Src, size, hipMemcpyHostToDevice, stream));
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void D2DAsync(T *Dst, T *Src, size_t size, hipStream_t stream){
|
||||
HIPCHECK(hipMemcpyAsync(Dst, Src, size, hipMemcpyDeviceToDevice, stream));
|
||||
template <typename T>
|
||||
void D2DAsync(T* Dst, T* Src, size_t size, hipStream_t stream) {
|
||||
HIPCHECK(hipMemcpyAsync(Dst, Src, size, hipMemcpyDeviceToDevice, stream));
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void D2HAsync(T *Dst, T *Src, size_t size, hipStream_t stream){
|
||||
HIPCHECK(hipMemcpyAsync(Dst, Src, size, hipMemcpyDeviceToHost, stream));
|
||||
template <typename T>
|
||||
void D2HAsync(T* Dst, T* Src, size_t size, hipStream_t stream) {
|
||||
HIPCHECK(hipMemcpyAsync(Dst, Src, size, hipMemcpyDeviceToHost, stream));
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void H2H(T *Dst, T *Src, size_t size){
|
||||
HIPCHECK(hipMemcpy(Dst, Src, size, hipMemcpyHostToHost));
|
||||
template <typename T>
|
||||
void H2H(T* Dst, T* Src, size_t size) {
|
||||
HIPCHECK(hipMemcpy(Dst, Src, size, hipMemcpyHostToHost));
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void H2D(T *Dst, T *Src, size_t size){
|
||||
HIPCHECK(hipMemcpy(Dst, Src, size, hipMemcpyHostToDevice));
|
||||
template <typename T>
|
||||
void H2D(T* Dst, T* Src, size_t size) {
|
||||
HIPCHECK(hipMemcpy(Dst, Src, size, hipMemcpyHostToDevice));
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void D2D(T *Dst, T *Src, size_t size){
|
||||
HIPCHECK(hipMemcpy(Dst, Src, size, hipMemcpyDeviceToDevice));
|
||||
template <typename T>
|
||||
void D2D(T* Dst, T* Src, size_t size) {
|
||||
HIPCHECK(hipMemcpy(Dst, Src, size, hipMemcpyDeviceToDevice));
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void D2H(T *Dst, T *Src, size_t size){
|
||||
HIPCHECK(hipMemcpy(Dst, Src, size, hipMemcpyDeviceToHost));
|
||||
template <typename T>
|
||||
void D2H(T* Dst, T* Src, size_t size) {
|
||||
HIPCHECK(hipMemcpy(Dst, Src, size, hipMemcpyDeviceToHost));
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
__global__ void Inc(hipLaunchParm lp, T *In){
|
||||
int tx = threadIdx.x + blockIdx.x * blockDim.x;
|
||||
In[tx] = In[tx] + 1;
|
||||
template <typename T>
|
||||
__global__ void Inc(hipLaunchParm lp, T* In) {
|
||||
int tx = threadIdx.x + blockIdx.x * blockDim.x;
|
||||
In[tx] = In[tx] + 1;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void initArrays(T **Ad, T **Ah,
|
||||
size_t N, bool usePinnedHost=false){
|
||||
size_t NBytes = N * sizeof(T);
|
||||
if(Ad){
|
||||
HIPCHECK( hipMalloc(Ad, NBytes));
|
||||
}
|
||||
if(usePinnedHost){
|
||||
HIPCHECK( hipHostMalloc((void**)Ah, NBytes, hipHostMallocDefault));
|
||||
}
|
||||
else{
|
||||
*Ah = new T[N];
|
||||
HIPASSERT(*Ah != NULL);
|
||||
}
|
||||
template <typename T>
|
||||
void initArrays(T** Ad, T** Ah, size_t N, bool usePinnedHost = false) {
|
||||
size_t NBytes = N * sizeof(T);
|
||||
if (Ad) {
|
||||
HIPCHECK(hipMalloc(Ad, NBytes));
|
||||
}
|
||||
if (usePinnedHost) {
|
||||
HIPCHECK(hipHostMalloc((void**)Ah, NBytes, hipHostMallocDefault));
|
||||
} else {
|
||||
*Ah = new T[N];
|
||||
HIPASSERT(*Ah != NULL);
|
||||
}
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void initArrays(T **Ad, size_t N,
|
||||
bool deviceMemory = false,
|
||||
bool usePinnedHost = false){
|
||||
size_t NBytes = N * sizeof(T);
|
||||
if(deviceMemory){
|
||||
HIPCHECK( hipMalloc(Ad, NBytes));
|
||||
}else{
|
||||
if(usePinnedHost){
|
||||
HIPCHECK(hipHostMalloc((void**)Ad, NBytes, hipHostMallocDefault));
|
||||
}else{
|
||||
*Ad = new T[N];
|
||||
HIPASSERT(*Ad != NULL);
|
||||
}
|
||||
}
|
||||
template <typename T>
|
||||
void initArrays(T** Ad, size_t N, bool deviceMemory = false, bool usePinnedHost = false) {
|
||||
size_t NBytes = N * sizeof(T);
|
||||
if (deviceMemory) {
|
||||
HIPCHECK(hipMalloc(Ad, NBytes));
|
||||
} else {
|
||||
if (usePinnedHost) {
|
||||
HIPCHECK(hipHostMalloc((void**)Ad, NBytes, hipHostMallocDefault));
|
||||
} else {
|
||||
*Ad = new T[N];
|
||||
HIPASSERT(*Ad != NULL);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void setArray(T* Array, int N, T val){
|
||||
for(int i=0;i<N;i++){
|
||||
Array[i] = val;
|
||||
}
|
||||
template <typename T>
|
||||
void setArray(T* Array, int N, T val) {
|
||||
for (int i = 0; i < N; i++) {
|
||||
Array[i] = val;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -29,16 +29,15 @@ THE SOFTWARE.
|
||||
#include "hip/hip_runtime.h"
|
||||
#include "test_common.h"
|
||||
|
||||
#ifdef __HIP_PLATFORM_HCC__
|
||||
#ifdef __HIP_PLATFORM_HCC__
|
||||
#define HIPRT_CB
|
||||
#endif
|
||||
|
||||
__global__ void vector_square(float *C_d, float *A_d, size_t N)
|
||||
{
|
||||
__global__ void vector_square(float* C_d, float* A_d, size_t N) {
|
||||
size_t offset = (blockIdx.x * blockDim.x + threadIdx.x);
|
||||
size_t stride = blockDim.x * gridDim.x ;
|
||||
size_t stride = blockDim.x * gridDim.x;
|
||||
|
||||
for (size_t i=offset; i<N; i+=stride) {
|
||||
for (size_t i = offset; i < N; i += stride) {
|
||||
C_d[i] = A_d[i] * A_d[i];
|
||||
}
|
||||
}
|
||||
@@ -46,31 +45,28 @@ __global__ void vector_square(float *C_d, float *A_d, size_t N)
|
||||
float *A_h, *C_h;
|
||||
bool cbDone = false;
|
||||
|
||||
static void HIPRT_CB Callback(hipStream_t stream, hipError_t status, void *userData)
|
||||
{
|
||||
for (size_t i=0; i<N; i++) {
|
||||
static void HIPRT_CB Callback(hipStream_t stream, hipError_t status, void* userData) {
|
||||
for (size_t i = 0; i < N; i++) {
|
||||
if (C_h[i] != A_h[i] * A_h[i]) {
|
||||
warn("Data mismatch %zu", i);
|
||||
}
|
||||
}
|
||||
printf ("PASSED!\n");
|
||||
printf("PASSED!\n");
|
||||
cbDone = true;
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int main(int argc, char* argv[]) {
|
||||
float *A_d, *C_d;
|
||||
size_t Nbytes = N * sizeof(float);
|
||||
|
||||
A_h = (float*)malloc(Nbytes);
|
||||
HIPCHECK(A_h == 0 ? hipErrorMemoryAllocation : hipSuccess );
|
||||
HIPCHECK(A_h == 0 ? hipErrorMemoryAllocation : hipSuccess);
|
||||
C_h = (float*)malloc(Nbytes);
|
||||
HIPCHECK(C_h == 0 ? hipErrorMemoryAllocation : hipSuccess );
|
||||
HIPCHECK(C_h == 0 ? hipErrorMemoryAllocation : hipSuccess);
|
||||
|
||||
// Fill with Phi + i
|
||||
for (size_t i=0; i<N; i++)
|
||||
{
|
||||
A_h[i] = 1.618f + i;
|
||||
for (size_t i = 0; i < N; i++) {
|
||||
A_h[i] = 1.618f + i;
|
||||
}
|
||||
|
||||
HIPCHECK(hipMalloc(&A_d, Nbytes));
|
||||
@@ -83,11 +79,11 @@ int main(int argc, char *argv[])
|
||||
|
||||
const unsigned blocks = 512;
|
||||
const unsigned threadsPerBlock = 256;
|
||||
hipLaunchKernelGGL((vector_square), dim3(blocks), dim3(threadsPerBlock), 0, mystream, C_d, A_d, N);
|
||||
hipLaunchKernelGGL((vector_square), dim3(blocks), dim3(threadsPerBlock), 0, mystream, C_d, A_d,
|
||||
N);
|
||||
|
||||
HIPCHECK(hipMemcpyAsync(C_h, C_d, Nbytes, hipMemcpyDeviceToHost, mystream));
|
||||
HIPCHECK(hipStreamAddCallback(mystream, Callback, NULL, 0));
|
||||
|
||||
while(!cbDone)
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(10));
|
||||
while (!cbDone) std::this_thread::sleep_for(std::chrono::milliseconds(10));
|
||||
}
|
||||
|
||||
@@ -26,18 +26,17 @@ THE SOFTWARE.
|
||||
#include "test_common.h"
|
||||
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int main(int argc, char* argv[]) {
|
||||
hipStream_t stream;
|
||||
unsigned int flags;
|
||||
HIPCHECK(hipStreamCreateWithFlags(&stream, hipStreamDefault));
|
||||
HIPCHECK(hipStreamGetFlags(stream, &flags));
|
||||
HIPASSERT(flags == 0);
|
||||
HIPASSERT(flags == 0);
|
||||
HIPCHECK(hipStreamDestroy(stream));
|
||||
|
||||
HIPCHECK(hipStreamCreateWithFlags(&stream, hipStreamNonBlocking));
|
||||
HIPCHECK(hipStreamGetFlags(stream, &flags));
|
||||
HIPASSERT(flags == 1);
|
||||
HIPASSERT(flags == 1);
|
||||
HIPCHECK(hipStreamDestroy(stream));
|
||||
|
||||
passed();
|
||||
|
||||
Datei-Diff unterdrückt, da er zu groß ist
Diff laden
@@ -36,7 +36,7 @@ enum SyncMode {
|
||||
};
|
||||
|
||||
|
||||
const char *syncModeString(int syncMode) {
|
||||
const char* syncModeString(int syncMode) {
|
||||
switch (syncMode) {
|
||||
case syncNone:
|
||||
return "syncNone";
|
||||
@@ -56,9 +56,8 @@ const char *syncModeString(int syncMode) {
|
||||
};
|
||||
|
||||
|
||||
void test(unsigned testMask, int *C_d, int *C_h, int64_t numElements, SyncMode syncMode, bool expectMismatch)
|
||||
{
|
||||
|
||||
void test(unsigned testMask, int* C_d, int* C_h, int64_t numElements, SyncMode syncMode,
|
||||
bool expectMismatch) {
|
||||
// This test sends a long-running kernel to the null stream, then tests to see if the
|
||||
// specified synchronization technique is effective.
|
||||
//
|
||||
@@ -75,20 +74,21 @@ void test(unsigned testMask, int *C_d, int *C_h, int64_t numElements, SyncMode s
|
||||
if (!(testMask & p_tests)) {
|
||||
return;
|
||||
}
|
||||
printf ("\ntest 0x%02x: syncMode=%s expectMismatch=%d\n",
|
||||
testMask, syncModeString(syncMode), expectMismatch);
|
||||
printf("\ntest 0x%02x: syncMode=%s expectMismatch=%d\n", testMask, syncModeString(syncMode),
|
||||
expectMismatch);
|
||||
|
||||
size_t sizeBytes = numElements * sizeof(int);
|
||||
|
||||
int count =100;
|
||||
int count = 100;
|
||||
int init0 = 0;
|
||||
HIPCHECK(hipMemset(C_d, init0, sizeBytes));
|
||||
for (int i=0; i<numElements; i++) {
|
||||
C_h[i] = -1; // initialize
|
||||
for (int i = 0; i < numElements; i++) {
|
||||
C_h[i] = -1; // initialize
|
||||
}
|
||||
|
||||
hipStream_t otherStream = 0;
|
||||
unsigned flags = (syncMode == syncMarkerThenOtherNonBlockingStream) ? hipStreamNonBlocking : hipStreamDefault;
|
||||
unsigned flags = (syncMode == syncMarkerThenOtherNonBlockingStream) ? hipStreamNonBlocking
|
||||
: hipStreamDefault;
|
||||
HIPCHECK(hipStreamCreateWithFlags(&otherStream, flags));
|
||||
hipEvent_t stop, otherStreamEvent;
|
||||
HIPCHECK(hipEventCreate(&stop));
|
||||
@@ -97,17 +97,9 @@ void test(unsigned testMask, int *C_d, int *C_h, int64_t numElements, SyncMode s
|
||||
|
||||
unsigned blocks = HipTest::setNumBlocks(blocksPerCU, threadsPerBlock, numElements);
|
||||
// Launch kernel into null stream, should result in C_h == count.
|
||||
hipLaunchKernelGGL(
|
||||
HipTest::addCountReverse,
|
||||
dim3(blocks),
|
||||
dim3(threadsPerBlock),
|
||||
0,
|
||||
0 /*stream*/,
|
||||
static_cast<const int*>(C_d),
|
||||
C_h,
|
||||
numElements,
|
||||
count);
|
||||
HIPCHECK(hipEventRecord(stop, 0/*default*/));
|
||||
hipLaunchKernelGGL(HipTest::addCountReverse, dim3(blocks), dim3(threadsPerBlock), 0,
|
||||
0 /*stream*/, static_cast<const int*>(C_d), C_h, numElements, count);
|
||||
HIPCHECK(hipEventRecord(stop, 0 /*default*/));
|
||||
|
||||
switch (syncMode) {
|
||||
case syncNone:
|
||||
@@ -137,26 +129,26 @@ void test(unsigned testMask, int *C_d, int *C_h, int64_t numElements, SyncMode s
|
||||
hipError_t done = hipEventQuery(stop);
|
||||
|
||||
if (expectMismatch) {
|
||||
assert (done == hipErrorNotReady);
|
||||
assert(done == hipErrorNotReady);
|
||||
} else {
|
||||
assert (done == hipSuccess);
|
||||
assert(done == hipSuccess);
|
||||
}
|
||||
|
||||
int mismatches = 0;
|
||||
int expected = init0 + count;
|
||||
for (int i=0; i<numElements; i++) {
|
||||
for (int i = 0; i < numElements; i++) {
|
||||
bool compareEqual = (C_h[i] == expected);
|
||||
if (!compareEqual) {
|
||||
mismatches ++;
|
||||
if (!expectMismatch) {
|
||||
printf ("C_h[%d] (%d) != %d\n", i, C_h[i], expected);
|
||||
mismatches++;
|
||||
if (!expectMismatch) {
|
||||
printf("C_h[%d] (%d) != %d\n", i, C_h[i], expected);
|
||||
assert(C_h[i] == expected);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (expectMismatch) {
|
||||
assert (mismatches > 0);
|
||||
assert(mismatches > 0);
|
||||
}
|
||||
|
||||
|
||||
@@ -166,15 +158,16 @@ void test(unsigned testMask, int *C_d, int *C_h, int64_t numElements, SyncMode s
|
||||
|
||||
HIPCHECK(hipDeviceSynchronize());
|
||||
|
||||
printf ("test: OK - %d mismatches (%6.2f%%)\n", mismatches, ((double)(mismatches)*100.0)/numElements);
|
||||
printf("test: OK - %d mismatches (%6.2f%%)\n", mismatches,
|
||||
((double)(mismatches)*100.0) / numElements);
|
||||
}
|
||||
|
||||
|
||||
void runTests(int64_t numElements)
|
||||
{
|
||||
void runTests(int64_t numElements) {
|
||||
size_t sizeBytes = numElements * sizeof(int);
|
||||
|
||||
printf ("\n\ntest: starting sequence with sizeBytes=%zu bytes, %6.2f MB\n", sizeBytes, sizeBytes/1024.0/1024.0);
|
||||
printf("\n\ntest: starting sequence with sizeBytes=%zu bytes, %6.2f MB\n", sizeBytes,
|
||||
sizeBytes / 1024.0 / 1024.0);
|
||||
|
||||
|
||||
int *C_h, *C_d;
|
||||
@@ -183,18 +176,19 @@ void runTests(int64_t numElements)
|
||||
|
||||
|
||||
{
|
||||
test (0x01, C_d, C_h, numElements, syncNone, true /*expectMismatch*/);
|
||||
test (0x02, C_d, C_h, numElements, syncNullStream, false /*expectMismatch*/);
|
||||
test (0x04, C_d, C_h, numElements, syncOtherStream, true /*expectMismatch*/);
|
||||
test (0x08, C_d, C_h, numElements, syncDevice, false /*expectMismatch*/);
|
||||
test(0x01, C_d, C_h, numElements, syncNone, true /*expectMismatch*/);
|
||||
test(0x02, C_d, C_h, numElements, syncNullStream, false /*expectMismatch*/);
|
||||
test(0x04, C_d, C_h, numElements, syncOtherStream, true /*expectMismatch*/);
|
||||
test(0x08, C_d, C_h, numElements, syncDevice, false /*expectMismatch*/);
|
||||
|
||||
// Sending a marker to to null stream may synchronize the otherStream
|
||||
// - other created with hipStreamNonBlocking=0 : synchronization, should match
|
||||
// - other created with hipStreamNonBlocking=1 : no synchronization, may mismatch
|
||||
test (0x10, C_d, C_h, numElements, syncMarkerThenOtherStream, false /*expectMismatch*/);
|
||||
test(0x10, C_d, C_h, numElements, syncMarkerThenOtherStream, false /*expectMismatch*/);
|
||||
|
||||
// TODO - review why this test seems flaky
|
||||
//test (0x20, C_d, C_h, numElements, syncMarkerThenOtherNonBlockingStream, true /*expectMismatch*/);
|
||||
// test (0x20, C_d, C_h, numElements, syncMarkerThenOtherNonBlockingStream, true
|
||||
// /*expectMismatch*/);
|
||||
}
|
||||
|
||||
|
||||
@@ -203,8 +197,7 @@ void runTests(int64_t numElements)
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int main(int argc, char* argv[]) {
|
||||
// Can' destroy the default stream:// TODO - move to another test
|
||||
HIPCHECK_API(hipStreamDestroy(0), hipErrorInvalidResourceHandle);
|
||||
|
||||
|
||||
@@ -34,69 +34,63 @@ unsigned p_db = 0;
|
||||
unsigned p_count = 100;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//------
|
||||
// Structure for one stream;
|
||||
template <typename T>
|
||||
class Streamer {
|
||||
|
||||
#define COMMAND_ADD_FORWARD 0
|
||||
#define COMMAND_ADD_REVERSE 1
|
||||
#define COMMAND_COPY 2
|
||||
#define COMMAND_COPY 2
|
||||
|
||||
|
||||
public:
|
||||
Streamer(int deviceId, T *input, size_t numElements, int commandType);
|
||||
public:
|
||||
Streamer(int deviceId, T* input, size_t numElements, int commandType);
|
||||
~Streamer();
|
||||
void runAsyncAfter(Streamer<T> *depStreamer, bool waitSameStream=false);
|
||||
void runAsyncAfter(Streamer<T>* depStreamer, bool waitSameStream = false);
|
||||
void runAsyncWaitSameStream();
|
||||
void queryUntilComplete();
|
||||
|
||||
size_t check(int streamerNum, T initValue, T expectedOffset, bool expectPass=true);
|
||||
size_t check(int streamerNum, T initValue, T expectedOffset, bool expectPass = true);
|
||||
void copyToHost(hipStream_t copyStream);
|
||||
|
||||
hipEvent_t event() { return _event; };
|
||||
|
||||
int deviceId() const { return _deviceId; };
|
||||
size_t mismatchCount() const { return _mismatchCount; };
|
||||
T *C_d() { return _C_d; };
|
||||
T* C_d() { return _C_d; };
|
||||
|
||||
// How much does this streamer add to A[i] after running runAsyncAfter
|
||||
int expectedAdd() const { return (_commandType == COMMAND_COPY) ? 0 : p_count; };
|
||||
|
||||
|
||||
int _commandType; // 0=addReverse, 1=addFwd, 2=move
|
||||
private:
|
||||
int _commandType; // 0=addReverse, 1=addFwd, 2=move
|
||||
private:
|
||||
T* _C_h;
|
||||
|
||||
T *_C_h;
|
||||
|
||||
T *_preA_d; // if input is on another device, this is pointer to that memory.
|
||||
T *_A_d;
|
||||
T *_C_d;
|
||||
T* _preA_d; // if input is on another device, this is pointer to that memory.
|
||||
T* _A_d;
|
||||
T* _C_d;
|
||||
|
||||
hipStream_t _stream;
|
||||
hipEvent_t _event;
|
||||
hipEvent_t _event;
|
||||
|
||||
int _deviceId;
|
||||
size_t _numElements;
|
||||
int _deviceId;
|
||||
size_t _numElements;
|
||||
|
||||
size_t _mismatchCount;
|
||||
size_t _mismatchCount;
|
||||
};
|
||||
|
||||
|
||||
template <typename T>
|
||||
Streamer<T>::Streamer(int deviceId, T * A_d, size_t numElements, int commandType) :
|
||||
_preA_d(NULL),
|
||||
_A_d(A_d),
|
||||
_deviceId(deviceId),
|
||||
_numElements(numElements),
|
||||
_commandType(commandType)
|
||||
{
|
||||
Streamer<T>::Streamer(int deviceId, T* A_d, size_t numElements, int commandType)
|
||||
: _preA_d(NULL),
|
||||
_A_d(A_d),
|
||||
_deviceId(deviceId),
|
||||
_numElements(numElements),
|
||||
_commandType(commandType) {
|
||||
size_t sizeElements = numElements * sizeof(int);
|
||||
|
||||
//if (commandType == 0) _commandType = 1; // TODO - remove me
|
||||
// if (commandType == 0) _commandType = 1; // TODO - remove me
|
||||
|
||||
HIPCHECK(hipSetDevice(_deviceId));
|
||||
|
||||
@@ -106,7 +100,7 @@ Streamer<T>::Streamer(int deviceId, T * A_d, size_t numElements, int commandType
|
||||
if (attr.device != deviceId) {
|
||||
// source is on another device, we will need to copy later.
|
||||
// So save original source pointer and allocate local space.
|
||||
printf ("info: source for streamer on another device, will insert memcpy\n");
|
||||
printf("info: source for streamer on another device, will insert memcpy\n");
|
||||
_preA_d = A_d;
|
||||
HIPCHECK(hipMalloc(&_A_d, sizeElements));
|
||||
HIPCHECK(hipMemset(_A_d, -3, sizeElements));
|
||||
@@ -120,18 +114,14 @@ Streamer<T>::Streamer(int deviceId, T * A_d, size_t numElements, int commandType
|
||||
|
||||
HIPCHECK(hipStreamCreate(&_stream));
|
||||
HIPCHECK(hipEventCreate(&_event));
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
template <typename T>
|
||||
Streamer<T>::~Streamer()
|
||||
{
|
||||
Streamer<T>::~Streamer() {
|
||||
HIPCHECK(hipSetDevice(_deviceId));
|
||||
|
||||
printf ("info: ~Streamer\n");
|
||||
printf("info: ~Streamer\n");
|
||||
if (_preA_d) {
|
||||
HIPCHECK(hipFree(_preA_d));
|
||||
}
|
||||
@@ -144,11 +134,11 @@ Streamer<T>::~Streamer()
|
||||
|
||||
|
||||
template <typename T>
|
||||
void Streamer<T>::runAsyncAfter(Streamer<T> *depStreamer, bool waitSameStream)
|
||||
{
|
||||
void Streamer<T>::runAsyncAfter(Streamer<T>* depStreamer, bool waitSameStream) {
|
||||
HIPCHECK(hipSetDevice(_deviceId));
|
||||
if (p_db) {
|
||||
printf ("testing: %s numElements=%zu size=%6.2fMB\n", __func__, _numElements, _numElements * sizeof(T) / 1024.0/1024.0);
|
||||
printf("testing: %s numElements=%zu size=%6.2fMB\n", __func__, _numElements,
|
||||
_numElements * sizeof(T) / 1024.0 / 1024.0);
|
||||
}
|
||||
|
||||
if (depStreamer) {
|
||||
@@ -157,131 +147,117 @@ void Streamer<T>::runAsyncAfter(Streamer<T> *depStreamer, bool waitSameStream)
|
||||
|
||||
if (_preA_d) {
|
||||
// _preA_d is on another device, so copy to local device so kernel can access it:
|
||||
HIPCHECK(hipMemcpyAsync(_A_d, _preA_d, _numElements * sizeof(T), hipMemcpyDeviceToDevice, _stream));
|
||||
HIPCHECK(hipMemcpyAsync(_A_d, _preA_d, _numElements * sizeof(T), hipMemcpyDeviceToDevice,
|
||||
_stream));
|
||||
}
|
||||
|
||||
|
||||
unsigned blocks = HipTest::setNumBlocks(blocksPerCU, threadsPerBlock, _numElements);
|
||||
if (_commandType == COMMAND_ADD_REVERSE) {
|
||||
hipLaunchKernelGGL(
|
||||
HipTest::addCountReverse,
|
||||
dim3(blocks),
|
||||
dim3(threadsPerBlock),
|
||||
0,
|
||||
_stream,
|
||||
static_cast<const T*>(_A_d),
|
||||
_C_d,
|
||||
static_cast<int64_t>(_numElements),
|
||||
static_cast<int>(p_count));
|
||||
hipLaunchKernelGGL(HipTest::addCountReverse, dim3(blocks), dim3(threadsPerBlock), 0,
|
||||
_stream, static_cast<const T*>(_A_d), _C_d,
|
||||
static_cast<int64_t>(_numElements), static_cast<int>(p_count));
|
||||
} else if (_commandType == COMMAND_ADD_FORWARD) {
|
||||
hipLaunchKernelGGL(
|
||||
HipTest::addCount,
|
||||
dim3(blocks),
|
||||
dim3(threadsPerBlock),
|
||||
0,
|
||||
_stream,
|
||||
static_cast<const T*>(_A_d),
|
||||
_C_d,
|
||||
_numElements,
|
||||
static_cast<int>(p_count));
|
||||
hipLaunchKernelGGL(HipTest::addCount, dim3(blocks), dim3(threadsPerBlock), 0, _stream,
|
||||
static_cast<const T*>(_A_d), _C_d, _numElements,
|
||||
static_cast<int>(p_count));
|
||||
} else if (_commandType == COMMAND_COPY) {
|
||||
HIPCHECK(hipMemcpyAsync(_C_d, _A_d, _numElements * sizeof(T), hipMemcpyDeviceToDevice, _stream));
|
||||
HIPCHECK(
|
||||
hipMemcpyAsync(_C_d, _A_d, _numElements * sizeof(T), hipMemcpyDeviceToDevice, _stream));
|
||||
} else {
|
||||
assert(0); // bad command type
|
||||
assert(0); // bad command type
|
||||
}
|
||||
HIPCHECK(hipEventRecord(_event, _stream));
|
||||
|
||||
if (waitSameStream) {
|
||||
HIPCHECK(hipStreamWaitEvent(_stream, _event, 0)); // this is essentially a no-op, but make sure it doesn't crash
|
||||
HIPCHECK(hipStreamWaitEvent(
|
||||
_stream, _event, 0)); // this is essentially a no-op, but make sure it doesn't crash
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
template <typename T>
|
||||
void Streamer<T>::queryUntilComplete()
|
||||
{
|
||||
void Streamer<T>::queryUntilComplete() {
|
||||
HIPCHECK(hipSetDevice(_deviceId));
|
||||
int numQueries = 0;
|
||||
hipError_t e = hipSuccess;
|
||||
do {
|
||||
numQueries++;
|
||||
e = hipStreamQuery(_stream);
|
||||
} while (e != hipSuccess) ;
|
||||
} while (e != hipSuccess);
|
||||
|
||||
printf ("info: hipStreamQuery completed after %d queries\n", numQueries);
|
||||
printf("info: hipStreamQuery completed after %d queries\n", numQueries);
|
||||
};
|
||||
|
||||
|
||||
// If copyStream is !nullptr it is used for the copy.
|
||||
template <typename T>
|
||||
void Streamer<T>::copyToHost(hipStream_t copyStream)
|
||||
{
|
||||
void Streamer<T>::copyToHost(hipStream_t copyStream) {
|
||||
if (p_db) {
|
||||
printf ("db: copy back to host\n");
|
||||
printf("db: copy back to host\n");
|
||||
}
|
||||
HIPCHECK(hipSetDevice(_deviceId));
|
||||
HIPCHECK(hipMemcpyAsync(_C_h, _C_d, _numElements*sizeof(T), hipMemcpyDeviceToHost, copyStream ? copyStream : _stream));
|
||||
HIPCHECK(hipStreamSynchronize(copyStream ? copyStream:_stream));
|
||||
|
||||
HIPCHECK(hipMemcpyAsync(_C_h, _C_d, _numElements * sizeof(T), hipMemcpyDeviceToHost,
|
||||
copyStream ? copyStream : _stream));
|
||||
HIPCHECK(hipStreamSynchronize(copyStream ? copyStream : _stream));
|
||||
}
|
||||
|
||||
|
||||
template <typename T>
|
||||
size_t Streamer<T>::check(int streamerNum, T initValue, T expectedOffset, bool expectPass)
|
||||
{
|
||||
size_t Streamer<T>::check(int streamerNum, T initValue, T expectedOffset, bool expectPass) {
|
||||
T expected = initValue + expectedOffset;
|
||||
if (p_db) {
|
||||
printf ("db: check\n");
|
||||
printf("db: check\n");
|
||||
}
|
||||
|
||||
_mismatchCount = 0;
|
||||
for (size_t i=0; i<_numElements; i++) {
|
||||
for (size_t i = 0; i < _numElements; i++) {
|
||||
if (_C_h[i] != expected) {
|
||||
_mismatchCount++;
|
||||
if (expectPass) {
|
||||
fprintf(stderr, "for streamer:%d _C_h[%zu] (%d) != expected(%d)\n", streamerNum, i, _C_h[i], expected);
|
||||
fprintf(stderr, "for streamer:%d _C_h[%zu] (%d) != expected(%d)\n", streamerNum,
|
||||
i, _C_h[i], expected);
|
||||
if (_mismatchCount > 10) {
|
||||
failed("for streamer:%d _C_h[%zu] (%d) != expected(%d)\n", streamerNum, i, _C_h[i], expected);
|
||||
failed("for streamer:%d _C_h[%zu] (%d) != expected(%d)\n", streamerNum, i,
|
||||
_C_h[i], expected);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!expectPass && (_mismatchCount ==0)) {
|
||||
// the test should run kernels long enough that if we don't correctly wait for them to finish then an error is reported.
|
||||
//failed("for streamer:%d we expected inavalid synchronization to lead to mismatch but none was detected. Increase --N to sensitize sync.\n", streamerNum);
|
||||
|
||||
if (!expectPass && (_mismatchCount == 0)) {
|
||||
// the test should run kernels long enough that if we don't correctly wait for them to
|
||||
// finish then an error is reported.
|
||||
// failed("for streamer:%d we expected inavalid synchronization to lead to mismatch but
|
||||
// none was detected. Increase --N to sensitize sync.\n", streamerNum);
|
||||
}
|
||||
|
||||
return _mismatchCount;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//---
|
||||
//Parse arguments specific to this test.
|
||||
void parseMyArguments(int argc, char *argv[])
|
||||
{
|
||||
N = 64*1024*1024;
|
||||
// Parse arguments specific to this test.
|
||||
void parseMyArguments(int argc, char* argv[]) {
|
||||
N = 64 * 1024 * 1024;
|
||||
|
||||
int more_argc = HipTest::parseStandardArguments(argc, argv, false);
|
||||
|
||||
// parse args for this test:
|
||||
for (int i = 1; i < more_argc; i++) {
|
||||
const char *arg = argv[i];
|
||||
const char* arg = argv[i];
|
||||
|
||||
if (!strcmp(arg, "--streams")) {
|
||||
if (++i >= argc || !HipTest::parseUInt(argv[i], &p_streams)) {
|
||||
failed("Bad streams argument");
|
||||
failed("Bad streams argument");
|
||||
}
|
||||
} else if (!strcmp(arg, "--count")) {
|
||||
if (++i >= argc || !HipTest::parseUInt(argv[i], &p_count)) {
|
||||
failed("Bad count argument");
|
||||
failed("Bad count argument");
|
||||
}
|
||||
} else if (!strcmp(arg, "--db")) {
|
||||
if (++i >= argc || !HipTest::parseUInt(argv[i], &p_db)) {
|
||||
failed("Bad db argument");
|
||||
failed("Bad db argument");
|
||||
}
|
||||
} else {
|
||||
failed("Bad argument '%s'", arg);
|
||||
@@ -293,80 +269,73 @@ void parseMyArguments(int argc, char *argv[])
|
||||
typedef Streamer<int> IntStreamer;
|
||||
|
||||
|
||||
|
||||
|
||||
void runStreamerLoop(std::vector<IntStreamer *> &streamers)
|
||||
{
|
||||
for (int i=0; i<streamers.size(); i++) {
|
||||
streamers[i]->runAsyncAfter(i ? streamers[i-1] : NULL);
|
||||
void runStreamerLoop(std::vector<IntStreamer*>& streamers) {
|
||||
for (int i = 0; i < streamers.size(); i++) {
|
||||
streamers[i]->runAsyncAfter(i ? streamers[i - 1] : NULL);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void checkAll(int initValue, std::vector<IntStreamer *> &streamers, std::vector<hipStream_t> &sideStreams, bool expectPass=true)
|
||||
{
|
||||
size_t mismatchCount=0;
|
||||
void checkAll(int initValue, std::vector<IntStreamer*>& streamers,
|
||||
std::vector<hipStream_t>& sideStreams, bool expectPass = true) {
|
||||
size_t mismatchCount = 0;
|
||||
|
||||
// Copy in reverse order to catch anything not yet finished...
|
||||
for (int i=streamers.size()-1; i>=0; i--) {
|
||||
streamers[i]->copyToHost(sideStreams.empty() ? NULL : sideStreams[streamers[i]->deviceId()]);
|
||||
for (int i = streamers.size() - 1; i >= 0; i--) {
|
||||
streamers[i]->copyToHost(sideStreams.empty() ? NULL
|
||||
: sideStreams[streamers[i]->deviceId()]);
|
||||
}
|
||||
|
||||
|
||||
int expected = 0;
|
||||
// Check in forward order so we can find first mismatch:
|
||||
for (int i=0; i<streamers.size(); i++) {
|
||||
|
||||
for (int i = 0; i < streamers.size(); i++) {
|
||||
expected += streamers[i]->expectedAdd();
|
||||
|
||||
mismatchCount += streamers[i]->check(i+1, initValue, expected, expectPass);
|
||||
|
||||
mismatchCount += streamers[i]->check(i + 1, initValue, expected, expectPass);
|
||||
}
|
||||
if (!expectPass && (mismatchCount==0)) {
|
||||
// the test should run kernels long enough that if we don't correctly wait for them to finish then an error is reported.
|
||||
failed("we expected inavalid synchronization to lead to mismatch but none was detected. Increase --count to sensitize sync.\n");
|
||||
if (!expectPass && (mismatchCount == 0)) {
|
||||
// the test should run kernels long enough that if we don't correctly wait for them to
|
||||
// finish then an error is reported.
|
||||
failed(
|
||||
"we expected inavalid synchronization to lead to mismatch but none was detected. "
|
||||
"Increase --count to sensitize sync.\n");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
#define RUN_SYNC_TEST(_enableBit, _streamers, _sync, _expectPass)\
|
||||
if (p_tests & (_enableBit)) {\
|
||||
printf ("==> Test %02x runAsyncAfter sync=%s\n", (_enableBit), #_sync);\
|
||||
runStreamerLoop(_streamers);\
|
||||
(_sync);\
|
||||
checkAll (initValue, _streamers, sideStreams, _expectPass);\
|
||||
#define RUN_SYNC_TEST(_enableBit, _streamers, _sync, _expectPass) \
|
||||
if (p_tests & (_enableBit)) { \
|
||||
printf("==> Test %02x runAsyncAfter sync=%s\n", (_enableBit), #_sync); \
|
||||
runStreamerLoop(_streamers); \
|
||||
(_sync); \
|
||||
checkAll(initValue, _streamers, sideStreams, _expectPass); \
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//---
|
||||
// A family of sync functions which somehow wait for inflight activity to finish:
|
||||
|
||||
|
||||
void sync_none(void) {};
|
||||
void sync_none(void){};
|
||||
|
||||
void sync_allDevices(int numDevices)
|
||||
{
|
||||
for (int d=0; d<numDevices; d++) {
|
||||
void sync_allDevices(int numDevices) {
|
||||
for (int d = 0; d < numDevices; d++) {
|
||||
HIPCHECK(hipSetDevice(d));
|
||||
HIPCHECK(hipDeviceSynchronize());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void sync_queryAllUntilComplete(std::vector<IntStreamer *> streamers)
|
||||
{
|
||||
for (int i=streamers.size()-1; i>=0; i--) {
|
||||
void sync_queryAllUntilComplete(std::vector<IntStreamer*> streamers) {
|
||||
for (int i = streamers.size() - 1; i >= 0; i--) {
|
||||
streamers[i]->queryUntilComplete();
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
void sync_streamWaitEvent(hipEvent_t lastEvent, int sideDeviceId, hipStream_t sideStream, bool waitHere)
|
||||
{
|
||||
void sync_streamWaitEvent(hipEvent_t lastEvent, int sideDeviceId, hipStream_t sideStream,
|
||||
bool waitHere) {
|
||||
HIPCHECK(hipSetDevice(sideDeviceId));
|
||||
|
||||
// wait on the last event in the stream of chained streamers:
|
||||
@@ -379,31 +348,28 @@ void sync_streamWaitEvent(hipEvent_t lastEvent, int sideDeviceId, hipStream_t si
|
||||
}
|
||||
|
||||
|
||||
|
||||
//---
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int main(int argc, char* argv[]) {
|
||||
HipTest::parseStandardArguments(argc, argv, false);
|
||||
parseMyArguments(argc, argv);
|
||||
|
||||
|
||||
|
||||
|
||||
size_t numElements = N;
|
||||
size_t sizeElements = numElements * sizeof(int);
|
||||
|
||||
printf("info: sizeof arrays = %zu elements (%6.3f MB)\n", numElements, sizeElements / 1024.0/1024.0);
|
||||
printf("info: sizeof arrays = %zu elements (%6.3f MB)\n", numElements,
|
||||
sizeElements / 1024.0 / 1024.0);
|
||||
printf("info: streams=%d count=%d\n", p_streams, p_count);
|
||||
|
||||
assert (sizeElements <= std::numeric_limits<int64_t>::max());
|
||||
assert(sizeElements <= std::numeric_limits<int64_t>::max());
|
||||
|
||||
|
||||
int initValue = 1000;
|
||||
|
||||
int * initArray_d, *initArray_h;
|
||||
int *initArray_d, *initArray_h;
|
||||
HIPCHECK(hipMalloc(&initArray_d, sizeElements));
|
||||
HIPCHECK(hipHostMalloc(&initArray_h, sizeElements));
|
||||
for (size_t i=0; i<numElements; i++) {
|
||||
for (size_t i = 0; i < numElements; i++) {
|
||||
initArray_h[i] = initValue;
|
||||
}
|
||||
HIPCHECK(hipMemcpy(initArray_d, initArray_h, sizeElements, hipMemcpyHostToDevice));
|
||||
@@ -411,31 +377,29 @@ int main(int argc, char *argv[])
|
||||
|
||||
int numDevices;
|
||||
HIPCHECK(hipGetDeviceCount(&numDevices));
|
||||
numDevices = min(2, numDevices); // multi-GPU to 2 device.
|
||||
numDevices = min(2, numDevices); // multi-GPU to 2 device.
|
||||
|
||||
std::vector<IntStreamer *> streamers;
|
||||
std::vector<IntStreamer *> streamersDev0; // streamers for first device.
|
||||
std::vector<IntStreamer*> streamers;
|
||||
std::vector<IntStreamer*> streamersDev0; // streamers for first device.
|
||||
|
||||
for (int d=0; d<numDevices/*TODO*/; d++) {
|
||||
for (int i=0; i<p_streams; i++) {
|
||||
int command = (i%2) ? COMMAND_ADD_FORWARD : COMMAND_ADD_REVERSE;
|
||||
IntStreamer * s = new IntStreamer(d, i ? streamers.back()->C_d() : initArray_d, numElements, command);
|
||||
for (int d = 0; d < numDevices /*TODO*/; d++) {
|
||||
for (int i = 0; i < p_streams; i++) {
|
||||
int command = (i % 2) ? COMMAND_ADD_FORWARD : COMMAND_ADD_REVERSE;
|
||||
IntStreamer* s =
|
||||
new IntStreamer(d, i ? streamers.back()->C_d() : initArray_d, numElements, command);
|
||||
streamers.push_back(s);
|
||||
if (d==0) {
|
||||
if (d == 0) {
|
||||
streamersDev0.push_back(s);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// A sideband stream channel that is independent from above.
|
||||
// Used to check to ensure the WaitEvent or other synchronization is working correctly since by default sideStream is
|
||||
// asynchronous wrt the other streams.
|
||||
// Used to check to ensure the WaitEvent or other synchronization is working correctly since by
|
||||
// default sideStream is asynchronous wrt the other streams.
|
||||
std::vector<hipStream_t> sideStreams;
|
||||
for (int d=0; d<numDevices; d++) {
|
||||
for (int d = 0; d < numDevices; d++) {
|
||||
hipStream_t s;
|
||||
HIPCHECK(hipStreamCreate(&s));
|
||||
sideStreams.push_back(s);
|
||||
@@ -444,27 +408,31 @@ int main(int argc, char *argv[])
|
||||
|
||||
// Tests on first GPU:
|
||||
//
|
||||
// This test has no synchronization - make sure it mismatches so we can ensure the other tests properyl prevent the mismatch:
|
||||
// This test has no synchronization - make sure it mismatches so we can ensure the other tests
|
||||
// properyl prevent the mismatch:
|
||||
RUN_SYNC_TEST(0x01, streamersDev0, sync_none(), false);
|
||||
|
||||
RUN_SYNC_TEST(0x02, streamersDev0, sync_allDevices(numDevices), true);
|
||||
RUN_SYNC_TEST(0x04, streamersDev0, sync_queryAllUntilComplete(streamersDev0), true);
|
||||
RUN_SYNC_TEST(0x08, streamersDev0, sync_streamWaitEvent(streamersDev0.back()->event(), 0, sideStreams[0], false), true);
|
||||
RUN_SYNC_TEST(0x02, streamersDev0, sync_allDevices(numDevices), true);
|
||||
RUN_SYNC_TEST(0x04, streamersDev0, sync_queryAllUntilComplete(streamersDev0), true);
|
||||
RUN_SYNC_TEST(0x08, streamersDev0,
|
||||
sync_streamWaitEvent(streamersDev0.back()->event(), 0, sideStreams[0], false),
|
||||
true);
|
||||
|
||||
if (numDevices > 1) {
|
||||
// Sync on second device for activity running on device 0:
|
||||
RUN_SYNC_TEST(0x10, streamersDev0, sync_streamWaitEvent(streamersDev0.back()->event(), 1, sideStreams[1], true), true);
|
||||
RUN_SYNC_TEST(0x10, streamersDev0,
|
||||
sync_streamWaitEvent(streamersDev0.back()->event(), 1, sideStreams[1], true),
|
||||
true);
|
||||
}
|
||||
|
||||
|
||||
// Tests on all GPUs:
|
||||
// RUN_SYNC_TEST(0x100, streamers, sync_streamWaitEvent(streamers.back()->event(), 0, sideStreams[0], false), true);
|
||||
|
||||
|
||||
// RUN_SYNC_TEST(0x100, streamers, sync_streamWaitEvent(streamers.back()->event(), 0,
|
||||
// sideStreams[0], false), true);
|
||||
|
||||
|
||||
if (p_tests & 0x1000) {
|
||||
printf ("==> Test 0x1000 simple null stream tests\n");
|
||||
printf("==> Test 0x1000 simple null stream tests\n");
|
||||
|
||||
// try some null stream:
|
||||
hipStreamQuery(0);
|
||||
@@ -480,7 +448,7 @@ int main(int argc, char *argv[])
|
||||
|
||||
HIPCHECK(hipEventRecord(e1, s1))
|
||||
|
||||
HIPCHECK(hipStreamWaitEvent(hipStream_t(0), e1, 0/*flags*/));
|
||||
HIPCHECK(hipStreamWaitEvent(hipStream_t(0), e1, 0 /*flags*/));
|
||||
|
||||
HIPCHECK(hipStreamDestroy(s1));
|
||||
HIPCHECK(hipEventDestroy(e1));
|
||||
@@ -493,38 +461,39 @@ int main(int argc, char *argv[])
|
||||
|
||||
HIPCHECK(hipEventRecord(e1, hipStream_t(0)))
|
||||
|
||||
HIPCHECK(hipStreamWaitEvent(s1, e1, 0/*flags*/));
|
||||
HIPCHECK(hipStreamWaitEvent(s1, e1, 0 /*flags*/));
|
||||
|
||||
HIPCHECK(hipStreamDestroy(s1));
|
||||
HIPCHECK(hipEventDestroy(e1));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
// Insert small wrinkle here, insert a wait on event just recorded, all in the same stream.
|
||||
if (p_tests & 0x2000) {
|
||||
printf ("==> Test 0x2000 runAsyncWaitSameStream\n");
|
||||
for (int i=0; i<streamersDev0.size(); i++) {
|
||||
streamersDev0[i]->runAsyncAfter(i ? streamersDev0[i-1] : NULL, true/*waitSameStream*/);
|
||||
printf("==> Test 0x2000 runAsyncWaitSameStream\n");
|
||||
for (int i = 0; i < streamersDev0.size(); i++) {
|
||||
streamersDev0[i]->runAsyncAfter(i ? streamersDev0[i - 1] : NULL,
|
||||
true /*waitSameStream*/);
|
||||
}
|
||||
|
||||
sync_streamWaitEvent(streamersDev0.back()->event(), 0, sideStreams[0], false);
|
||||
checkAll (initValue, streamersDev0, sideStreams);
|
||||
checkAll(initValue, streamersDev0, sideStreams);
|
||||
}
|
||||
|
||||
|
||||
// Change Adds to copies to stimulate different case with event followign copy:
|
||||
for (auto &s : streamers) {
|
||||
if (s->_commandType == COMMAND_ADD_FORWARD)
|
||||
s->_commandType = COMMAND_COPY;
|
||||
for (auto& s : streamers) {
|
||||
if (s->_commandType == COMMAND_ADD_FORWARD) s->_commandType = COMMAND_COPY;
|
||||
}
|
||||
|
||||
|
||||
if (p_tests & 0x4000 ) {
|
||||
printf ("test: %x alternating memcpy/count-reverse followed by event\n", p_tests);
|
||||
RUN_SYNC_TEST(0x4000, streamersDev0, sync_queryAllUntilComplete(streamersDev0), true);
|
||||
RUN_SYNC_TEST(0x8000, streamersDev0, sync_streamWaitEvent(streamersDev0.back()->event(), 0, sideStreams[0], false), true);
|
||||
if (p_tests & 0x4000) {
|
||||
printf("test: %x alternating memcpy/count-reverse followed by event\n", p_tests);
|
||||
RUN_SYNC_TEST(0x4000, streamersDev0, sync_queryAllUntilComplete(streamersDev0), true);
|
||||
RUN_SYNC_TEST(0x8000, streamersDev0,
|
||||
sync_streamWaitEvent(streamersDev0.back()->event(), 0, sideStreams[0], false),
|
||||
true);
|
||||
}
|
||||
|
||||
|
||||
|
||||
+109
-129
@@ -20,8 +20,8 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
//ROCM_TARGET=gfx900 hipcc --genco memcpyInt.device.cpp -o memcpyInt.hsaco
|
||||
//hipcc copy_coherency.cpp -I ~/X/HIP/tests/src/ ~/X/HIP/tests/src/test_common.cpp
|
||||
// ROCM_TARGET=gfx900 hipcc --genco memcpyInt.device.cpp -o memcpyInt.hsaco
|
||||
// hipcc copy_coherency.cpp -I ~/X/HIP/tests/src/ ~/X/HIP/tests/src/test_common.cpp
|
||||
|
||||
|
||||
// TODO - add code object support here.
|
||||
@@ -44,34 +44,33 @@ THE SOFTWARE.
|
||||
#define SKIP_MODULE_KERNEL 1
|
||||
|
||||
|
||||
class MemcpyFunction
|
||||
{
|
||||
public:
|
||||
MemcpyFunction(const char *fileName, const char *functionName) { load(fileName, functionName); };
|
||||
void load(const char *fileName, const char *functionName);
|
||||
void launch(int * dst, const int * src, size_t numElements, hipStream_t s);
|
||||
class MemcpyFunction {
|
||||
public:
|
||||
MemcpyFunction(const char* fileName, const char* functionName) {
|
||||
load(fileName, functionName);
|
||||
};
|
||||
void load(const char* fileName, const char* functionName);
|
||||
void launch(int* dst, const int* src, size_t numElements, hipStream_t s);
|
||||
|
||||
private:
|
||||
private:
|
||||
hipFunction_t _function;
|
||||
hipModule_t _module;
|
||||
hipModule_t _module;
|
||||
};
|
||||
|
||||
|
||||
void MemcpyFunction::load(const char *fileName, const char *functionName)
|
||||
{
|
||||
#if SKIP_MODULE_KERNEL!=1
|
||||
void MemcpyFunction::load(const char* fileName, const char* functionName) {
|
||||
#if SKIP_MODULE_KERNEL != 1
|
||||
HIPCHECK(hipModuleLoad(&_module, fileName));
|
||||
HIPCHECK(hipModuleGetFunction(&_function, _module, functionName));
|
||||
#endif
|
||||
};
|
||||
|
||||
|
||||
void MemcpyFunction::launch(int * dst, const int * src, size_t numElements, hipStream_t s)
|
||||
{
|
||||
void MemcpyFunction::launch(int* dst, const int* src, size_t numElements, hipStream_t s) {
|
||||
struct {
|
||||
int* _dst;
|
||||
const int* _src;
|
||||
size_t _numElements;
|
||||
int* _dst;
|
||||
const int* _src;
|
||||
size_t _numElements;
|
||||
} args;
|
||||
|
||||
args._dst = dst;
|
||||
@@ -79,55 +78,49 @@ void MemcpyFunction::launch(int * dst, const int * src, size_t numElements, hipS
|
||||
args._numElements = numElements;
|
||||
|
||||
size_t size = sizeof(args);
|
||||
void *config[] = {
|
||||
HIP_LAUNCH_PARAM_BUFFER_POINTER, &args,
|
||||
HIP_LAUNCH_PARAM_BUFFER_SIZE, &size,
|
||||
HIP_LAUNCH_PARAM_END
|
||||
};
|
||||
void* config[] = {HIP_LAUNCH_PARAM_BUFFER_POINTER, &args, HIP_LAUNCH_PARAM_BUFFER_SIZE, &size,
|
||||
HIP_LAUNCH_PARAM_END};
|
||||
|
||||
unsigned blocks = HipTest::setNumBlocks(blocksPerCU, threadsPerBlock, numElements);
|
||||
HIPCHECK(hipModuleLaunchKernel(_function, blocks, 1, 1, threadsPerBlock, 1, 1, 0/*dynamicShared*/, s, NULL, (void**)&config));
|
||||
HIPCHECK(hipModuleLaunchKernel(_function, blocks, 1, 1, threadsPerBlock, 1, 1,
|
||||
0 /*dynamicShared*/, s, NULL, (void**)&config));
|
||||
};
|
||||
|
||||
bool g_warnOnFail = true;
|
||||
//int g_elementSizes[] = {1, 16, 1024, 524288, 16*1000*1000}; // TODO
|
||||
int g_elementSizes[] = {128*1000, 256*1000, 16*1000*1000};
|
||||
// int g_elementSizes[] = {1, 16, 1024, 524288, 16*1000*1000}; // TODO
|
||||
int g_elementSizes[] = {128 * 1000, 256 * 1000, 16 * 1000 * 1000};
|
||||
|
||||
MemcpyFunction g_moduleMemcpy("memcpyInt.hsaco", "memcpyIntKernel");
|
||||
|
||||
|
||||
|
||||
// Set value of array to specified 32-bit integer:
|
||||
__global__ void
|
||||
memsetIntKernel(int * ptr, const int val, size_t numElements)
|
||||
{
|
||||
__global__ void memsetIntKernel(int* ptr, const int val, size_t numElements) {
|
||||
int gid = (blockIdx.x * blockDim.x + threadIdx.x);
|
||||
int stride = blockDim.x * gridDim.x ;
|
||||
for (size_t i= gid; i< numElements; i+=stride){
|
||||
ptr[i] = val;
|
||||
int stride = blockDim.x * gridDim.x;
|
||||
for (size_t i = gid; i < numElements; i += stride) {
|
||||
ptr[i] = val;
|
||||
}
|
||||
};
|
||||
|
||||
__global__ void
|
||||
memcpyIntKernel(int *dst, const int * src, size_t numElements)
|
||||
{
|
||||
__global__ void memcpyIntKernel(int* dst, const int* src, size_t numElements) {
|
||||
int gid = (blockIdx.x * blockDim.x + threadIdx.x);
|
||||
int stride = blockDim.x * gridDim.x ;
|
||||
for (size_t i= gid; i< numElements; i+=stride){
|
||||
dst[i] = src[i];
|
||||
int stride = blockDim.x * gridDim.x;
|
||||
for (size_t i = gid; i < numElements; i += stride) {
|
||||
dst[i] = src[i];
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
// CHeck arrays in reverse order, to more easily detect cases where
|
||||
// the copy is "partially" done.
|
||||
void checkReverse(const int *ptr, int numElements, int expected) {
|
||||
void checkReverse(const int* ptr, int numElements, int expected) {
|
||||
int mismatchCnt = 0;
|
||||
for (int i=numElements-1; i>=0; i--) {
|
||||
for (int i = numElements - 1; i >= 0; i--) {
|
||||
if (ptr[i] != expected) {
|
||||
fprintf (stderr, "%s**error: i=%d, ptr[i] == (%x) , does not equal expected (%x)\n%s", KRED, i, ptr[i], expected, KNRM);
|
||||
fprintf(stderr, "%s**error: i=%d, ptr[i] == (%x) , does not equal expected (%x)\n%s",
|
||||
KRED, i, ptr[i], expected, KNRM);
|
||||
if (!g_warnOnFail) {
|
||||
assert (ptr[i] == expected);
|
||||
assert(ptr[i] == expected);
|
||||
}
|
||||
if (++mismatchCnt >= 10) {
|
||||
break;
|
||||
@@ -135,26 +128,23 @@ void checkReverse(const int *ptr, int numElements, int expected) {
|
||||
}
|
||||
}
|
||||
|
||||
fprintf (stderr, "test: OK\n");
|
||||
fprintf(stderr, "test: OK\n");
|
||||
}
|
||||
|
||||
#define ENUM_CASE_STR(x) case x: return #x
|
||||
#define ENUM_CASE_STR(x) \
|
||||
case x: \
|
||||
return #x
|
||||
|
||||
enum CmdType {
|
||||
COPY,
|
||||
KERNEL,
|
||||
MODULE_KERNEL,
|
||||
MAX_CmdType
|
||||
};
|
||||
enum CmdType { COPY, KERNEL, MODULE_KERNEL, MAX_CmdType };
|
||||
|
||||
|
||||
const char * CmdTypeStr(CmdType c)
|
||||
{
|
||||
switch(c) {
|
||||
const char* CmdTypeStr(CmdType c) {
|
||||
switch (c) {
|
||||
ENUM_CASE_STR(COPY);
|
||||
ENUM_CASE_STR(KERNEL);
|
||||
ENUM_CASE_STR(MODULE_KERNEL);
|
||||
default: return "UNKNOWN";
|
||||
default:
|
||||
return "UNKNOWN";
|
||||
};
|
||||
}
|
||||
|
||||
@@ -171,9 +161,8 @@ enum SyncType {
|
||||
};
|
||||
|
||||
|
||||
const char * SyncTypeStr(SyncType s)
|
||||
{
|
||||
switch(s) {
|
||||
const char* SyncTypeStr(SyncType s) {
|
||||
switch (s) {
|
||||
ENUM_CASE_STR(NONE);
|
||||
ENUM_CASE_STR(EVENT_QUERY);
|
||||
ENUM_CASE_STR(EVENT_SYNC);
|
||||
@@ -181,24 +170,23 @@ const char * SyncTypeStr(SyncType s)
|
||||
ENUM_CASE_STR(STREAM_QUERY);
|
||||
ENUM_CASE_STR(STREAM_SYNC);
|
||||
ENUM_CASE_STR(DEVICE_SYNC);
|
||||
default: return "UNKNOWN";
|
||||
default:
|
||||
return "UNKNOWN";
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
void runCmd(CmdType cmd, int *dst, const int *src, hipStream_t s, size_t numElements)
|
||||
{
|
||||
void runCmd(CmdType cmd, int* dst, const int* src, hipStream_t s, size_t numElements) {
|
||||
switch (cmd) {
|
||||
case COPY:
|
||||
HIPCHECK(hipMemcpyAsync(dst, src, numElements*sizeof(int), hipMemcpyDeviceToDevice, s));
|
||||
break;
|
||||
case KERNEL:
|
||||
{
|
||||
unsigned blocks = HipTest::setNumBlocks(blocksPerCU, threadsPerBlock, numElements);
|
||||
hipLaunchKernelGGL(memcpyIntKernel, dim3(blocks), dim3(threadsPerBlock), 0, s,
|
||||
dst, src, numElements);
|
||||
}
|
||||
HIPCHECK(
|
||||
hipMemcpyAsync(dst, src, numElements * sizeof(int), hipMemcpyDeviceToDevice, s));
|
||||
break;
|
||||
case KERNEL: {
|
||||
unsigned blocks = HipTest::setNumBlocks(blocksPerCU, threadsPerBlock, numElements);
|
||||
hipLaunchKernelGGL(memcpyIntKernel, dim3(blocks), dim3(threadsPerBlock), 0, s, dst, src,
|
||||
numElements);
|
||||
} break;
|
||||
case MODULE_KERNEL:
|
||||
g_moduleMemcpy.launch(dst, src, numElements, s);
|
||||
break;
|
||||
@@ -207,44 +195,44 @@ void runCmd(CmdType cmd, int *dst, const int *src, hipStream_t s, size_t numElem
|
||||
};
|
||||
}
|
||||
|
||||
void resetInputs( int * Ad, int * Bd, int *Cd, int *Ch, size_t numElements, int expected)
|
||||
{
|
||||
void resetInputs(int* Ad, int* Bd, int* Cd, int* Ch, size_t numElements, int expected) {
|
||||
unsigned blocks = HipTest::setNumBlocks(blocksPerCU, threadsPerBlock, numElements);
|
||||
hipLaunchKernelGGL(memsetIntKernel, dim3(blocks), dim3(threadsPerBlock), 0, hipStream_t(0),
|
||||
Ad, expected, numElements);
|
||||
hipLaunchKernelGGL(memsetIntKernel, dim3(blocks), dim3(threadsPerBlock), 0, hipStream_t(0),
|
||||
Bd, 0xDEADBEEF, numElements); // poison with bad value to ensure is overwritten correctly
|
||||
hipLaunchKernelGGL(memsetIntKernel, dim3(blocks), dim3(threadsPerBlock), 0, hipStream_t(0),
|
||||
Bd, 0xF000BA55, numElements); // poison with bad value to ensure is overwritten correctly
|
||||
memset(Ch, 13, numElements*sizeof(int)); // poison with bad value to ensure is overwritten correctly
|
||||
hipLaunchKernelGGL(memsetIntKernel, dim3(blocks), dim3(threadsPerBlock), 0, hipStream_t(0), Ad,
|
||||
expected, numElements);
|
||||
hipLaunchKernelGGL(memsetIntKernel, dim3(blocks), dim3(threadsPerBlock), 0, hipStream_t(0), Bd,
|
||||
0xDEADBEEF,
|
||||
numElements); // poison with bad value to ensure is overwritten correctly
|
||||
hipLaunchKernelGGL(memsetIntKernel, dim3(blocks), dim3(threadsPerBlock), 0, hipStream_t(0), Bd,
|
||||
0xF000BA55,
|
||||
numElements); // poison with bad value to ensure is overwritten correctly
|
||||
memset(Ch, 13,
|
||||
numElements * sizeof(int)); // poison with bad value to ensure is overwritten correctly
|
||||
HIPCHECK(hipDeviceSynchronize());
|
||||
}
|
||||
|
||||
// Intended to test proper synchronization and cache flushing between CMDA and CMDB.
|
||||
// CMD are of type CmdType. All command copy memory, using either hipMemcpyAsync or kernel implementations.
|
||||
// CmdA copies from Ad to Bd,
|
||||
// Some form of synchronization is applied.
|
||||
// Then cmdB copies from Bd to Cd.
|
||||
// CMD are of type CmdType. All command copy memory, using either hipMemcpyAsync or kernel
|
||||
// implementations. CmdA copies from Ad to Bd, Some form of synchronization is applied. Then cmdB
|
||||
// copies from Bd to Cd.
|
||||
//
|
||||
// Cd is then copied to host Ch using a memory copy.
|
||||
//
|
||||
// Correct result at the end is that Ch contains the contents originally in Ad (integer 0x42)
|
||||
void runTestImpl(CmdType cmdAType, SyncType syncType, CmdType cmdBType,
|
||||
hipStream_t stream1, hipStream_t stream2, int numElements,
|
||||
int * Ad, int * Bd, int *Cd, int *Ch,
|
||||
int expected)
|
||||
{
|
||||
void runTestImpl(CmdType cmdAType, SyncType syncType, CmdType cmdBType, hipStream_t stream1,
|
||||
hipStream_t stream2, int numElements, int* Ad, int* Bd, int* Cd, int* Ch,
|
||||
int expected) {
|
||||
hipEvent_t e;
|
||||
HIPCHECK(hipEventCreateWithFlags(&e,0));
|
||||
HIPCHECK(hipEventCreateWithFlags(&e, 0));
|
||||
|
||||
resetInputs(Ad, Bd, Cd, Ch, numElements, expected);
|
||||
|
||||
const size_t sizeElements = numElements * sizeof(int);
|
||||
fprintf (stderr, "test: runTest with %zu bytes (%6.2f MB) cmdA=%s; sync=%s; cmdB=%s\n",
|
||||
sizeElements, (double) (sizeElements/1024.0), CmdTypeStr(cmdAType), SyncTypeStr(syncType), CmdTypeStr(cmdBType));
|
||||
fprintf(stderr, "test: runTest with %zu bytes (%6.2f MB) cmdA=%s; sync=%s; cmdB=%s\n",
|
||||
sizeElements, (double)(sizeElements / 1024.0), CmdTypeStr(cmdAType),
|
||||
SyncTypeStr(syncType), CmdTypeStr(cmdBType));
|
||||
|
||||
if (SKIP_MODULE_KERNEL && ((cmdAType == MODULE_KERNEL) || (cmdBType == MODULE_KERNEL))) {
|
||||
fprintf (stderr, "warn: skipping since test infra does not yet support modules\n");
|
||||
fprintf(stderr, "warn: skipping since test infra does not yet support modules\n");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -257,16 +245,14 @@ void runTestImpl(CmdType cmdAType, SyncType syncType, CmdType cmdBType,
|
||||
switch (syncType) {
|
||||
case NONE:
|
||||
break;
|
||||
case EVENT_QUERY:
|
||||
{
|
||||
hipError_t st = hipErrorNotReady;
|
||||
HIPCHECK(hipEventRecord(e, stream1));
|
||||
do {
|
||||
st = hipEventQuery(e);
|
||||
} while (st == hipErrorNotReady);
|
||||
HIPCHECK(st);
|
||||
}
|
||||
break;
|
||||
case EVENT_QUERY: {
|
||||
hipError_t st = hipErrorNotReady;
|
||||
HIPCHECK(hipEventRecord(e, stream1));
|
||||
do {
|
||||
st = hipEventQuery(e);
|
||||
} while (st == hipErrorNotReady);
|
||||
HIPCHECK(st);
|
||||
} break;
|
||||
case EVENT_SYNC:
|
||||
HIPCHECK(hipEventRecord(e, stream1));
|
||||
HIPCHECK(hipEventSynchronize(e));
|
||||
@@ -275,15 +261,13 @@ void runTestImpl(CmdType cmdAType, SyncType syncType, CmdType cmdBType,
|
||||
HIPCHECK(hipEventRecord(e, stream1));
|
||||
HIPCHECK(hipStreamWaitEvent(stream2, e, 0));
|
||||
break;
|
||||
case STREAM_QUERY:
|
||||
{
|
||||
hipError_t st = hipErrorNotReady;
|
||||
do {
|
||||
st = hipStreamQuery(stream1);
|
||||
} while (st == hipErrorNotReady);
|
||||
HIPCHECK(st);
|
||||
}
|
||||
break;
|
||||
case STREAM_QUERY: {
|
||||
hipError_t st = hipErrorNotReady;
|
||||
do {
|
||||
st = hipStreamQuery(stream1);
|
||||
} while (st == hipErrorNotReady);
|
||||
HIPCHECK(st);
|
||||
} break;
|
||||
case STREAM_SYNC:
|
||||
HIPCHECK(hipStreamSynchronize(stream1));
|
||||
break;
|
||||
@@ -292,8 +276,8 @@ void runTestImpl(CmdType cmdAType, SyncType syncType, CmdType cmdBType,
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr, "warning: unknown sync type=%s", SyncTypeStr(syncType));
|
||||
return; // FIXME, this doesn't clean up
|
||||
//failed("unknown sync type=%s", SyncTypeStr(syncType));
|
||||
return; // FIXME, this doesn't clean up
|
||||
// failed("unknown sync type=%s", SyncTypeStr(syncType));
|
||||
};
|
||||
|
||||
|
||||
@@ -310,11 +294,10 @@ void runTestImpl(CmdType cmdAType, SyncType syncType, CmdType cmdBType,
|
||||
};
|
||||
|
||||
|
||||
void testWrapper(size_t numElements)
|
||||
{
|
||||
void testWrapper(size_t numElements) {
|
||||
const size_t sizeElements = numElements * sizeof(int);
|
||||
const int expected = 0x42;
|
||||
int * Ad, * Bd, *Cd, *Ch;
|
||||
int *Ad, *Bd, *Cd, *Ch;
|
||||
|
||||
HIPCHECK(hipMalloc(&Ad, sizeElements));
|
||||
HIPCHECK(hipMalloc(&Bd, sizeElements));
|
||||
@@ -322,7 +305,6 @@ void testWrapper(size_t numElements)
|
||||
HIPCHECK(hipHostMalloc(&Ch, sizeElements)); // Ch is the end array
|
||||
|
||||
|
||||
|
||||
hipStream_t stream1, stream2;
|
||||
|
||||
HIPCHECK(hipStreamCreate(&stream1));
|
||||
@@ -330,27 +312,27 @@ void testWrapper(size_t numElements)
|
||||
|
||||
|
||||
HIPCHECK(hipDeviceSynchronize());
|
||||
fprintf (stderr, "test: init complete, start running tests\n");
|
||||
fprintf(stderr, "test: init complete, start running tests\n");
|
||||
|
||||
|
||||
runTestImpl(COPY, EVENT_SYNC, KERNEL, stream1, stream2, numElements, Ad, Bd, Cd, Ch, expected);
|
||||
|
||||
for (int cmdA=0; cmdA<MAX_CmdType; cmdA++) {
|
||||
for (int cmdB=0; cmdB<MAX_CmdType; cmdB++) {
|
||||
for (int syncMode=0; syncMode<MAX_SyncType; syncMode++) {
|
||||
switch(syncMode) {
|
||||
//case NONE::
|
||||
for (int cmdA = 0; cmdA < MAX_CmdType; cmdA++) {
|
||||
for (int cmdB = 0; cmdB < MAX_CmdType; cmdB++) {
|
||||
for (int syncMode = 0; syncMode < MAX_SyncType; syncMode++) {
|
||||
switch (syncMode) {
|
||||
// case NONE::
|
||||
case EVENT_QUERY:
|
||||
case EVENT_SYNC:
|
||||
case STREAM_WAIT_EVENT:
|
||||
//case STREAM_QUERY:
|
||||
// case STREAM_QUERY:
|
||||
case STREAM_SYNC:
|
||||
case DEVICE_SYNC:
|
||||
runTestImpl(CmdType(cmdA), SyncType(syncMode), CmdType(cmdB), stream1, stream2, numElements, Ad, Bd, Cd, Ch, expected);
|
||||
runTestImpl(CmdType(cmdA), SyncType(syncMode), CmdType(cmdB), stream1,
|
||||
stream2, numElements, Ad, Bd, Cd, Ch, expected);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -374,10 +356,8 @@ void testWrapper(size_t numElements)
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
|
||||
for(int index = 0;index < sizeof(g_elementSizes) / sizeof(int); index++) {
|
||||
int main(int argc, char* argv[]) {
|
||||
for (int index = 0; index < sizeof(g_elementSizes) / sizeof(int); index++) {
|
||||
size_t numElements = g_elementSizes[index];
|
||||
testWrapper(numElements);
|
||||
}
|
||||
|
||||
@@ -1,13 +1,11 @@
|
||||
#include <hip/hip_runtime.h>
|
||||
|
||||
|
||||
|
||||
extern "C" __global__ void
|
||||
memcpyIntKernel(hipLaunchParm lp, int *dst, const int * src, size_t numElements)
|
||||
{
|
||||
extern "C" __global__ void memcpyIntKernel(hipLaunchParm lp, int* dst, const int* src,
|
||||
size_t numElements) {
|
||||
int gid = (blockIdx.x * blockDim.x + threadIdx.x);
|
||||
int stride = blockDim.x * gridDim.x ;
|
||||
for (size_t i= gid; i< numElements; i+=stride){
|
||||
dst[i] = src[i];
|
||||
int stride = blockDim.x * gridDim.x;
|
||||
for (size_t i = gid; i < numElements; i += stride) {
|
||||
dst[i] = src[i];
|
||||
}
|
||||
};
|
||||
|
||||
In neuem Issue referenzieren
Einen Benutzer sperren