SWDEV-420894 - Remove directed tests
Point users to correct hip-tests path. Remove references of directed test from code. Replace documentation which used directed test with a native sample. Change-Id: I3e8b5b5b40c0847e03d3aa637ea5b0c0d06c1201
Этот коммит содержится в:
коммит произвёл
Rahul Garg
родитель
f324a8f9ee
Коммит
405d029422
@@ -123,47 +123,14 @@ hip_prof_gen.py -v -p -t --priv <hip>/include/hip/hip_runtime_api.h \
|
||||
|
||||
### Build HIP tests
|
||||
|
||||
#### Build HIP directed tests
|
||||
Developers can build HIP directed tests right after build HIP commands,
|
||||
|
||||
```shell
|
||||
sudo make install
|
||||
make -j$(nproc) build_tests
|
||||
```
|
||||
By default, all HIP directed tests will be built and generated under the folder `$CLR_DIR/build/hipamd`directed_tests.
|
||||
Take HIP directed device APIs tests, as an example, all available test applications will have executable files generated under,
|
||||
`$CLR_DIR/build/hipamd/directed_tests/runtimeApi/device`.
|
||||
|
||||
Run all HIP directed_tests, use the command,
|
||||
|
||||
```shell
|
||||
ctest
|
||||
```
|
||||
Or
|
||||
```shell
|
||||
make test
|
||||
```
|
||||
|
||||
Build and run a single directed test, use the follow command as an example,
|
||||
|
||||
```shell
|
||||
make directed_tests.texture.hipTexObjPitch
|
||||
cd $CLR_DIR/build/hipamd/directed_tests/texcture
|
||||
./hipTexObjPitch
|
||||
```
|
||||
Please note, the integrated HIP directed tests, will be deprecated in future release.
|
||||
|
||||
|
||||
##### Build HIP catch tests
|
||||
|
||||
HIP catch tests, with new architectured Catch2, are official seperated from HIP project, exist in HIP tests repository, can be built via the following instructions.
|
||||
|
||||
##### Get HIP tests source code
|
||||
#### Get HIP tests source code
|
||||
|
||||
```shell
|
||||
git clone -b "$ROCM_BRANCH" https://github.com/ROCm-Developer-Tools/hip-tests.git
|
||||
```
|
||||
##### Build HIP tests from source
|
||||
#### Build HIP tests from source
|
||||
|
||||
```shell
|
||||
export HIPTESTS_DIR="$(readlink -f hip-tests)"
|
||||
@@ -183,7 +150,7 @@ cd $HIPTESTS_DIR/build/catch_tests/unit/texture
|
||||
./TextureTest
|
||||
```
|
||||
|
||||
##### Build HIP Catch2 standalone test
|
||||
#### Build HIP Catch2 standalone test
|
||||
|
||||
HIP Catch2 supports build a standalone test, for example,
|
||||
|
||||
|
||||
@@ -59,16 +59,16 @@ Selected multilib: .;@m64
|
||||
|
||||
## Unit Testing Environment
|
||||
|
||||
HIP includes unit tests in the tests/src directory.
|
||||
When adding a new HIP feature, add a new unit test as well.
|
||||
See [tests/README.md](README.md) for more information.
|
||||
Tests for HIP are hosted at [ROCm-Developer-Tools/hip-tests](https://github.com/ROCm-Developer-Tools/hip-tests).
|
||||
|
||||
To run `hip-tests` please go to the repo and follow the steps.
|
||||
|
||||
## Development Flow
|
||||
|
||||
Directed tests provide a great place to develop new features alongside the associated test.
|
||||
`hip-tests` provide a great place to develop new features alongside the associated test.
|
||||
|
||||
For applications and benchmarks outside the directed test environment, developments should use a two-step development flow:
|
||||
- #1. Compile, link, and install HIP/ROCclr. See [Installation](README.md#Installation) notes.
|
||||
For applications and benchmarks outside the hip-tests environment, developments should use a two-step development flow:
|
||||
- #1. Compile, link, and install HIP/ROCclr. See [Installation](README.md#Installation) notes.
|
||||
- #2. Relink the target application to include changes in HIP runtime file.
|
||||
|
||||
## Environment Variables
|
||||
@@ -124,13 +124,7 @@ Differences or limitations of HIP APIs as compared to CUDA APIs should be clearl
|
||||
|
||||
|
||||
### Presubmit Testing:
|
||||
Before checking in or submitting a pull request, run all directed tests (see tests/README.md) and all Rodinia tests.
|
||||
Ensure pass results match starting point:
|
||||
|
||||
```console
|
||||
> cd examples/
|
||||
> ./run_all.sh
|
||||
```
|
||||
Before checking in or submitting a pull request, run all hip-tests (see [ROCm-Developer-Tools/hip-tests](https://github.com/ROCm-Developer-Tools/hip-tests)).
|
||||
|
||||
|
||||
### Checkin messages
|
||||
|
||||
@@ -98,16 +98,16 @@ Find the GDB manual and other documentation resources online at:
|
||||
...
|
||||
Reading symbols from ./hipTexObjPitch...
|
||||
(gdb) break main
|
||||
Breakpoint 1 at 0x4013d1: file /home/test/hip/tests/src/texture/hipTexObjPitch.cpp, line 98.
|
||||
Breakpoint 1 at 0x4013d1: file /home/<your_awesome_name>/hip-tests/samples/2_Cookbook/0_MatrixTranspose/MatrixTranspose.cpp, line 56.
|
||||
(gdb) run
|
||||
Starting program: /home/test/hip/build/directed_tests/texture/hipTexObjPitch
|
||||
Starting program: MatrixTranspose
|
||||
[Thread debugging using libthread_db enabled]
|
||||
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
|
||||
|
||||
Breakpoint 1, main ()
|
||||
at /home/test/hip/tests/src/texture/hipTexObjPitch.cpp:98
|
||||
98 texture2Dtest<float>();
|
||||
(gdb)c
|
||||
at MatrixTranspose.cpp:56
|
||||
56 int main() {
|
||||
(gdb) c
|
||||
|
||||
```
|
||||
|
||||
@@ -116,66 +116,96 @@ There are also other debugging tools available online developers can google and
|
||||
|
||||
## Debugging HIP Applications
|
||||
|
||||
Below is an example on Linux to show how to get useful information from the debugger while running a simple memory copy test, which caused an issue of segmentation fault.
|
||||
Below is an example on Linux to show how to get useful information from the debugger while running a simple hip application, which caused an issue of segmentation fault.
|
||||
|
||||
Simple HIP Program:
|
||||
|
||||
```cpp
|
||||
#include <hip/hip_runtime.h>
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
|
||||
__global__ void kernel_add(int* a, int b) {
|
||||
int i = threadIdx.x;
|
||||
a[i] += b;
|
||||
}
|
||||
|
||||
int main() {
|
||||
constexpr size_t size = 1024;
|
||||
int* ptr;
|
||||
hipMalloc(&ptr, sizeof(int) * size);
|
||||
hipMemset(ptr, 0, sizeof(int) * size);
|
||||
std::vector<int> input(size, 0);
|
||||
size_t i = 100;
|
||||
std::for_each(input.begin(), input.end(), [&](int& a) { a = i; });
|
||||
hipMemcpy(ptr, input.data(), sizeof(int) * size, hipMemcpyHostToDevice);
|
||||
kernel_add<<<1, size>>>(ptr, 10);
|
||||
std::vector<int> output = input;
|
||||
hipMemcpy(output.data(), ptr, sizeof(int) * size, hipMemcpyDeviceToHost);
|
||||
std::cout << ((std::all_of(output.begin(), output.end(), [&](int a) { return a == (i + 10); }))
|
||||
? "passed"
|
||||
: "failed")
|
||||
<< std::endl;
|
||||
hipFree(ptr);
|
||||
}
|
||||
```
|
||||
|
||||
Compile and run command:
|
||||
|
||||
```console
|
||||
test: simpleTest2<?> numElements=4194304 sizeElements=4194304 bytes
|
||||
Segmentation fault (core dumped)
|
||||
hipcc app.cpp -ggdb -o app
|
||||
rocgdb ./app
|
||||
```
|
||||
|
||||
```console
|
||||
(gdb) b main
|
||||
Breakpoint 1 at 0x21275e: file app.cpp, line 14.
|
||||
|
||||
(gdb) run
|
||||
Starting program: /home/test/hipamd/build/directed_tests/runtimeApi/memory/hipMemcpy_simple
|
||||
Starting program: /home/<your_awesome_name>/app
|
||||
warning: os_agent_id 31475: `Device 1002:164e' architecture not supported.
|
||||
[Thread debugging using libthread_db enabled]
|
||||
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
|
||||
|
||||
Breakpoint 1, main (argc=1, argv=0x7fffffffdea8)
|
||||
at /home/test/hip/tests/src/runtimeApi/memory/hipMemcpy_simple.cpp:147
|
||||
147 int main(int argc, char* argv[]) {
|
||||
(gdb) c
|
||||
Continuing.
|
||||
[New Thread 0x7ffff64c4700 (LWP 146066)]
|
||||
Breakpoint 1, hipMalloc<int> (devPtr=0x7fffffffe098, size=4096) at /opt/rocm/include/hip/hip_runtime_api.h:8487
|
||||
8487 return hipMalloc((void**)devPtr, size);
|
||||
|
||||
Thread 1 "hipMemcpy_simpl" received signal SIGSEGV, Segmentation fault.
|
||||
0x000000000020f78e in simpleTest2<float> (numElements=4194304, usePinnedHost=true)
|
||||
at /home/test/hip/tests/src/runtimeApi/memory/hipMemcpy_simple.cpp:104
|
||||
104 A_h1[i] = 3.14f + 1000 * i;
|
||||
(gdb) bt
|
||||
#0 0x000000000020f78e in simpleTest2<float> (numElements=4194304, usePinnedHost=true)
|
||||
at /home/test/hip/tests/src/runtimeApi/memory/hipMemcpy_simple.cpp:104
|
||||
#1 0x000000000020e96c in main (argc=<optimized out>, argv=<optimized out>)
|
||||
at /home/test/hip/tests/src/runtimeApi/memory/hipMemcpy_simple.cpp:163
|
||||
(gdb) info thread
|
||||
Id Target Id Frame
|
||||
* 1 Thread 0x7ffff64c5880 (LWP 146060) "hipMemcpy_simpl" 0x000000000020f78e in simpleTest2<float> (numElements=4194304, usePinnedHost=true)
|
||||
at /home/test/hip/tests/src/runtimeApi/memory/hipMemcpy_simple.cpp:104
|
||||
2 Thread 0x7ffff64c4700 (LWP 146066) "hipMemcpy_simpl" 0x00007ffff6b0850b in ioctl
|
||||
() from /lib/x86_64-linux-gnu/libc.so.6
|
||||
#0 hipMalloc<int> (devPtr=0x7fffffffe098, size=4096) at /opt/rocm/include/hip/hip_runtime_api.h:8487
|
||||
#1 main () at app.cpp:14
|
||||
|
||||
(gdb) n
|
||||
[New Thread 0x7fffeb7ff640 (LWP 1524879)]
|
||||
[New Thread 0x7fffeaffe640 (LWP 1524880)]
|
||||
[Thread 0x7fffeaffe640 (LWP 1524880) exited]
|
||||
main () at app.cpp:15
|
||||
15 hipMemset(ptr, 0, sizeof(int) * size);
|
||||
|
||||
(gdb) info threads
|
||||
Id Target Id Frame
|
||||
* 1 Thread 0x7ffff7e6ba80 (LWP 1524135) "app" main () at app.cpp:15
|
||||
2 Thread 0x7fffeb7ff640 (LWP 1524879) "app" __GI___ioctl (fd=3, request=3222817548) at ../sysdeps/unix/sysv/linux/ioctl.c:36
|
||||
|
||||
(gdb) thread 2
|
||||
[Switching to thread 2 (Thread 0x7ffff64c4700 (LWP 146066))]
|
||||
#0 0x00007ffff6b0850b in ioctl () from /lib/x86_64-linux-gnu/libc.so.6
|
||||
[Switching to thread 2 (Thread 0x7fffeb7ff640 (LWP 1524879))]
|
||||
#0 __GI___ioctl (fd=3, request=3222817548) at ../sysdeps/unix/sysv/linux/ioctl.c:36
|
||||
36 ../sysdeps/unix/sysv/linux/ioctl.c: No such file or directory.
|
||||
|
||||
(gdb) bt
|
||||
#0 0x00007ffff6b0850b in ioctl () from /lib/x86_64-linux-gnu/libc.so.6
|
||||
#1 0x00007ffff6604568 in ?? () from /opt/rocm/lib/libhsa-runtime64.so.1
|
||||
#2 0x00007ffff65fe73a in ?? () from /opt/rocm/lib/libhsa-runtime64.so.1
|
||||
#3 0x00007ffff659e4d6 in ?? () from /opt/rocm/lib/libhsa-runtime64.so.1
|
||||
#4 0x00007ffff65807de in ?? () from /opt/rocm/lib/libhsa-runtime64.so.1
|
||||
#5 0x00007ffff65932a2 in ?? () from /opt/rocm/lib/libhsa-runtime64.so.1
|
||||
#6 0x00007ffff654f547 in ?? () from /opt/rocm/lib/libhsa-runtime64.so.1
|
||||
#7 0x00007ffff7f76609 in start_thread () from /lib/x86_64-linux-gnu/libpthread.so.0
|
||||
#8 0x00007ffff6b13293 in clone () from /lib/x86_64-linux-gnu/libc.so.6
|
||||
(gdb) thread 1
|
||||
[Switching to thread 1 (Thread 0x7ffff64c5880 (LWP 146060))]
|
||||
#0 0x000000000020f78e in simpleTest2<float> (numElements=4194304, usePinnedHost=true)
|
||||
at /home/test/hip/tests/src/runtimeApi/memory/hipMemcpy_simple.cpp:104
|
||||
104 A_h1[i] = 3.14f + 1000 * i;
|
||||
(gdb) bt
|
||||
#0 0x000000000020f78e in simpleTest2<float> (numElements=4194304, usePinnedHost=true)
|
||||
at /home/test/hip/tests/src/runtimeApi/memory/hipMemcpy_simple.cpp:104
|
||||
#1 0x000000000020e96c in main (argc=<optimized out>, argv=<optimized out>)
|
||||
at /home/test/hip/tests/src/runtimeApi/memory/hipMemcpy_simple.cpp:163
|
||||
(gdb)
|
||||
#0 __GI___ioctl (fd=3, request=3222817548) at ../sysdeps/unix/sysv/linux/ioctl.c:36
|
||||
#1 0x00007fffeb8fda80 in ?? () from /opt/rocm/lib/libhsa-runtime64.so.1
|
||||
#2 0x00007fffeb8f6912 in ?? () from /opt/rocm/lib/libhsa-runtime64.so.1
|
||||
#3 0x00007fffeb883021 in ?? () from /opt/rocm/lib/libhsa-runtime64.so.1
|
||||
#4 0x00007fffeb85e026 in ?? () from /opt/rocm/lib/libhsa-runtime64.so.1
|
||||
#5 0x00007fffeb874b6a in ?? () from /opt/rocm/lib/libhsa-runtime64.so.1
|
||||
#6 0x00007fffeb828fdb in ?? () from /opt/rocm/lib/libhsa-runtime64.so.1
|
||||
#7 0x00007ffff5c94b43 in start_thread (arg=<optimised out>) at ./nptl/pthread_create.c:442
|
||||
#8 0x00007ffff5d26a00 in clone3 () at ../sysdeps/unix/sysv/linux/x86_64/clone3.S:81
|
||||
...
|
||||
```
|
||||
|
||||
A complete guide to `rocgdb` can be found [here](https://rocm.docs.amd.com/projects/ROCgdb/en/latest/).
|
||||
|
||||
On Windows, debugging HIP applications on IDE like Microsoft Visual Studio tools, are more informative and visible to debug codes, inspect variables, watch multiple details and examine the call stacks.
|
||||
|
||||
## Useful Environment Variables
|
||||
|
||||
@@ -93,7 +93,6 @@ else {
|
||||
}
|
||||
```
|
||||
Please note, the managed memory capability check may not be necessary, but if HMM is not supported, then managed malloc will fall back to using system memory and other managed memory API calls will have undefined behavior.
|
||||
For more details on managed memory APIs, please refer to the documentation HIP-API.pdf, and the application at (https://github.com/ROCm-Developer-Tools/HIP/blob/rocm-4.5.x/tests/src/runtimeApi/memory/hipMallocManaged.cpp) is a sample usage.
|
||||
|
||||
Note, managed memory management is implemented on Linux, not supported on Windows yet.
|
||||
|
||||
@@ -139,8 +138,6 @@ HIP graph is supported. For more details, refer to the HIP API Guide.
|
||||
HIP-Clang now supports device-side malloc and free.
|
||||
This implementation does not require the use of `hipDeviceSetLimit(hipLimitMallocHeapSize,value)` nor respects any setting. The heap is fully dynamic and can grow until the available free memory on the device is consumed.
|
||||
|
||||
The test codes in the link (https://github.com/ROCm-Developer-Tools/HIP/blob/develop/tests/src/deviceLib/hipDeviceMalloc.cpp) show how to implement application using malloc and free functions in device kernels.
|
||||
|
||||
## Use of Per-thread default stream
|
||||
|
||||
The per-thread default stream is supported in HIP. It is an implicit stream local to both the thread and the current device. This means that the command issued to the per-thread default stream by the thread does not implicitly synchronize with other streams (like explicitly created streams), or default per-thread stream on other threads.
|
||||
|
||||
@@ -133,9 +133,6 @@ extern "C" hipError_t hipExtLaunchKernel(const void* function_address, dim3 numB
|
||||
* launched in any order.
|
||||
* @param [in] args templated kernel arguments.
|
||||
*
|
||||
*
|
||||
* Please refer to the application for sample usage at,
|
||||
* (https://github.com/ROCm-Developer-Tools/HIP/blob/rocm-4.5.x/tests/src/kernel/hipExtLaunchKernelGGL.cpp).
|
||||
*/
|
||||
template <typename... Args, typename F = void (*)(Args...)>
|
||||
inline void hipExtLaunchKernelGGL(F kernel, const dim3& numBlocks, const dim3& dimBlocks,
|
||||
|
||||
@@ -1,185 +0,0 @@
|
||||
# HIP testing environment.
|
||||
|
||||
This document explains how to use the HIP CMAKE testing environment.
|
||||
We make use of the HIT Integrated Tester (HIT) framework to automatically find and add test cases to the CMAKE testing environment.
|
||||
|
||||
### Quickstart
|
||||
|
||||
HIP unit tests are integrated into the top-level cmake project. The tests depend upon the installed version of HIP.
|
||||
Typical usage (paths relative to top of the HIP repo):
|
||||
```
|
||||
$ mkdir build
|
||||
$ cd build
|
||||
$ cmake .. -DCMAKE_INSTALL_PREFIX=$PWD/install
|
||||
$ make
|
||||
$ make install
|
||||
$ make build_tests
|
||||
$ make test
|
||||
```
|
||||
|
||||
### How to add a new test
|
||||
|
||||
The test infrastructure use a hierarchy of folders. So add the new test to the appropriate folder.
|
||||
The tests/src/runtimeApi/memory/hipMemset.cpp file contains a simple unit test and is a good starting point for other tests.
|
||||
Copy this to a new test name and modify it.
|
||||
|
||||
|
||||
### HIP Integrated Tester (HIT)
|
||||
|
||||
The HIT framework automatically finds and adds test cases to the CMAKE testing environment. It achives this by parsing all files in the tests/src folder.
|
||||
The parser looks for a code block similar to the one below.
|
||||
```
|
||||
/* HIT_START
|
||||
* BUILD: %t %s ../../test_common.cpp
|
||||
* TEST: %t
|
||||
* //Small copy
|
||||
* TEST: %t -N 10 --memsetval 0x42
|
||||
* // Oddball size
|
||||
* TEST: %t -N 10013 --memsetval 0x5a
|
||||
* // Big copy
|
||||
* TEST: %t -N 256M --memsetval 0xa6
|
||||
* HIT_END
|
||||
*/
|
||||
```
|
||||
In the above, BUILD commands provide instructions on how to build the test case while TEST commands provide instructions on how to execute the test case.
|
||||
|
||||
#### BUILD command
|
||||
|
||||
The supported syntax for the BUILD command is:
|
||||
```
|
||||
BUILD: %t %s HIPCC_OPTIONS <hipcc_specific_options> CLANG_OPTIONS <clang_specific_options> NVCC_OPTIONS <nvcc_specific_options> EXCLUDE_HIP_PLATFORM <amd|nvidia|all> EXCLUDE_HIP_RUNTIME <rocclr> EXCLUDE_HIP_COMPILER <clang> DEPENDS EXCLUDE_HIP_LIB_TYPE <static|shared> <dependencies>
|
||||
```
|
||||
%s: refers to current source file name. Additional source files needed for the test can be specified by name (including relative path).
|
||||
%t: refers to target executable named derived by removing the extension from the current source file. Alternatively a target executable name can be specified.
|
||||
HIPCC_OPTIONS: All options specified after this delimiter are passed to hipcc on both amd and nvidia platforms.
|
||||
CLANG_OPTIONS: All options specified after this delimiter are passed to hipcc on HIP-Clang compiler only.
|
||||
NVCC_OPTIONS: All options specified after this delimiter are passed to hipcc on nvidia platform only.
|
||||
EXCLUDE_HIP_PLATFORM: This can be used to exclude a test case from amd, nvidia or both platforms.
|
||||
EXCLUDE_HIP_RUNTIME: This can be used to exclude a test case from rocclr runtime.
|
||||
EXCLUDE_HIP_COMPILER: This can be used to exclude a test case from clang compiler.
|
||||
EXCLUDE_HIP_RUNTIME AND EXCLUDE_HIP_COMPILER: when both options are specified it excludes test case from particular runtime and compiler.
|
||||
EXCLUDE_HIP_LIB_TYPE: This can be used to exclude a test case from static or shared libs.
|
||||
DEPENDS: This can be used to specify dependencies that need to be built before building the current target.
|
||||
|
||||
|
||||
#### BUILD_CMD command
|
||||
|
||||
The supported syntax for the BUILD_CMD command is:
|
||||
```
|
||||
BUILD_CMD: <targetname> <build_command> EXCLUDE_HIP_PLATFORM <amd|nvidia|all> EXCLUDE_HIP_RUNTIME <rocclr> EXCLUDE_HIP_COMPILER <clang> EXCLUDE_HIP_LIB_TYPE <static|shared> DEPENDS <dependencies>
|
||||
```
|
||||
%s: refers to current source file name. Additional source files needed for the test can be specified by name (including relative path).
|
||||
%t: refers to target executable named derived by removing the extension from the current source file. Alternatively a target executable name can be specified.
|
||||
%hc: refers to hipcc pointed to by $CMAKE_INSTALL_PREFIX/bin/hipcc.
|
||||
%hip-path: refers to hip installed location pointed to by $CMAKE_INSTALL_PREFIX
|
||||
%cc: refers to system c compiler pointed to by /usr/bin/cc.
|
||||
%cxx: refers to system c compiler pointed to by /usr/bin/c++.
|
||||
%S: refers to path to current source file.
|
||||
%T: refers to path to current build target.
|
||||
EXCLUDE_HIP_PLATFORM: This can be used to exclude a test case from amd, nvidia or both platforms.
|
||||
EXCLUDE_HIP_RUNTIME: This can be used to exclude a test case from rocclr runtime.
|
||||
EXCLUDE_HIP_COMPILER: This can be used to exclude a test case from clang compiler.
|
||||
EXCLUDE_HIP_RUNTIME AND EXCLUDE_HIP_COMPILER: when both options are specified it excludes test from particular runtime and compiler.
|
||||
EXCLUDE_HIP_LIB_TYPE: This can be used to exclude a test case from static or shared libs.
|
||||
DEPENDS: This can be used to specify dependencies that need to be built before building the current target.
|
||||
|
||||
|
||||
#### TEST command
|
||||
|
||||
The supported syntax for the TEST command is:
|
||||
```
|
||||
TEST: %t <arguments_to_test_executable> EXCLUDE_HIP_PLATFORM <amd|nvidia|all> EXCLUDE_HIP_RUNTIME <rocclr> EXCLUDE_HIP_COMPILER <clang> EXCLUDE_HIP_LIB_TYPE <static|shared>
|
||||
```
|
||||
%t: refers to target executable named derived by removing the extension from the current source file. Alternatively a target executable name can be specified.
|
||||
EXCLUDE_HIP_PLATFORM: This can be used to exclude a test case from amd, nvidia or both platforms.
|
||||
EXCLUDE_HIP_RUNTIME: This can be used to exclude a test case from rocclr runtime.
|
||||
EXCLUDE_HIP_COMPILER: This can be used to exclude a test case from clang compiler.
|
||||
EXCLUDE_HIP_RUNTIME AND EXCLUDE_HIP_COMPILER: when both options are specified it excludes test from particular runtime and compiler.
|
||||
EXCLUDE_HIP_LIB_TYPE: This can be used to exclude a test case from static or shared libs.
|
||||
|
||||
Note that if the test has been excluded for a specific platform/runtime/compiler in the BUILD command, it is automatically excluded from the TEST command as well for the sameplatform.
|
||||
|
||||
#### TEST_NAMED command
|
||||
|
||||
When using the TEST command, HIT will squash and append the arguments specified to the test executable name to generate the CMAKE test name. Sometimes we might want to specify a more descriptive name. The TEST_NAMED command is used for that. The supported syntax for the TEST_NAMED command is:
|
||||
```
|
||||
TEST: %t CMAKE_TEST_NAME <arguments_to_test_executable> EXCLUDE_HIP_PLATFORM <amd|nvidia|all> EXCLUDE_HIP_RUNTIME <rocclr> EXCLUDE_HIP_COMPILER <clang> EXCLUDE_HIP_LIB_TYPE <static|shared>
|
||||
```
|
||||
|
||||
|
||||
### Running tests:
|
||||
```
|
||||
ctest
|
||||
```
|
||||
|
||||
### Run subsets of all tests:
|
||||
```
|
||||
# Run one test on the commandline
|
||||
./directed_tests/runtime/memory/hipMemset
|
||||
|
||||
# Run all the hipMemcpy tests:
|
||||
ctest -R Memcpy
|
||||
|
||||
# Run all tests in a specific folder:
|
||||
ctest -R memory
|
||||
```
|
||||
|
||||
### Performance tests:
|
||||
```
|
||||
Above tests are direct tests which are majorly used for function verification.
|
||||
We also provide performance tests under tests/performance folder.
|
||||
|
||||
# Build all performance tests after running "make install" under build folder:
|
||||
make build_perf
|
||||
|
||||
Then all performance test applications will be built into ./performance_tests folder.
|
||||
|
||||
# Run all performance tests:
|
||||
make perf
|
||||
|
||||
# Run individual performance test:
|
||||
For example,
|
||||
performance_tests/memory/hipPerfMemMallocCpyFree
|
||||
|
||||
# Run a specific test set:
|
||||
For example,
|
||||
/usr/bin/ctest -C performance -R performance_tests/perfDispatch --verbose
|
||||
Here "-C performance" indicate the "performance" configuration of ctest.
|
||||
```
|
||||
|
||||
### RTC Testing
|
||||
|
||||
To enable RTC testing, cmake needs to be passed the `-DRTC_TESTING=1` option.
|
||||
|
||||
When this option is passed, all tests that support this functionality will be run using HIP RTC to compile and run.
|
||||
|
||||
To enable HIP RTC support for a specific test:
|
||||
|
||||
1. Move all its kernels to `tests/catch/kernels` (one file per kernel):
|
||||
1. Kernel **functions** should use the file extension `.cpp` and include `kernels.hh`
|
||||
2. Kernel **templates** should use the file extension `.inl`
|
||||
2. Update `tests/catch/kernels/CMakeLists.txt` (i.e. add the new kernel **functions** to `TEST_SRC`)
|
||||
3. Update `tests/catch/include/kernels.hh`:
|
||||
1. Declare the new kernel **functions**
|
||||
2. Include the new .inl files that contain kernel **templates**
|
||||
3. Call the `FUNCTION_WRAPPER` and `TEMPLATE_WRAPPER` macros for each new function and template respectively.
|
||||
4. Update `tests/catch/include/kernel_mapping.hh` with the mapping between the new files and respective function / template names.
|
||||
5. Include `kernels.hh`
|
||||
6. Call the `hipTest::launchKernel()` function instead of `hipLaunchKernelGGL()`
|
||||
|
||||
**Note:** HIP RTC does not do implicit casting of kernel parameters. This **requires** the test writer to explicitly do all the casting before running the kernel. There is a `static_assert` inside `hipTest::launchKernel()` that checks that this was done correctly. However, due to limitations, the assertion is only performed when `-DRTC_TESTING` option is **disabled**. This means that runtime errors can occur if the casts are not performed correctly and `-DRTC_TESTING` is enabled.
|
||||
|
||||
### If a test fails - how to debug a test
|
||||
|
||||
Find the test and commandline that fail:
|
||||
|
||||
(From the build directory, perhaps hip/build)
|
||||
grep -IR hipMemcpy-modes -IR ../tests/
|
||||
../tests/src/runtimeApi/memory/hipMemcpy.cpp: * TEST_NAMED: %t hipMemcpy-modes --tests 0x1
|
||||
|
||||
# Guidelines for adding new tests
|
||||
|
||||
- Prefer to enhance an existing test as opposed to writing a new one. Tests have overhead to start and many small tests spend precious test time on startup and initialization issues.
|
||||
- Make the test run standalone without requirement for command-line arguments. THis makes it easier to debug since the name of the test is shown in the test report and if you know the name of the test you can the run the test.
|
||||
- For long-running tests or tests with multiple phases, consider using the --tests option as an optional mechanism to allow debuggers to start with the failing subset of the test.
|
||||
|
||||
@@ -1,52 +0,0 @@
|
||||
# Copyright (c) 2020 - 2021 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:
|
||||
#
|
||||
# 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.
|
||||
|
||||
###############################################################################
|
||||
# Tests.cmake
|
||||
###############################################################################
|
||||
|
||||
# Add tests
|
||||
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)
|
||||
include_directories(${CMAKE_CURRENT_LIST_DIR}/src)
|
||||
hit_add_directory_recursive(${HIP_CTEST_CONFIG_DEFAULT} ${CMAKE_CURRENT_LIST_DIR}/src "directed_tests")
|
||||
|
||||
# Add unit tests
|
||||
include_directories(${CMAKE_CURRENT_LIST_DIR}/unit)
|
||||
hit_add_directory_recursive(${HIP_CTEST_CONFIG_DEFAULT} ${CMAKE_CURRENT_LIST_DIR}/unit "unit_tests")
|
||||
|
||||
# Add performance tests
|
||||
include_directories(${CMAKE_CURRENT_LIST_DIR}/performance)
|
||||
hit_add_directory_recursive(${HIP_CTEST_CONFIG_PERFORMANCE} ${CMAKE_CURRENT_LIST_DIR}/performance "performance_tests")
|
||||
|
||||
# Add top-level tests to build_tests
|
||||
add_custom_target(build_tests DEPENDS directed_tests unit_tests)
|
||||
|
||||
# Add top-level tests to build performance_tests.
|
||||
# To build performance tests, just run "make build_perf"
|
||||
add_custom_target(build_perf DEPENDS performance_tests)
|
||||
|
||||
# Add custom target: perf.
|
||||
# To run performance tests, just run "make perf"
|
||||
add_custom_target(perf COMMAND "${CMAKE_CTEST_COMMAND}" -C "${HIP_CTEST_CONFIG_PERFORMANCE}" -R "performance_tests/" --verbose)
|
||||
|
||||
# Add custom target: check
|
||||
add_custom_target(check COMMAND "${CMAKE_COMMAND}" --build . --target test DEPENDS build_tests)
|
||||
|
||||
# vim: ts=4:sw=4:expandtab:smartindent
|
||||
@@ -1,506 +0,0 @@
|
||||
# Copyright (c) 2016 - 2021 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:
|
||||
#
|
||||
# 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.
|
||||
|
||||
include(CTest)
|
||||
find_package(HIP REQUIRED)
|
||||
|
||||
set(HIP_CTEST_CONFIG_DEFAULT "default")
|
||||
set(HIP_CTEST_CONFIG_PERFORMANCE "performance")
|
||||
set(HIP_LIB_TYPE "shared")
|
||||
if (NOT ${BUILD_SHARED_LIBS})
|
||||
set(HIP_LIB_TYPE "static")
|
||||
endif()
|
||||
message(STATUS "HIP runtime lib type - ${HIP_LIB_TYPE}")
|
||||
message(STATUS "CMAKE_TESTING_TOOL: ${CMAKE_TESTING_TOOL}")
|
||||
|
||||
# Turn off CMAKE_HIP_ARCHITECTURES Feature if cmake version is 3.21+
|
||||
if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.21.0)
|
||||
set(CMAKE_HIP_ARCHITECTURES OFF)
|
||||
endif()
|
||||
message(STATUS "CMAKE HIP ARCHITECTURES: ${CMAKE_HIP_ARCHITECTURES}")
|
||||
|
||||
# Identify the GPU Targets.
|
||||
# This is done due to limitation of rocm_agent_enumerator
|
||||
# While building test parallelly, rocm_agent_enumerator can fail and give out an empty target
|
||||
# That results in hipcc building the test for gfx803 (the default target)
|
||||
if(NOT DEFINED OFFLOAD_ARCH_STR AND EXISTS "${ROCM_PATH}/bin/rocm_agent_enumerator"
|
||||
AND HIP_PLATFORM STREQUAL "amd" AND UNIX)
|
||||
execute_process(COMMAND ${ROCM_PATH}/bin/rocm_agent_enumerator OUTPUT_VARIABLE HIP_GPU_ARCH
|
||||
RESULT_VARIABLE ROCM_AGENT_ENUM_RESULT)
|
||||
message(STATUS "ROCm Agent Enumurator Result: ${ROCM_AGENT_ENUM_RESULT}")
|
||||
# Trim out gfx000
|
||||
string(REPLACE "gfx000\n" "" HIP_GPU_ARCH ${HIP_GPU_ARCH})
|
||||
if (NOT HIP_GPU_ARCH STREQUAL "")
|
||||
string(LENGTH ${HIP_GPU_ARCH} HIP_GPU_ARCH_LEN)
|
||||
# If string has more gfx target except gfx000
|
||||
if(${HIP_GPU_ARCH_LEN} GREATER_EQUAL 1)
|
||||
string(REGEX REPLACE "\n" ";" HIP_GPU_ARCH_LIST "${HIP_GPU_ARCH}")
|
||||
set(OFFLOAD_ARCH_STR "")
|
||||
foreach(_hip_gpu_arch ${HIP_GPU_ARCH_LIST})
|
||||
set(OFFLOAD_ARCH_STR " ${OFFLOAD_ARCH_STR} --offload-arch=${_hip_gpu_arch} ")
|
||||
endforeach()
|
||||
message(STATUS "Using offload arch string: ${OFFLOAD_ARCH_STR}")
|
||||
endif()
|
||||
else()
|
||||
message(STATUS "ROCm Agent Enumurator found no valid architectures")
|
||||
endif()
|
||||
else()
|
||||
message(STATUS "ROCm Agent Enumurator Not Found")
|
||||
endif()
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Helper macro to parse BUILD instructions
|
||||
macro(PARSE_BUILD_COMMAND _target _sources _hipcc_options _clang_options _nvcc_options _link_options _exclude_platforms _exclude_runtime _exclude_compiler _exclude_lib_type _depends _dir)
|
||||
set(${_target})
|
||||
set(${_sources})
|
||||
if(DEFINED OFFLOAD_ARCH_STR)
|
||||
set(${_hipcc_options} "${OFFLOAD_ARCH_STR}")
|
||||
else()
|
||||
set(${_hipcc_options})
|
||||
endif()
|
||||
set(${_clang_options})
|
||||
set(${_nvcc_options})
|
||||
set(${_link_options})
|
||||
set(${_exclude_platforms})
|
||||
set(${_exclude_runtime})
|
||||
set(${_exclude_compiler})
|
||||
set(${_exclude_lib_type})
|
||||
set(${_depends})
|
||||
|
||||
set(_target_found FALSE)
|
||||
set(_flag "")
|
||||
|
||||
foreach(arg ${ARGN})
|
||||
if(NOT _target_found)
|
||||
set(_target_found TRUE)
|
||||
set(${_target} ${arg})
|
||||
elseif("x${arg}" STREQUAL "xHIPCC_OPTIONS"
|
||||
OR "x${arg}" STREQUAL "xCLANG_OPTIONS"
|
||||
OR "x${arg}" STREQUAL "xNVCC_OPTIONS"
|
||||
OR "x${arg}" STREQUAL "xLINK_OPTIONS"
|
||||
OR "x${arg}" STREQUAL "xEXCLUDE_HIP_PLATFORM"
|
||||
OR "x${arg}" STREQUAL "xEXCLUDE_HIP_RUNTIME"
|
||||
OR "x${arg}" STREQUAL "xEXCLUDE_HIP_COMPILER"
|
||||
OR "x${arg}" STREQUAL "xEXCLUDE_HIP_LIB_TYPE"
|
||||
OR "x${arg}" STREQUAL "xDEPENDS")
|
||||
set(_flag ${arg})
|
||||
elseif("x${_flag}" STREQUAL "xHIPCC_OPTIONS")
|
||||
list(APPEND ${_hipcc_options} ${arg})
|
||||
elseif("x${_flag}" STREQUAL "xCLANG_OPTIONS")
|
||||
list(APPEND ${_clang_options} ${arg})
|
||||
elseif("x${_flag}" STREQUAL "xNVCC_OPTIONS")
|
||||
list(APPEND ${_nvcc_options} ${arg})
|
||||
elseif("x${_flag}" STREQUAL "xLINK_OPTIONS")
|
||||
list(APPEND ${_link_options} ${arg})
|
||||
elseif("x${_flag}" STREQUAL "xEXCLUDE_HIP_PLATFORM")
|
||||
list(APPEND ${_exclude_platforms} ${arg})
|
||||
elseif("x${_flag}" STREQUAL "xEXCLUDE_HIP_RUNTIME")
|
||||
list(APPEND ${_exclude_runtime} ${arg})
|
||||
elseif("x${_flag}" STREQUAL "xEXCLUDE_HIP_COMPILER")
|
||||
list(APPEND ${_exclude_compiler} ${arg})
|
||||
elseif("x${_flag}" STREQUAL "xEXCLUDE_HIP_LIB_TYPE")
|
||||
list(APPEND ${_exclude_lib_type} ${arg})
|
||||
elseif("x${_flag}" STREQUAL "xDEPENDS")
|
||||
list(APPEND ${_depends} ${arg})
|
||||
else()
|
||||
list(APPEND ${_sources} "${_dir}/${arg}")
|
||||
endif()
|
||||
endforeach()
|
||||
endmacro()
|
||||
|
||||
# Helper macro to parse CUSTOM BUILD instructions
|
||||
macro(PARSE_CUSTOMBUILD_COMMAND _target _buildcmd _exclude_platforms _exclude_runtime _exclude_compiler _exclude_lib_type _depends)
|
||||
set(${_target})
|
||||
set(${_buildcmd})
|
||||
set(${_exclude_platforms})
|
||||
set(${_exclude_runtime})
|
||||
set(${_exclude_compiler})
|
||||
set(${_exclude_lib_type})
|
||||
set(${_depends})
|
||||
|
||||
set(_target_found FALSE)
|
||||
set(_flag "")
|
||||
|
||||
foreach(arg ${ARGN})
|
||||
if(NOT _target_found)
|
||||
set(_target_found TRUE)
|
||||
set(${_target} ${arg})
|
||||
elseif("x${arg}" STREQUAL "xEXCLUDE_HIP_PLATFORM"
|
||||
OR "x${arg}" STREQUAL "xEXCLUDE_HIP_RUNTIME"
|
||||
OR "x${arg}" STREQUAL "xEXCLUDE_HIP_COMPILER"
|
||||
OR "x${arg}" STREQUAL "xEXCLUDE_HIP_LIB_TYPE"
|
||||
OR "x${arg}" STREQUAL "xDEPENDS")
|
||||
set(_flag ${arg})
|
||||
elseif("x${_flag}" STREQUAL "xEXCLUDE_HIP_PLATFORM")
|
||||
list(APPEND ${_exclude_platforms} ${arg})
|
||||
elseif("x${_flag}" STREQUAL "xEXCLUDE_HIP_RUNTIME")
|
||||
list(APPEND ${_exclude_runtime} ${arg})
|
||||
elseif("x${_flag}" STREQUAL "xEXCLUDE_HIP_COMPILER")
|
||||
list(APPEND ${_exclude_compiler} ${arg})
|
||||
elseif("x${_flag}" STREQUAL "xEXCLUDE_HIP_LIB_TYPE")
|
||||
list(APPEND ${_exclude_lib_type} ${arg})
|
||||
elseif("x${_flag}" STREQUAL "xDEPENDS")
|
||||
list(APPEND ${_depends} ${arg})
|
||||
else()
|
||||
list(APPEND ${_buildcmd} ${arg}) # always before exclude lists
|
||||
endif()
|
||||
endforeach()
|
||||
endmacro()
|
||||
|
||||
# Helper macro to parse command part of CUSTOM BUILD instructions
|
||||
macro(PARSE_CUSTOMBUILD_COMMAND_PART _compiler _target _target_type _sources _options)
|
||||
set(${_compiler})
|
||||
set(${_target})
|
||||
set(${_target_type} "EXECUTABLE")
|
||||
set(${_sources})
|
||||
set(${_options})
|
||||
set(_compiler_found FALSE)
|
||||
set(_target_found FALSE)
|
||||
|
||||
foreach(arg ${ARGN})
|
||||
if(NOT _compiler_found)
|
||||
set(_compiler_found TRUE)
|
||||
set(${_compiler} ${arg})
|
||||
elseif("x${arg}" STREQUAL "x-o")
|
||||
set(_target_found TRUE)
|
||||
elseif(_target_found)
|
||||
set(${_target} ${arg})
|
||||
set(_target_found FALSE)
|
||||
elseif("x${arg}" STREQUAL "x-c" OR "x${arg}" STREQUAL "x--genco")
|
||||
set(${_target_type} "OBJECT")
|
||||
list(APPEND ${_options} ${arg})
|
||||
elseif("x${arg}" STREQUAL "x-shared")
|
||||
# Note: Currently all directed_tests are linux based.
|
||||
set(${_target_type} "SHARED")
|
||||
list(APPEND ${_options} ${arg})
|
||||
elseif("x${arg}" MATCHES "^x-I")
|
||||
# -I
|
||||
list(APPEND ${_options} ${arg})
|
||||
elseif("x${arg}" MATCHES "^x.*\.cpp$")
|
||||
# cpp file
|
||||
list(APPEND ${_sources} ${arg})
|
||||
elseif("x${arg}" MATCHES "^x.*\.c$")
|
||||
# c file
|
||||
list(APPEND ${_sources} ${arg})
|
||||
else()
|
||||
list(APPEND ${_options} ${arg})
|
||||
endif()
|
||||
endforeach()
|
||||
endmacro()
|
||||
|
||||
# Helper macro to parse TEST instructions
|
||||
macro(PARSE_TEST_COMMAND _target _arguments _exclude_platforms _exclude_runtime _exclude_compiler _exclude_lib_type)
|
||||
set(${_target})
|
||||
set(${_arguments} " ")
|
||||
set(${_exclude_platforms})
|
||||
set(${_exclude_runtime})
|
||||
set(${_exclude_compiler})
|
||||
set(${_exclude_lib_type})
|
||||
|
||||
set(_target_found FALSE)
|
||||
set(_flag "")
|
||||
|
||||
foreach(arg ${ARGN})
|
||||
if(NOT _target_found)
|
||||
set(_target_found TRUE)
|
||||
set(${_target} ${arg})
|
||||
elseif("x${arg}" STREQUAL "xEXCLUDE_HIP_PLATFORM"
|
||||
OR "x${arg}" STREQUAL "xEXCLUDE_HIP_RUNTIME"
|
||||
OR "x${arg}" STREQUAL "xEXCLUDE_HIP_COMPILER"
|
||||
OR "x${arg}" STREQUAL "xEXCLUDE_HIP_LIB_TYPE")
|
||||
set(_flag ${arg})
|
||||
elseif("x${_flag}" STREQUAL "xEXCLUDE_HIP_PLATFORM")
|
||||
list(APPEND ${_exclude_platforms} ${arg})
|
||||
elseif("x${_flag}" STREQUAL "xEXCLUDE_HIP_RUNTIME")
|
||||
list(APPEND ${_exclude_runtime} ${arg})
|
||||
elseif("x${_flag}" STREQUAL "xEXCLUDE_HIP_COMPILER")
|
||||
list(APPEND ${_exclude_compiler} ${arg})
|
||||
elseif("x${_flag}" STREQUAL "xEXCLUDE_HIP_LIB_TYPE")
|
||||
list(APPEND ${_exclude_lib_type} ${arg})
|
||||
else()
|
||||
list(APPEND ${_arguments} ${arg}) # always before exclude lists
|
||||
endif()
|
||||
endforeach()
|
||||
endmacro()
|
||||
|
||||
# Helper macro to parse TEST_NAMED instructions
|
||||
macro(PARSE_TEST_NAMED_COMMAND _target _testname _arguments _exclude_platforms _exclude_runtime _exclude_compiler _exclude_lib_type)
|
||||
set(${_target})
|
||||
set(${_arguments} " ")
|
||||
set(${_exclude_platforms})
|
||||
set(${_exclude_runtime})
|
||||
set(${_exclude_compiler})
|
||||
set(${_exclude_lib_type})
|
||||
|
||||
set(_target_found FALSE)
|
||||
set(_testname_found FALSE)
|
||||
set(_flag "")
|
||||
|
||||
foreach(arg ${ARGN})
|
||||
if(NOT _target_found)
|
||||
set(_target_found TRUE)
|
||||
set(${_target} ${arg})
|
||||
elseif(NOT _testname_found)
|
||||
set(_testname_found TRUE)
|
||||
set(${_testname} ${arg})
|
||||
elseif("x${arg}" STREQUAL "xEXCLUDE_HIP_PLATFORM"
|
||||
OR "x${arg}" STREQUAL "xEXCLUDE_HIP_RUNTIME"
|
||||
OR "x${arg}" STREQUAL "xEXCLUDE_HIP_COMPILER"
|
||||
OR "x${arg}" STREQUAL "xEXCLUDE_HIP_LIB_TYPE")
|
||||
set(_flag ${arg})
|
||||
elseif("x${_flag}" STREQUAL "xEXCLUDE_HIP_PLATFORM")
|
||||
list(APPEND ${_exclude_platforms} ${arg})
|
||||
elseif("x${_flag}" STREQUAL "xEXCLUDE_HIP_RUNTIME")
|
||||
list(APPEND ${_exclude_runtime} ${arg})
|
||||
elseif("x${_flag}" STREQUAL "xEXCLUDE_HIP_COMPILER")
|
||||
list(APPEND ${_exclude_compiler} ${arg})
|
||||
elseif("x${_flag}" STREQUAL "xEXCLUDE_HIP_LIB_TYPE")
|
||||
list(APPEND ${_exclude_lib_type} ${arg})
|
||||
else()
|
||||
list(APPEND ${_arguments} ${arg}) # always before exclude lists
|
||||
endif()
|
||||
endforeach()
|
||||
endmacro()
|
||||
|
||||
# Helper macro to insert key/value pair into "hashmap"
|
||||
macro(INSERT_INTO_MAP _map _key _value)
|
||||
set("${_map}_${_key}" "${_value}")
|
||||
endmacro()
|
||||
|
||||
# Helper macro to read key/value pair from "hashmap"
|
||||
macro(READ_FROM_MAP _map _key _value)
|
||||
set(${_value} "${${_map}_${_key}}")
|
||||
endmacro()
|
||||
|
||||
|
||||
# Helper macro to generate a test
|
||||
macro(GENERATE_TEST _config testname cmdline)
|
||||
set(TEST_CMD_LINE ${cmdline} ${ARGN})
|
||||
if(${_config} STREQUAL ${HIP_CTEST_CONFIG_DEFAULT})
|
||||
add_test(NAME ${testname} COMMAND ${TEST_CMD_LINE})
|
||||
else()
|
||||
add_test(NAME ${testname} CONFIGURATIONS ${_config} COMMAND ${TEST_CMD_LINE})
|
||||
endif()
|
||||
set_tests_properties(${testname} PROPERTIES PASS_REGULAR_EXPRESSION "PASSED" ENVIRONMENT HIP_PATH=${HIP_ROOT_DIR})
|
||||
set_tests_properties(${testname} PROPERTIES SKIP_RETURN_CODE 127 ENVIRONMENT HIP_PATH=${HIP_ROOT_DIR})
|
||||
endmacro()
|
||||
|
||||
# Helper macro to create a test
|
||||
macro(MAKE_NAMED_TEST _config exe testname)
|
||||
# to generate hip original test
|
||||
set(TEST_CMD_LINE ${PROJECT_BINARY_DIR}/${exe} ${ARGN})
|
||||
generate_test(${_config} ${testname} ${TEST_CMD_LINE})
|
||||
|
||||
# to generate test with tool enabled
|
||||
if(DEFINED CMAKE_TESTING_TOOL)
|
||||
# arguments passing to the testing tool
|
||||
# <source dir>, <build dir>, <test name>, <test args...>
|
||||
set(TOOL_CMD_LINE ${CMAKE_TESTING_TOOL} ${PROJECT_SOURCE_DIR} ${PROJECT_BINARY_DIR} ${TEST_CMD_LINE})
|
||||
generate_test(${_config} ${testname}.prof ${TOOL_CMD_LINE})
|
||||
endif()
|
||||
endmacro()
|
||||
|
||||
# Helper macro to create a test with default name
|
||||
macro(MAKE_TEST _config exe)
|
||||
string(REPLACE " " "" smush_args ${ARGN})
|
||||
set(testname ${exe}${smush_args}.tst)
|
||||
make_named_test(${_config} ${exe} ${testname} ${ARGN})
|
||||
endmacro()
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
# Macro: HIT_ADD_FILES used to scan+add multiple files for testing.
|
||||
file(GLOB HIP_LIB_FILES ${HIP_PATH}/lib/*)
|
||||
macro(HIT_ADD_FILES _config _dir _label _parent)
|
||||
foreach (file ${ARGN})
|
||||
# Build tests
|
||||
execute_process(COMMAND ${CMAKE_CURRENT_LIST_DIR}/hit/parser --buildCMDs ${file}
|
||||
OUTPUT_VARIABLE _contents
|
||||
ERROR_QUIET
|
||||
WORKING_DIRECTORY ${_dir}
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE)
|
||||
string(REGEX REPLACE "\n" ";" _contents "${_contents}")
|
||||
foreach(_cmd ${_contents})
|
||||
string(REGEX REPLACE " " ";" _cmd "${_cmd}")
|
||||
parse_build_command(_target _sources _hipcc_options _clang_options _nvcc_options _link_options _exclude_platforms _exclude_runtime _exclude_compiler _exclude_lib_type _depends ${_dir} ${_cmd})
|
||||
string(REGEX REPLACE "/" "." target ${_label}/${_target})
|
||||
if("all" IN_LIST _exclude_platforms OR ${HIP_PLATFORM} IN_LIST _exclude_platforms)
|
||||
insert_into_map("_exclude" "${target}" TRUE)
|
||||
elseif(NOT _exclude_runtime AND ${HIP_COMPILER} IN_LIST _exclude_compiler)
|
||||
insert_into_map("_exclude" "${target}" TRUE)
|
||||
elseif(NOT _exclude_compiler AND ${HIP_RUNTIME} IN_LIST _exclude_runtime)
|
||||
insert_into_map("_exclude" "${target}" TRUE)
|
||||
elseif(${HIP_RUNTIME} IN_LIST _exclude_runtime AND ${HIP_COMPILER} IN_LIST _exclude_compiler)
|
||||
insert_into_map("_exclude" "${target}" TRUE)
|
||||
elseif(${HIP_LIB_TYPE} IN_LIST _exclude_lib_type)
|
||||
insert_into_map("_exclude" "${target}" TRUE)
|
||||
else()
|
||||
set_source_files_properties(${_sources} PROPERTIES HIP_SOURCE_PROPERTY_FORMAT 1)
|
||||
hip_reset_flags()
|
||||
hip_add_executable(${target} ${_sources} HIPCC_OPTIONS ${_hipcc_options} CLANG_OPTIONS ${_clang_options} NVCC_OPTIONS ${_nvcc_options} EXCLUDE_FROM_ALL)
|
||||
target_link_options(${target} PRIVATE ${_link_options})
|
||||
set_target_properties(${target} PROPERTIES OUTPUT_NAME ${_target} RUNTIME_OUTPUT_DIRECTORY ${_label} LINK_DEPENDS "${HIP_LIB_FILES}")
|
||||
add_dependencies(${_parent} ${target})
|
||||
foreach(_dependency ${_depends})
|
||||
string(REGEX REPLACE "/" "." _dependency ${_label}/${_dependency})
|
||||
add_dependencies(${target} ${_dependency})
|
||||
endforeach()
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
# Custom build commands
|
||||
execute_process(COMMAND ${CMAKE_CURRENT_LIST_DIR}/hit/parser --customBuildCMDs ${file}
|
||||
OUTPUT_VARIABLE _contents
|
||||
ERROR_QUIET
|
||||
WORKING_DIRECTORY ${_dir}
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE)
|
||||
string(REGEX REPLACE "\n" ";" _contents "${_contents}")
|
||||
string(REGEX REPLACE "%hc" "${HIP_HIPCC_EXECUTABLE}" _contents "${_contents}")
|
||||
string(REGEX REPLACE "%hip-path" "${HIP_ROOT_DIR}" _contents "${_contents}")
|
||||
string(REGEX REPLACE "%rocm-path" "${ROCM_PATH}" _contents "${_contents}")
|
||||
string(REGEX REPLACE "%cc" "cc" _contents "${_contents}")
|
||||
string(REGEX REPLACE "%cxx" "c++" _contents "${_contents}")
|
||||
string(REGEX REPLACE "%S" ${_dir} _contents "${_contents}")
|
||||
string(REGEX REPLACE "%T" ${_label} _contents "${_contents}")
|
||||
foreach(_cmd ${_contents})
|
||||
string(REGEX REPLACE " " ";" _cmd "${_cmd}")
|
||||
parse_custombuild_command(_target _buildcmd _exclude_platforms _exclude_runtime _exclude_compiler _exclude_lib_type _depends ${_cmd})
|
||||
string(REGEX REPLACE "/" "." target ${_label}/${_target})
|
||||
if("all" IN_LIST _exclude_platforms OR ${HIP_PLATFORM} IN_LIST _exclude_platforms)
|
||||
insert_into_map("_exclude" "${target}" TRUE)
|
||||
elseif(NOT _exclude_runtime AND ${HIP_COMPILER} IN_LIST _exclude_compiler)
|
||||
insert_into_map("_exclude" "${target}" TRUE)
|
||||
elseif(NOT _exclude_compiler AND ${HIP_RUNTIME} IN_LIST _exclude_runtime)
|
||||
insert_into_map("_exclude" "${target}" TRUE)
|
||||
elseif(${HIP_RUNTIME} IN_LIST _exclude_runtime AND ${HIP_COMPILER} IN_LIST _exclude_compiler)
|
||||
insert_into_map("_exclude" "${target}" TRUE)
|
||||
elseif(${HIP_LIB_TYPE} IN_LIST _exclude_lib_type)
|
||||
insert_into_map("_exclude" "${target}" TRUE)
|
||||
else()
|
||||
parse_custombuild_command_part(_compiler _target_r _target_type _sources _options ${_buildcmd})
|
||||
string(REGEX REPLACE ";" " " _buildcmd "${_buildcmd}")
|
||||
string(REGEX REPLACE ";" " " _options "${_options}")
|
||||
|
||||
set(CHOICE_FLAG "${HIP_LIB_TYPE}" STREQUAL "static" AND "${_compiler}" MATCHES "hipcc$"
|
||||
AND "${HIP_RUNTIME}" STREQUAL "rocclr" AND "${HIP_COMPILER}" STREQUAL "clang")
|
||||
if (${CHOICE_FLAG} AND "${_target_type}" STREQUAL "EXECUTABLE")
|
||||
# message(STATUS "hip_add_executable*:_target_r= ${_target_r} --- target= ${target} --- _sources=${_sources} --- _options=${_options}")
|
||||
set_source_files_properties(${_sources} PROPERTIES HIP_SOURCE_PROPERTY_FORMAT 1)
|
||||
hip_reset_flags()
|
||||
hip_add_executable(${target} ${_sources} HIPCC_OPTIONS ${_options} EXCLUDE_FROM_ALL)
|
||||
set_target_properties(${target} PROPERTIES OUTPUT_NAME ${_target_r} RUNTIME_OUTPUT_DIRECTORY "." LINK_DEPENDS "${HIP_LIB_FILES}")
|
||||
elseif(${CHOICE_FLAG} AND "${_target_type}" STREQUAL "SHARED")
|
||||
# message(STATUS "hip_add_library*:_target_r= ${_target_r} --- target= ${target} --- _sources=${_sources} --- _options=${_options}")
|
||||
set_source_files_properties(${_sources} PROPERTIES HIP_SOURCE_PROPERTY_FORMAT 1)
|
||||
hip_reset_flags()
|
||||
hip_add_library(${target} ${_sources} HIPCC_OPTIONS ${_options} EXCLUDE_FROM_ALL ${_target_type})
|
||||
set_target_properties(${target} PROPERTIES OUTPUT_NAME ${_target_r} RUNTIME_OUTPUT_DIRECTORY "." LINK_DEPENDS "${HIP_LIB_FILES}" PREFIX "" SUFFIX "")
|
||||
else()
|
||||
# message(STATUS "add_custom_target*: target= ${target} _buildcmd= ${_buildcmd}")
|
||||
add_custom_target(${target} COMMAND sh -c "${_buildcmd} -L${CMAKE_CURRENT_SOURCE_DIR}/build/lib -isystem ${CMAKE_CURRENT_SOURCE_DIR}/include")
|
||||
endif()
|
||||
add_dependencies(${_parent} ${target})
|
||||
foreach(_dependency ${_depends})
|
||||
string(REGEX REPLACE "/" "." _dependency ${_label}/${_dependency})
|
||||
add_dependencies(${target} ${_dependency})
|
||||
endforeach()
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
# Add tests
|
||||
execute_process(COMMAND ${CMAKE_CURRENT_LIST_DIR}/hit/parser --testCMDs ${file}
|
||||
OUTPUT_VARIABLE _contents
|
||||
ERROR_QUIET
|
||||
WORKING_DIRECTORY ${_dir}
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE)
|
||||
string(REGEX REPLACE "\n" ";" _contents "${_contents}")
|
||||
foreach(_cmd ${_contents})
|
||||
string(REGEX REPLACE " " ";" _cmd "${_cmd}")
|
||||
parse_test_command(_target _arguments _exclude_platforms _exclude_runtime _exclude_compiler _exclude_lib_type ${_cmd})
|
||||
string(REGEX REPLACE "/" "." target ${_label}/${_target})
|
||||
read_from_map("_exclude" "${target}" _exclude_test_from_build)
|
||||
if("all" IN_LIST _exclude_platforms OR ${HIP_PLATFORM} IN_LIST _exclude_platforms)
|
||||
elseif(NOT _exclude_runtime AND ${HIP_COMPILER} IN_LIST _exclude_compiler)
|
||||
elseif(NOT _exclude_compiler AND ${HIP_RUNTIME} IN_LIST _exclude_runtime)
|
||||
elseif(${HIP_RUNTIME} IN_LIST _exclude_runtime AND ${HIP_COMPILER} IN_LIST _exclude_compiler)
|
||||
elseif(${HIP_LIB_TYPE} IN_LIST _exclude_lib_type)
|
||||
elseif(_exclude_test_from_build STREQUAL TRUE)
|
||||
else()
|
||||
make_test(${_config} ${_label}/${_target} ${_arguments})
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
# Add named tests
|
||||
execute_process(COMMAND ${CMAKE_CURRENT_LIST_DIR}/hit/parser --testNamedCMDs ${file}
|
||||
OUTPUT_VARIABLE _contents
|
||||
ERROR_QUIET
|
||||
WORKING_DIRECTORY ${_dir}
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE)
|
||||
string(REGEX REPLACE "\n" ";" _contents "${_contents}")
|
||||
foreach(_cmd ${_contents})
|
||||
string(REGEX REPLACE " " ";" _cmd "${_cmd}")
|
||||
parse_test_named_command(_target _testname _arguments _exclude_platforms _exclude_runtime _exclude_compiler _exclude_lib_type ${_cmd})
|
||||
string(REGEX REPLACE "/" "." target ${_label}/${_target})
|
||||
read_from_map("_exclude" "${target}" _exclude_test_from_build)
|
||||
if("all" IN_LIST _exclude_platforms OR ${HIP_PLATFORM} IN_LIST _exclude_platforms)
|
||||
elseif(NOT _exclude_runtime AND ${HIP_COMPILER} IN_LIST _exclude_compiler)
|
||||
elseif(NOT _exclude_compiler AND ${HIP_RUNTIME} IN_LIST _exclude_runtime)
|
||||
elseif(${HIP_RUNTIME} IN_LIST _exclude_runtime AND ${HIP_COMPILER} IN_LIST _exclude_compiler)
|
||||
elseif(${HIP_LIB_TYPE} IN_LIST _exclude_lib_type)
|
||||
elseif(_exclude_test_from_build STREQUAL TRUE)
|
||||
else()
|
||||
make_named_test(${_config} ${_label}/${_target} ${_label}/${_testname}.tst ${_arguments})
|
||||
endif()
|
||||
endforeach()
|
||||
endforeach()
|
||||
endmacro()
|
||||
|
||||
# Macro: HIT_ADD_DIRECTORY to scan+add all files in a directory for testing
|
||||
macro(HIT_ADD_DIRECTORY _dir _label)
|
||||
execute_process(COMMAND ${CMAKE_COMMAND} -E make_directory ${_label} WORKING_DIRECTORY ${PROJECT_BINARY_DIR})
|
||||
string(REGEX REPLACE "/" "." _parent ${_label})
|
||||
add_custom_target(${_parent})
|
||||
file(GLOB files "${_dir}/*.c*")
|
||||
hit_add_files(${HIP_CTEST_CONFIG_DEFAULT} ${_dir} ${_label} ${parent} ${files})
|
||||
endmacro()
|
||||
|
||||
# Macro: HIT_ADD_DIRECTORY_RECURSIVE to scan+add all files in a directory+subdirectories for testing
|
||||
macro(HIT_ADD_DIRECTORY_RECURSIVE _config _dir _label)
|
||||
execute_process(COMMAND ${CMAKE_COMMAND} -E make_directory ${_label} WORKING_DIRECTORY ${PROJECT_BINARY_DIR})
|
||||
string(REGEX REPLACE "/" "." _parent ${_label})
|
||||
add_custom_target(${_parent})
|
||||
if(${ARGC} EQUAL 4)
|
||||
add_dependencies(${ARGV3} ${_parent})
|
||||
endif()
|
||||
file(GLOB children RELATIVE ${_dir} ${_dir}/*)
|
||||
set(dirlist "")
|
||||
foreach(child ${children})
|
||||
if(IS_DIRECTORY ${_dir}/${child})
|
||||
list(APPEND dirlist ${child})
|
||||
else()
|
||||
hit_add_files(${_config} ${_dir} ${_label} ${_parent} ${child})
|
||||
endif()
|
||||
endforeach()
|
||||
foreach(child ${dirlist})
|
||||
string(REGEX REPLACE "/" "." _parent ${_label})
|
||||
hit_add_directory_recursive(${_config} ${_dir}/${child} ${_label}/${child} ${_parent})
|
||||
endforeach()
|
||||
endmacro()
|
||||
|
||||
# vim: ts=4:sw=4:expandtab:smartindent
|
||||
@@ -1,139 +0,0 @@
|
||||
#!/usr/bin/env perl
|
||||
# Copyright (c) 2016 - 2021 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:
|
||||
#
|
||||
# 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.
|
||||
|
||||
use 5.006; use v5.10.1;
|
||||
use warnings;
|
||||
use File::Basename;
|
||||
use File::Spec;
|
||||
|
||||
my $patBUILD = "^".quotemeta(" * BUILD:");
|
||||
my $patTEST = "^".quotemeta(" * TEST:");
|
||||
my $patTEST_NAMED = "^".quotemeta(" * TEST_NAMED:");
|
||||
my $patBUILD_CMD = "^".quotemeta(" * BUILD_CMD:");
|
||||
|
||||
# Scan input file for HIT information
|
||||
sub parse_file {
|
||||
my $file = shift;
|
||||
(my $exe = $file) =~ s/\.[^.]+$//g;
|
||||
my (@buildCMDs, @testCMDs, @testNamedCMDs, @customBuildCMDs);
|
||||
if (open (SOURCE, '<:encoding(UTF-8)', "$file")) {
|
||||
while (<SOURCE>) {
|
||||
my $line=$_;
|
||||
# Look for BUILD instructions
|
||||
if ($line =~ /$patBUILD/) {
|
||||
$line =~ s/^ \* BUILD: //g; # Remove " * BUILD: "
|
||||
$line =~ s/%s/$file/g; # Substitute %s -> filename
|
||||
$line =~ s/%t/$exe/g; # Substitute %t -> targetname
|
||||
$line =~ s/\R//g; # Remove line endings
|
||||
push @buildCMDs, $line;
|
||||
}
|
||||
# Look for TEST instructions
|
||||
if ($line =~ /$patTEST/) {
|
||||
$line =~ s/^ \* TEST: //g; # Remove " * TEST: "
|
||||
$line =~ s/%s/$file/g; # Substitute %s -> filename
|
||||
$line =~ s/%t/$exe/g; # Subsitute %t -> targetname
|
||||
$line =~ s/\R//g; # Remove line endings
|
||||
push @testCMDs, $line;
|
||||
}
|
||||
# Look for TEST_NAMED instructions
|
||||
if ($line =~ /$patTEST_NAMED/) {
|
||||
$line =~ s/^ \* TEST_NAMED: //g;# Remove " * TEST_NAMED: "
|
||||
$line =~ s/%s/$file/g; # Substitute %s -> filename
|
||||
$line =~ s/%t/$exe/g; # Subsitute %t -> targetname
|
||||
$line =~ s/\R//g; # Remove line endings
|
||||
push @testNamedCMDs, $line;
|
||||
}
|
||||
# Look for BUILD_CMD instructions
|
||||
if ($line =~ /$patBUILD_CMD/) {
|
||||
$line =~ s/^ \* BUILD_CMD: //g; # Remove " * BUILD_CMD: "
|
||||
$line =~ s/%s/$file/g; # Substitute %s -> filename
|
||||
$line =~ s/%t/$exe/g; # Substitute %t -> targetname
|
||||
# Substitute %hc -> /path/to/hipcc and %hip-path -> /path/to/hip happens in cmake
|
||||
# Substitute %cc -> cc and %cxx -> c++ happens in cmake
|
||||
# Substitute %S -> src dir and %T -> target build dir happens in cmake
|
||||
$line =~ s/\R//g; # Remove line endings
|
||||
push @customBuildCMDs, $line;
|
||||
}
|
||||
}
|
||||
close(SOURCE);
|
||||
}
|
||||
return (\@buildCMDs, \@testCMDs, \@testNamedCMDs, \@customBuildCMDs);
|
||||
}
|
||||
|
||||
# Exit if no arguments specified
|
||||
if(scalar @ARGV == 0){
|
||||
print "No Arguments passed, exiting ...\n";
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
# Parse command
|
||||
my @options = ();
|
||||
my $retBuildCMDs = 0;
|
||||
my $retTestCMDs = 0;
|
||||
my $retTestNamedCMDs = 0;
|
||||
my $retCustomBuildCMDs = 0;
|
||||
foreach $arg (@ARGV) {
|
||||
if ($retBuildCMDs or $retTestCMDs or $retTestNamedCMDs or $retCustomBuildCMDs) {
|
||||
push (@options, $arg);
|
||||
}
|
||||
if ($arg eq '--buildCMDs') {
|
||||
$retBuildCMDs = 1;
|
||||
}
|
||||
if ($arg eq '--testCMDs') {
|
||||
$retTestCMDs = 1;
|
||||
}
|
||||
if ($arg eq '--testNamedCMDs') {
|
||||
$retTestNamedCMDs = 1;
|
||||
}
|
||||
if ($arg eq '--customBuildCMDs') {
|
||||
$retCustomBuildCMDs = 1;
|
||||
}
|
||||
}
|
||||
|
||||
# Atleast one command needs to be specified
|
||||
if (($retBuildCMDs eq 0) and ($retTestCMDs eq 0) and ($retTestNamedCMDs eq 0) and($retCustomBuildCMDs eq 0)) {
|
||||
die "Usage: $0 <--buildCMDs|--testCMDs|--testNamedCMDs|--customBuildCMDs> FILENAMEs\n";
|
||||
}
|
||||
|
||||
# Iterate over input files
|
||||
foreach $file (@options) {
|
||||
# Convert absolute path to path relative to working directory
|
||||
my $relfile = File::Spec->abs2rel($file);
|
||||
my ($buildCMDs, $testCMDs, $testNamedCMDs, $customBuildCMDs) = parse_file("$relfile");
|
||||
if ($retBuildCMDs) {
|
||||
# print "BuildCMDs:\n";
|
||||
print "$_\n" for @$buildCMDs;
|
||||
}
|
||||
if ($retTestCMDs) {
|
||||
# print "TestCMDs:\n";
|
||||
print "$_\n" for @$testCMDs;
|
||||
}
|
||||
if ($retTestNamedCMDs) {
|
||||
# print "TestNamedCMDs:\n";
|
||||
print "$_\n" for @$testNamedCMDs;
|
||||
}
|
||||
if ($retCustomBuildCMDs) {
|
||||
# print "CustomBuildCMDs:\n";
|
||||
print "$_\n" for @$customBuildCMDs;
|
||||
}
|
||||
}
|
||||
|
||||
# vim: ts=4:sw=4:expandtab:smartindent
|
||||
@@ -1,76 +0,0 @@
|
||||
/*
|
||||
Copyright (c) 2015 - 2021 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:
|
||||
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 WARRANNTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INNCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANNY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER INN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR INN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Test for checking the functionality of
|
||||
* hipError_t hipDeviceSynchronize();
|
||||
*/
|
||||
|
||||
/* HIT_START
|
||||
* BUILD: %t %s ../../test_common.cpp
|
||||
* TEST: %t
|
||||
* HIT_END
|
||||
*/
|
||||
|
||||
#include "test_common.h"
|
||||
|
||||
#define _SIZE sizeof(int) * 1024 * 1024
|
||||
#define NUM_STREAMS 2
|
||||
|
||||
__global__ void Iter(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++) {
|
||||
Ad[tx] += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
int* A[NUM_STREAMS];
|
||||
int* Ad[NUM_STREAMS];
|
||||
hipStream_t stream[NUM_STREAMS];
|
||||
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++) {
|
||||
HIPCHECK(hipMemcpyAsync(Ad[i], A[i], _SIZE, hipMemcpyHostToDevice, stream[i]));
|
||||
}
|
||||
for (int i = 0; i < NUM_STREAMS; i++) {
|
||||
hipLaunchKernelGGL(HIP_KERNEL_NAME(Iter), dim3(1), dim3(1), 0, stream[i], Ad[i], 1 << 30);
|
||||
}
|
||||
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);
|
||||
HIPCHECK(hipDeviceSynchronize());
|
||||
HIPASSERT(1 << 30 == A[NUM_STREAMS - 1][0] - 1);
|
||||
passed();
|
||||
}
|
||||
@@ -1,43 +0,0 @@
|
||||
/*
|
||||
Copyright (c) 2015 - 2021 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:
|
||||
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 WARRANNTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INNCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANNY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER INN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR INN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Conformance test for checking functionality of
|
||||
* hipError_t hipGetDevice(int *device);
|
||||
*/
|
||||
|
||||
/* HIT_START
|
||||
* BUILD: %t %s ../../test_common.cpp
|
||||
* TEST: %t
|
||||
* HIT_END
|
||||
*/
|
||||
|
||||
#include "test_common.h"
|
||||
|
||||
int main() {
|
||||
int numDevices = 0;
|
||||
int device;
|
||||
HIPCHECK(hipGetDeviceCount(&numDevices));
|
||||
for (int i = 0; i < numDevices; i++) {
|
||||
HIPCHECK(hipSetDevice(i));
|
||||
HIPCHECK(hipGetDevice(&device));
|
||||
HIPASSERT(device == i);
|
||||
}
|
||||
passed();
|
||||
}
|
||||
@@ -1,36 +0,0 @@
|
||||
/*
|
||||
Copyright (c) 2015 - 2021 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:
|
||||
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 WARRANNTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INNCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANNY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER INN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR INN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
/* HIT_START
|
||||
* BUILD: %t %s ../../test_common.cpp
|
||||
* TEST: %t EXCLUDE_HIP_PLATFORM
|
||||
* HIT_END
|
||||
*/
|
||||
|
||||
#include "test_common.h"
|
||||
|
||||
int main() {
|
||||
int numDevices = 0;
|
||||
HIPCHECK(hipGetDeviceCount(&numDevices));
|
||||
for (int i = 0; i < numDevices; i++) {
|
||||
HIPCHECK(hipSetDevice(i));
|
||||
}
|
||||
HIPASSERT(hipErrorInvalidDevice == hipSetDevice(numDevices));
|
||||
passed();
|
||||
}
|
||||
@@ -1,49 +0,0 @@
|
||||
/*
|
||||
Copyright (c) 2015 - 2021 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:
|
||||
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.
|
||||
*/
|
||||
|
||||
/* HIT_START
|
||||
* BUILD: %t %s ../../test_common.cpp
|
||||
* TEST: %t
|
||||
* HIT_END
|
||||
*/
|
||||
|
||||
#include "test_common.h"
|
||||
|
||||
int main() {
|
||||
unsigned flag = 0;
|
||||
HIPCHECK(hipDeviceReset());
|
||||
|
||||
int deviceCount = 0;
|
||||
HIPCHECK(hipGetDeviceCount(&deviceCount));
|
||||
|
||||
for (int j = 0; j < deviceCount; j++) {
|
||||
HIPCHECK(hipSetDevice(j));
|
||||
|
||||
for (int i = 0; i < 4; i++) {
|
||||
flag = 1 << i;
|
||||
printf("Flag=%x\n", flag);
|
||||
HIPCHECK(hipSetDeviceFlags(flag));
|
||||
// HIPCHECK_API(hipSetDeviceFlags(flag), hipErrorInvalidValue);
|
||||
}
|
||||
|
||||
flag = 0;
|
||||
}
|
||||
|
||||
passed();
|
||||
}
|
||||
@@ -1,59 +0,0 @@
|
||||
/*
|
||||
Copyright (c) 2015 - 2021 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:
|
||||
|
||||
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.
|
||||
*/
|
||||
|
||||
/* HIT_START
|
||||
* BUILD: %t %s ../../test_common.cpp EXCLUDE_HIP_PLATFORM nvidia
|
||||
* TEST: %t 1.2 2.3
|
||||
* HIT_END
|
||||
*/
|
||||
|
||||
#include <cstdlib>
|
||||
#include <hip/hip_runtime.h>
|
||||
#include "test_common.h"
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
// Testing that the compiler supports host _Float16 conversions
|
||||
float init_value = atof(argv[1]);
|
||||
_Float16 value_float16 = static_cast<_Float16>(init_value);
|
||||
float result_value = static_cast<float>(value_float16);
|
||||
|
||||
if(std::abs(result_value - init_value) >= 0.01){
|
||||
printf("init: %f\n", init_value);
|
||||
printf("result: %f\n", result_value);
|
||||
printf("diff: %f\n", std::abs(result_value - init_value));
|
||||
failed("Failed host _Float16 test.");
|
||||
}
|
||||
|
||||
// Testing that the compiler supports host __fp16 conversions
|
||||
init_value = atof(argv[2]);
|
||||
__fp16 value_fp16 = static_cast<__fp16>(init_value);
|
||||
result_value = static_cast<float>(value_fp16);
|
||||
|
||||
if(std::abs(result_value - init_value) >= 0.01){
|
||||
printf("init: %f\n", init_value);
|
||||
printf("result: %f\n", result_value);
|
||||
printf("diff: %f\n", std::abs(result_value - init_value));
|
||||
failed("Failed host __fp16 test.");
|
||||
}
|
||||
|
||||
passed();
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
HIP_PATH=..
|
||||
|
||||
TARGET=hcc
|
||||
include $(HIP_PATH)/examples/common/hip.prologue.make
|
||||
|
||||
SOURCES = hipMemset.cpp
|
||||
OBJECTS=$(SOURCES:.cpp=.o)
|
||||
|
||||
EXECUTABLE=hipMemset
|
||||
|
||||
$(EXECUTABLE): $(HIP_DEPS) $(OBJECTS)
|
||||
$(HCC) $(HLDFLAGS) $(OBJECTS) -o $@
|
||||
|
||||
.cpp.o:
|
||||
$(HCC) $(HCFLAGS) -c $< -o $@
|
||||
@$(CC) -MM -MT $@ $(CFLAGS) -c $< > $(@:.o=.d)
|
||||
|
||||
clean: hip_clean
|
||||
rm -rf $(EXECUTABLE) $(OBJECTS)
|
||||
|
||||
include $(HIP_PATH)/examples/common/hip.epilogue.make
|
||||
@@ -1,20 +0,0 @@
|
||||
#include "hip/hip_runtime.h"
|
||||
#include "hip/hip_runtime_api.h"
|
||||
#include "hipDeviceUtil.h"
|
||||
|
||||
int main() {
|
||||
int pi;
|
||||
int attr = 0;
|
||||
// hipDeviceAttribute_t attr = hipDeviceAttributeMaxThreadsPerBlock;
|
||||
HIP_CHECK(hipDeviceGetAttribute(NULL, hipDeviceAttribute_t(attr), 0), hipDeviceGetAttribute);
|
||||
HIP_CHECK(hipDeviceGetAttribute(&pi, hipDeviceAttribute_t(attr), 0), hipDeviceGetAttribute);
|
||||
attr = -1;
|
||||
HIP_CHECK(hipDeviceGetAttribute(NULL, hipDeviceAttribute_t(attr), 0), hipDeviceGetAttribute);
|
||||
HIP_CHECK(hipDeviceGetAttribute(&pi, hipDeviceAttribute_t(attr), 0), hipDeviceGetAttribute);
|
||||
attr = 0;
|
||||
HIP_CHECK(hipDeviceGetAttribute(NULL, hipDeviceAttribute_t(attr), -1), hipDeviceGetAttribute);
|
||||
HIP_CHECK(hipDeviceGetAttribute(&pi, hipDeviceAttribute_t(attr), -1), hipDeviceGetAttribute);
|
||||
attr = -1;
|
||||
HIP_CHECK(hipDeviceGetAttribute(NULL, hipDeviceAttribute_t(attr), -1), hipDeviceGetAttribute);
|
||||
HIP_CHECK(hipDeviceGetAttribute(&pi, hipDeviceAttribute_t(attr), -1), hipDeviceGetAttribute);
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
#ifndef HIPDEVICEUTIL_H
|
||||
#define HIPDEVICEUTIL_H
|
||||
|
||||
#include "hip/hip_runtime_api.h"
|
||||
#include <iostream>
|
||||
|
||||
#define HIP_CHECK(status, func) \
|
||||
std::cout << #func << " returned " << hipGetErrorString(status) << " in " << __func__ \
|
||||
<< " at " << __LINE__ << " in file " << __FILE__ << std::endl;
|
||||
|
||||
#endif
|
||||
@@ -1,9 +0,0 @@
|
||||
#include "hip/hip_runtime.h"
|
||||
#include "hip/hip_runtime_api.h"
|
||||
#include "hipDeviceUtil.h"
|
||||
|
||||
int main() {
|
||||
int device;
|
||||
HIP_CHECK(hipGetDevice(NULL), hipGetDevice);
|
||||
HIP_CHECK(hipGetDevice(&device), hipGetDevice);
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
#include "hip/hip_runtime.h"
|
||||
#include "hip/hip_runtime_api.h"
|
||||
#include "hipDeviceUtil.h"
|
||||
|
||||
int main() {
|
||||
int deviceCnt;
|
||||
HIP_CHECK(hipGetDeviceCount(&deviceCnt), hipGetDeviceCount);
|
||||
HIP_CHECK(hipGetDeviceCount(0), hipGetDeviceCount);
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
#include "hip/hip_runtime.h"
|
||||
#include "hip/hip_runtime_api.h"
|
||||
#include "hipDeviceUtil.h"
|
||||
|
||||
int main() {
|
||||
hipDeviceProp_t props;
|
||||
HIP_CHECK(hipGetDeviceProperties(&props, 0), hipGetDeviceProperties);
|
||||
HIP_CHECK(hipGetDeviceProperties(NULL, 0), hipGetDeviceProperties);
|
||||
HIP_CHECK(hipGetDeviceProperties(NULL, -1), hipGetDeviceProperties);
|
||||
HIP_CHECK(hipGetDeviceProperties(&props, -1), hipGetDeviceProperties);
|
||||
HIP_CHECK(hipGetDeviceProperties(NULL, 1024), hipGetDeviceProperties);
|
||||
HIP_CHECK(hipGetDeviceProperties(&props, 1024), hipGetDeviceProperties);
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
#include "test_common.h"
|
||||
|
||||
int main() {
|
||||
int numDevices = 0;
|
||||
|
||||
HIPCHECK_API(hipGetDeviceCount(&numDevices), hipSuccess);
|
||||
if (numDevices > 0) {
|
||||
for (int deviceId = 0; deviceId < numDevices; deviceId++) {
|
||||
HIPCHECK_API(hipSetDevice(deviceId), hipSuccess);
|
||||
}
|
||||
HIPCHECK_API(hipSetDevice(numDevices), hipErrorInvalidDevice);
|
||||
HIPCHECK_API(hipSetDevice(-1), hipErrorInvalidDevice);
|
||||
}
|
||||
else {
|
||||
failed("Error: failed to find any compatible devices.");
|
||||
}
|
||||
|
||||
passed();
|
||||
}
|
||||
@@ -1,46 +0,0 @@
|
||||
/*
|
||||
Copyright (c) 2015 - 2021 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:
|
||||
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.
|
||||
*/
|
||||
|
||||
/* HIT_START
|
||||
* BUILD: %t %s ../../test_common.cpp
|
||||
* TEST: %t
|
||||
* HIT_END
|
||||
*/
|
||||
|
||||
#include "test_common.h"
|
||||
#define SIZE 1024
|
||||
|
||||
int main(){
|
||||
|
||||
void *Sd;
|
||||
hipError_t e;
|
||||
char S[SIZE]="This is not a device symbol";
|
||||
|
||||
HIPCHECK(hipMalloc(&Sd,SIZE));
|
||||
|
||||
e = hipMemcpyFromSymbol(S, HIP_SYMBOL(Sd), SIZE, 0, hipMemcpyDeviceToHost);
|
||||
HIPASSERT(e==hipErrorInvalidSymbol);
|
||||
|
||||
e = hipMemcpyFromSymbol(S, NULL, SIZE, 0, hipMemcpyDeviceToHost);
|
||||
HIPASSERT(e==hipErrorInvalidSymbol);
|
||||
|
||||
HIPCHECK(hipFree(Sd));
|
||||
|
||||
passed();
|
||||
}
|
||||
@@ -1,49 +0,0 @@
|
||||
/*
|
||||
Copyright (c) 2015 - 2021 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:
|
||||
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.
|
||||
*/
|
||||
|
||||
/* HIT_START
|
||||
* BUILD: %t %s ../../test_common.cpp
|
||||
* TEST: %t
|
||||
* HIT_END
|
||||
*/
|
||||
|
||||
#include "test_common.h"
|
||||
#define SIZE 1024
|
||||
|
||||
int main(){
|
||||
|
||||
void *Sd;
|
||||
hipError_t e;
|
||||
char S[SIZE]="This is not a device symbol";
|
||||
|
||||
HIPCHECK(hipMalloc(&Sd,SIZE));
|
||||
|
||||
hipStream_t stream;
|
||||
HIPCHECK(hipStreamCreate(&stream));
|
||||
|
||||
e = hipMemcpyFromSymbolAsync(S, HIP_SYMBOL(Sd), SIZE, 0, hipMemcpyDeviceToHost, stream);
|
||||
HIPASSERT(e==hipErrorInvalidSymbol);
|
||||
|
||||
e = hipMemcpyFromSymbolAsync(S, NULL, SIZE, 0, hipMemcpyDeviceToHost, stream);
|
||||
HIPASSERT(e==hipErrorInvalidSymbol);
|
||||
|
||||
HIPCHECK(hipFree(Sd));
|
||||
|
||||
passed();
|
||||
}
|
||||
@@ -1,46 +0,0 @@
|
||||
/*
|
||||
Copyright (c) 2015 - 2021 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:
|
||||
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.
|
||||
*/
|
||||
|
||||
/* HIT_START
|
||||
* BUILD: %t %s ../../test_common.cpp
|
||||
* TEST: %t
|
||||
* HIT_END
|
||||
*/
|
||||
|
||||
#include "test_common.h"
|
||||
#define SIZE 1024
|
||||
|
||||
int main(){
|
||||
|
||||
void *Sd;
|
||||
hipError_t e;
|
||||
char S[SIZE]="This is not a device symbol";
|
||||
|
||||
HIPCHECK(hipMalloc(&Sd,SIZE));
|
||||
|
||||
e = hipMemcpyToSymbol(HIP_SYMBOL(Sd), S, SIZE, 0, hipMemcpyHostToDevice);
|
||||
HIPASSERT(e==hipErrorInvalidSymbol);
|
||||
|
||||
e = hipMemcpyToSymbol(NULL, S, SIZE, 0, hipMemcpyHostToDevice);
|
||||
HIPASSERT(e==hipErrorInvalidSymbol);
|
||||
|
||||
HIPCHECK(hipFree(Sd));
|
||||
|
||||
passed();
|
||||
}
|
||||
@@ -1,49 +0,0 @@
|
||||
/*
|
||||
Copyright (c) 2015 - 2021 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:
|
||||
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.
|
||||
*/
|
||||
|
||||
/* HIT_START
|
||||
* BUILD: %t %s ../../test_common.cpp
|
||||
* TEST: %t
|
||||
* HIT_END
|
||||
*/
|
||||
|
||||
#include "test_common.h"
|
||||
#define SIZE 100
|
||||
|
||||
int main(){
|
||||
|
||||
void *Sd;
|
||||
hipError_t e;
|
||||
char S[SIZE]="This is not a device symbol";
|
||||
|
||||
HIPCHECK(hipMalloc(&Sd,SIZE));
|
||||
|
||||
hipStream_t stream;
|
||||
HIPCHECK(hipStreamCreate(&stream));
|
||||
|
||||
e = hipMemcpyToSymbolAsync(HIP_SYMBOL(Sd), S, SIZE, 0, hipMemcpyHostToDevice, stream);
|
||||
HIPASSERT(e==hipErrorInvalidSymbol);
|
||||
|
||||
e = hipMemcpyToSymbolAsync(NULL, S, SIZE, 0, hipMemcpyHostToDevice, stream);
|
||||
HIPASSERT(e==hipErrorInvalidSymbol);
|
||||
|
||||
HIPCHECK(hipFree(Sd));
|
||||
|
||||
passed();
|
||||
}
|
||||
@@ -1,43 +0,0 @@
|
||||
/*
|
||||
Copyright (c) 2015 - 2021 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:
|
||||
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.
|
||||
*/
|
||||
|
||||
/* HIT_START
|
||||
* BUILD: %t %s ../../test_common.cpp EXCLUDE_HIP_RUNTIME rocclr
|
||||
* TEST: %t
|
||||
* HIT_END
|
||||
*/
|
||||
|
||||
#include "test_common.h"
|
||||
#define SIZE 100
|
||||
|
||||
int main(){
|
||||
hipError_t e;
|
||||
char str[SIZE]="Hi, I am Ellesemere. What is ur name?";
|
||||
|
||||
e = hipMemcpy(0, str, SIZE, hipMemcpyHostToDevice);
|
||||
HIPASSERT(e==hipErrorInvalidValue);
|
||||
|
||||
e = hipMemcpy(NULL, str, SIZE, hipMemcpyHostToDevice);
|
||||
HIPASSERT(e==hipErrorInvalidValue);
|
||||
|
||||
e = hipMemset(0,99,80);
|
||||
HIPASSERT(e==hipErrorInvalidValue);
|
||||
|
||||
passed();
|
||||
}
|
||||
@@ -1,40 +0,0 @@
|
||||
/*
|
||||
Copyright (c) 2015 - 2021 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:
|
||||
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.
|
||||
*/
|
||||
|
||||
/* HIT_START
|
||||
* BUILD: %t %s ../../test_common.cpp EXCLUDE_HIP_RUNTIME rocclr
|
||||
* TEST: %t
|
||||
* HIT_END
|
||||
*/
|
||||
|
||||
#include "test_common.h"
|
||||
|
||||
int main(){
|
||||
|
||||
hipError_t e;
|
||||
hipStream_t stream;
|
||||
|
||||
e = hipStreamCreateWithFlags(&stream, -1);
|
||||
HIPASSERT(e==hipErrorInvalidValue);
|
||||
|
||||
e = hipStreamCreateWithFlags(&stream, 2);
|
||||
HIPASSERT(e==hipErrorInvalidValue);
|
||||
|
||||
passed();
|
||||
}
|
||||
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
@@ -1,355 +0,0 @@
|
||||
/*
|
||||
Copyright (c) 2015 - 2021 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:
|
||||
|
||||
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.
|
||||
*/
|
||||
/* HIT_START
|
||||
* BUILD: %t %s ../test_common.cpp
|
||||
* TEST: %t
|
||||
* HIT_END
|
||||
*/
|
||||
#include "hipClassKernel.h"
|
||||
|
||||
#ifdef ENABLE_OVERLOAD_OVERRIDE_TESTS
|
||||
__global__ void
|
||||
ovrdClassKernel(bool* result_ecd){
|
||||
int tid = threadIdx.x + blockIdx.x * blockDim.x;
|
||||
testOvrD tobj1;
|
||||
result_ecd[tid] = (tobj1.ovrdFunc1() == 30);
|
||||
}
|
||||
|
||||
void HipClassTests::TestForOverride(void){
|
||||
bool *result_ecd, *result_ech;
|
||||
result_ech = HipClassTests::AllocateHostMemory();
|
||||
result_ecd = HipClassTests::AllocateDeviceMemory();
|
||||
|
||||
hipLaunchKernelGGL(ovrdClassKernel,
|
||||
dim3(BLOCKS),
|
||||
dim3(THREADS_PER_BLOCK),
|
||||
0,
|
||||
0,
|
||||
result_ecd);
|
||||
|
||||
HipClassTests::VerifyResult(result_ech,result_ecd);
|
||||
HipClassTests::FreeMem(result_ech,result_ecd);
|
||||
}
|
||||
|
||||
|
||||
__global__ void
|
||||
ovldClassKernel(bool* result_ecd){
|
||||
int tid = threadIdx.x + blockIdx.x * blockDim.x;
|
||||
testFuncOvld tfo1;
|
||||
result_ecd[tid] = (tfo1.func1(10) == 20)
|
||||
&& (tfo1.func1(10,10) == 30);
|
||||
}
|
||||
|
||||
void HipClassTests::TestForOverload(void){
|
||||
bool *result_ecd, *result_ech;
|
||||
result_ech = HipClassTests::AllocateHostMemory();
|
||||
result_ecd = HipClassTests::AllocateDeviceMemory();
|
||||
|
||||
hipLaunchKernelGGL(ovldClassKernel,
|
||||
dim3(BLOCKS),
|
||||
dim3(THREADS_PER_BLOCK),
|
||||
0,
|
||||
0,
|
||||
result_ecd);
|
||||
|
||||
HipClassTests::VerifyResult(result_ech,result_ecd);
|
||||
HipClassTests::FreeMem(result_ech,result_ecd);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef ENABLE_FRIEND_TEST
|
||||
// check for friend
|
||||
__global__ void
|
||||
friendClassKernel(bool* result_ecd){
|
||||
int tid = threadIdx.x + blockIdx.x * blockDim.x;
|
||||
testFrndB tfb1;
|
||||
result_ecd[tid] = (tfb1.showA() == 10);
|
||||
}
|
||||
#endif
|
||||
|
||||
// check sizeof empty class is 1
|
||||
__global__ void
|
||||
emptyClassKernel(bool* result_ecd) {
|
||||
int tid = threadIdx.x + blockIdx.x * blockDim.x;
|
||||
testClassEmpty ob1,ob2;
|
||||
result_ecd[tid] = (sizeof(testClassEmpty) == 1)
|
||||
&& (&ob1 != &ob2);
|
||||
}
|
||||
|
||||
void HipClassTests::TestForEmptyClass(void){
|
||||
bool *result_ecd, *result_ech;
|
||||
result_ech = HipClassTests::AllocateHostMemory();
|
||||
result_ecd = HipClassTests::AllocateDeviceMemory();
|
||||
|
||||
hipLaunchKernelGGL(emptyClassKernel,
|
||||
dim3(BLOCKS),
|
||||
dim3(THREADS_PER_BLOCK),
|
||||
0,
|
||||
0,
|
||||
result_ecd);
|
||||
|
||||
HipClassTests::VerifyResult(result_ech,result_ecd);
|
||||
HipClassTests::FreeMem(result_ech,result_ecd);
|
||||
}
|
||||
|
||||
// tests for classes >8 bytes
|
||||
__global__ void
|
||||
sizeClassBKernel(bool* result_ecd) {
|
||||
int tid = threadIdx.x + blockIdx.x * blockDim.x;
|
||||
result_ecd[tid] = (sizeof(testSizeB) == 12)
|
||||
&& (sizeof(testSizeC) == 16)
|
||||
&& (sizeof(testSizeP1) == 6)
|
||||
&& (sizeof(testSizeP2) == 13)
|
||||
&& (sizeof(testSizeP3) == 8);
|
||||
}
|
||||
|
||||
void HipClassTests::TestForClassBSize(void){
|
||||
bool *result_ecd, *result_ech;
|
||||
result_ech = HipClassTests::AllocateHostMemory();
|
||||
result_ecd = HipClassTests::AllocateDeviceMemory();
|
||||
|
||||
hipLaunchKernelGGL(sizeClassBKernel,
|
||||
dim3(BLOCKS),
|
||||
dim3(THREADS_PER_BLOCK),
|
||||
0,
|
||||
0,
|
||||
result_ecd);
|
||||
|
||||
HipClassTests::VerifyResult(result_ech,result_ecd);
|
||||
HipClassTests::FreeMem(result_ech,result_ecd);
|
||||
}
|
||||
|
||||
__global__ void
|
||||
sizeClassKernel(bool* result_ecd) {
|
||||
int tid = threadIdx.x + blockIdx.x * blockDim.x;
|
||||
result_ecd[tid] = (sizeof(testSizeA) == 16)
|
||||
&& (sizeof(testSizeDerived) == 24)
|
||||
&& (sizeof(testSizeDerived2) == 20);
|
||||
}
|
||||
|
||||
void HipClassTests::TestForClassSize(void){
|
||||
bool *result_ecd, *result_ech;
|
||||
result_ech = HipClassTests::AllocateHostMemory();
|
||||
result_ecd = HipClassTests::AllocateDeviceMemory();
|
||||
|
||||
hipLaunchKernelGGL(sizeClassKernel,
|
||||
dim3(BLOCKS),
|
||||
dim3(THREADS_PER_BLOCK),
|
||||
0,
|
||||
0,
|
||||
result_ecd);
|
||||
|
||||
HipClassTests::VerifyResult(result_ech,result_ecd);
|
||||
HipClassTests::FreeMem(result_ech,result_ecd);
|
||||
}
|
||||
|
||||
#ifdef ENABLE_VIRTUAL_TESTS
|
||||
__global__ void
|
||||
sizeVirtualClassKernel(bool* result_ecd) {
|
||||
int tid = threadIdx.x + blockIdx.x * blockDim.x;
|
||||
result_ecd[tid] = (sizeof(testSizeDV) == 16)
|
||||
&& (sizeof(testSizeDerivedDV) == 16)
|
||||
&& (sizeof(testSizeVirtDerPack) == 24)
|
||||
&& (sizeof(testSizeVirtDer) == 24)
|
||||
&& (sizeof(testSizeDerMulti) == 48) ;
|
||||
}
|
||||
|
||||
void HipClassTests::TestForVirtualClassSize(void){
|
||||
bool *result_ecd, *result_ech;
|
||||
result_ech = HipClassTests::AllocateHostMemory();
|
||||
result_ecd = HipClassTests::AllocateDeviceMemory();
|
||||
|
||||
hipLaunchKernelGGL(sizeVirtualClassKernel,
|
||||
dim3(BLOCKS),
|
||||
dim3(THREADS_PER_BLOCK),
|
||||
0,
|
||||
0,
|
||||
result_ecd);
|
||||
|
||||
HipClassTests::VerifyResult(result_ech,result_ecd);
|
||||
HipClassTests::FreeMem(result_ech,result_ecd);
|
||||
}
|
||||
#endif
|
||||
|
||||
// check pass by value
|
||||
__global__ void
|
||||
passByValueKernel(testPassByValue obj, bool* result_ecd) {
|
||||
int tid = threadIdx.x + blockIdx.x * blockDim.x;
|
||||
result_ecd[tid] = (obj.exI == 10)
|
||||
&& (obj.exC == 'C');
|
||||
}
|
||||
|
||||
void HipClassTests::TestForPassByValue(void){
|
||||
bool *result_ecd,*result_ech;
|
||||
result_ech = HipClassTests::AllocateHostMemory();
|
||||
result_ecd = HipClassTests::AllocateDeviceMemory();
|
||||
|
||||
testPassByValue exObj;
|
||||
exObj.exI = 10;
|
||||
exObj.exC = 'C';
|
||||
hipLaunchKernelGGL(passByValueKernel,
|
||||
dim3(BLOCKS),
|
||||
dim3(THREADS_PER_BLOCK),
|
||||
0,
|
||||
0,
|
||||
exObj,
|
||||
result_ecd);
|
||||
|
||||
HipClassTests::VerifyResult(result_ech,result_ecd);
|
||||
HipClassTests::FreeMem(result_ech,result_ecd);
|
||||
}
|
||||
|
||||
// check obj created with hipMalloc
|
||||
__global__ void
|
||||
mallocObjKernel(testPassByValue *obj, bool* result_ecd) {
|
||||
int tid = threadIdx.x + blockIdx.x * blockDim.x;
|
||||
result_ecd[tid] = (obj->exI == 100)
|
||||
&& (obj->exC == 'C');
|
||||
}
|
||||
|
||||
void HipClassTests::TestForMallocPassByValue(void){
|
||||
bool *result_ecd,*result_ech;
|
||||
result_ech = HipClassTests::AllocateHostMemory();
|
||||
result_ecd = HipClassTests::AllocateDeviceMemory();
|
||||
|
||||
|
||||
testPassByValue *exObjM;
|
||||
HIPCHECK(hipMalloc(&exObjM, sizeof(testPassByValue)));
|
||||
exObjM->exI = 100;
|
||||
exObjM->exC = 'C';
|
||||
hipLaunchKernelGGL(mallocObjKernel,
|
||||
dim3(BLOCKS),
|
||||
dim3(THREADS_PER_BLOCK),
|
||||
0,
|
||||
0,
|
||||
exObjM,
|
||||
result_ecd);
|
||||
|
||||
HipClassTests::VerifyResult(result_ech,result_ecd);
|
||||
HipClassTests::FreeMem(result_ech,result_ecd);
|
||||
|
||||
}
|
||||
|
||||
// check if constr and destr are accessible from kernel
|
||||
#ifdef ENABLE_DESTRUCTOR_TEST
|
||||
__global__ void
|
||||
testDeviceClassKernel() {
|
||||
int tid = threadIdx.x + blockIdx.x * blockDim.x;
|
||||
testDeviceClass ob1;
|
||||
testDeviceClass ob2;
|
||||
ob2.iVar = 10;
|
||||
}
|
||||
|
||||
void HipClassTests::TestForConsrtDesrt(){
|
||||
testDeviceClass tDC;
|
||||
hipLaunchKernelGGL(testDeviceClassKernel,
|
||||
dim3(BLOCKS),
|
||||
dim3(THREADS_PER_BLOCK),
|
||||
0,
|
||||
0);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef ENABLE_FRIEND_TEST
|
||||
void HipClassTests::TestForFriend(void){
|
||||
bool *result_ecd, *result_ech;
|
||||
result_ech = HipClassTests::AllocateHostMemory();
|
||||
result_ecd = HipClassTests::AllocateDeviceMemory();
|
||||
hipLaunchKernelGGL(friendClassKernel,
|
||||
dim3(BLOCKS),
|
||||
dim3(THREADS_PER_BLOCK),
|
||||
0,
|
||||
0,
|
||||
result_ecd);
|
||||
}
|
||||
#endif
|
||||
|
||||
bool* HipClassTests::AllocateHostMemory(void){
|
||||
bool *result_ech;
|
||||
HIPCHECK(hipHostMalloc(&result_ech,
|
||||
NBOOL,
|
||||
hipHostMallocDefault));
|
||||
return result_ech;
|
||||
}
|
||||
|
||||
bool* HipClassTests::AllocateDeviceMemory(void){
|
||||
bool* result_ecd;
|
||||
HIPCHECK(hipMalloc(&result_ecd,
|
||||
NBOOL));
|
||||
HIPCHECK(hipMemset(result_ecd,
|
||||
false,
|
||||
NBOOL));
|
||||
return result_ecd;
|
||||
}
|
||||
|
||||
void HipClassTests::VerifyResult(bool* result_ech, bool* result_ecd){
|
||||
HIPCHECK(hipMemcpy(result_ech,
|
||||
result_ecd,
|
||||
BLOCKS*sizeof(bool),
|
||||
hipMemcpyDeviceToHost));
|
||||
// validation on host side
|
||||
for (int i = 0; i < BLOCKS; i++) {
|
||||
HIPASSERT(result_ech[i] == true);
|
||||
}
|
||||
}
|
||||
|
||||
void HipClassTests::FreeMem(bool* result_ech, bool* result_ecd){
|
||||
HIPCHECK(hipHostFree(result_ech));
|
||||
HIPCHECK(hipFree(result_ecd));
|
||||
}
|
||||
|
||||
int main(){
|
||||
HipClassTests classTests;
|
||||
classTests.TestForEmptyClass();
|
||||
test_passed(TestForEmptyClass);
|
||||
classTests.TestForClassBSize();
|
||||
test_passed(TestForClassBSize);
|
||||
classTests.TestForClassSize();
|
||||
test_passed(TestForClassSize);
|
||||
classTests.TestForPassByValue();
|
||||
test_passed(TestForPassByValue);
|
||||
|
||||
#ifdef ENABLE_OVERLOAD_OVERRIDE_TESTS
|
||||
classTests.TestForOverload();
|
||||
test_passed(TestForOverload);
|
||||
classTests.TestForOverride();
|
||||
test_passed(TestForOverride);
|
||||
#endif
|
||||
|
||||
#ifdef ENABLE_FRIEND_TEST
|
||||
classTests.TestForFriend();
|
||||
test_passed(TestForFriend);
|
||||
#endif
|
||||
|
||||
// classTests.TestForMallocPassByValue();
|
||||
// test_passed(TestForMallocPassByValue); #this test is crashing
|
||||
|
||||
#ifdef ENABLE_VIRTUAL_TESTS
|
||||
classTests.TestForVirtualClassSize();
|
||||
test_passed(TestForVirtualClassSize);
|
||||
#endif
|
||||
|
||||
#ifdef ENABLE_DESTRUCTOR_TEST
|
||||
classTests.TestForConsrtDesrt();
|
||||
test_passed(TestForConsrtDesrt);
|
||||
#endif
|
||||
}
|
||||
@@ -1,239 +0,0 @@
|
||||
/*
|
||||
Copyright (c) 2015 - 2021 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:
|
||||
|
||||
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.
|
||||
*/
|
||||
#ifndef _COMPILER_HIPCLASSKERNEL_H_
|
||||
#define _COMPILER_HIPCLASSKERNEL_H_
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include "hip/hip_runtime.h"
|
||||
#include "test_common.h"
|
||||
|
||||
static const int BLOCKS = 512;
|
||||
static const int THREADS_PER_BLOCK = 1;
|
||||
static const int ENABLE_DESTRUCTOR_TEST = 0;
|
||||
static const int ENABLE_VIRTUAL_TESTS = 0;
|
||||
static const int ENABLE_FRIEND_TEST = 0;
|
||||
static const int ENABLE_OVERLAD_OVERRIDE_TESTS = 0;
|
||||
size_t NBOOL = BLOCKS * sizeof(bool);
|
||||
|
||||
#define test_passed(test_name) printf("%s %s PASSED!%s\n", KGRN, #test_name, KNRM);
|
||||
|
||||
#ifdef ENABLE_OVERLOAD_OVERRIDE_TESTS
|
||||
class testFuncOvld{
|
||||
public:
|
||||
int __host__ __device__ func1(int a){
|
||||
return a + 10;
|
||||
}
|
||||
|
||||
int __host__ __device__ func1(int a , int b){
|
||||
return a + b + 10;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
class testOvrB{
|
||||
public:
|
||||
int __host__ __device__ ovrdFunc1(){
|
||||
return 10;
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
class testOvrD: public testOvrB{
|
||||
public:
|
||||
int __host__ __device__ ovrdFunc1(){
|
||||
int x = testOvrB::ovrdFunc1();
|
||||
return x + 20;
|
||||
}
|
||||
|
||||
};
|
||||
#endif
|
||||
|
||||
#ifdef ENABLE_FRIEND_TEST
|
||||
class testFrndA{
|
||||
private:
|
||||
int fa = 10;
|
||||
public:
|
||||
friend class testFrndB;
|
||||
};
|
||||
|
||||
class testFrndB{
|
||||
public:
|
||||
__host__ __device__ int showA(){
|
||||
testFrndA x;
|
||||
return x.fa;
|
||||
}
|
||||
};
|
||||
#endif
|
||||
|
||||
class testClassEmpty {};
|
||||
|
||||
class testPassByValue{
|
||||
public:
|
||||
int exI;
|
||||
char exC;
|
||||
};
|
||||
|
||||
class testSizeA {
|
||||
public:
|
||||
float xa;
|
||||
int ia;
|
||||
double da;
|
||||
static char ca;
|
||||
};
|
||||
|
||||
class testSizeDerived : testSizeA {
|
||||
public:
|
||||
float fd;
|
||||
};
|
||||
|
||||
#pragma pack(push,4)
|
||||
class testSizeDerived2 : testSizeA {
|
||||
public:
|
||||
float fd;
|
||||
};
|
||||
#pragma pack(pop)
|
||||
|
||||
class testSizeB {
|
||||
public:
|
||||
char ab;
|
||||
int ib;
|
||||
char cb;
|
||||
};
|
||||
|
||||
#ifdef ENBABLE_VIRTUAL_TESTS
|
||||
class testSizeVirtDer : public virtual testSizeB {
|
||||
public:
|
||||
int ivd;
|
||||
};
|
||||
|
||||
class testSizeVirtDer1 : public virtual testSizeB {
|
||||
public:
|
||||
int ivd1;
|
||||
};
|
||||
|
||||
class testSizeDerMulti : public testSizeVirtDer, public testSizeVirtDer1 {
|
||||
public:
|
||||
int ivd2;
|
||||
};
|
||||
|
||||
#pragma pack(push,4)
|
||||
class testSizeVirtDerPack : public virtual testSizeB {
|
||||
public:
|
||||
int ivd;
|
||||
};
|
||||
#pragma pack(pop)
|
||||
#endif
|
||||
|
||||
class testSizeC {
|
||||
public:
|
||||
char ac;
|
||||
int ic;
|
||||
int bc[2];
|
||||
};
|
||||
|
||||
#ifdef ENABLE_VIRTUAL_TESTS
|
||||
class testSizeDV {
|
||||
public:
|
||||
virtual void __host__ __device__ func1();
|
||||
private:
|
||||
int iDV;
|
||||
|
||||
};
|
||||
|
||||
class testSizeDerivedDV : testSizeDV {
|
||||
public:
|
||||
virtual void __host__ __device__ funcD1();
|
||||
private:
|
||||
int iDDV;
|
||||
};
|
||||
#endif
|
||||
|
||||
#pragma pack(push, 1)
|
||||
class testSizeP1 {
|
||||
public:
|
||||
char ap;
|
||||
int ip;
|
||||
char cp;
|
||||
};
|
||||
#pragma pack(pop)
|
||||
|
||||
#pragma pack(push, 1)
|
||||
class testSizeP2 {
|
||||
public:
|
||||
char ap1;
|
||||
int ip1;
|
||||
int bp1[2];
|
||||
};
|
||||
#pragma pack(pop)
|
||||
|
||||
#pragma pack(push, 2)
|
||||
class testSizeP3 {
|
||||
public:
|
||||
char ap2;
|
||||
int ip2;
|
||||
char cp2;
|
||||
};
|
||||
#pragma pack(pop)
|
||||
|
||||
#ifdef ENABLE_DESTRUCTOR_TEST
|
||||
class testDeviceClass {
|
||||
public:
|
||||
int iVar;
|
||||
__host__ __device__ testDeviceClass();
|
||||
__host__ __device__ testDeviceClass(int a);
|
||||
__host__ __device__ ~testDeviceClass();
|
||||
};
|
||||
|
||||
__host__ __device__
|
||||
testDeviceClass::testDeviceClass() {
|
||||
iVar = 5;
|
||||
}
|
||||
|
||||
__host__ __device__
|
||||
testDeviceClass::testDeviceClass(int a) {
|
||||
iVar = a;
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // _HIPCLASSKERNEL_H_
|
||||
|
||||
class HipClassTests{
|
||||
public:
|
||||
void TestForEmptyClass(void);
|
||||
void TestForClassBSize(void);
|
||||
void TestForClassSize(void);
|
||||
void TestForVirtualClassSize(void);
|
||||
void TestForPassByValue(void);
|
||||
void TestForMallocPassByValue(void);
|
||||
void TestForConsrtDesrt(void);
|
||||
void TestForOverload(void);
|
||||
void TestForOverride(void);
|
||||
|
||||
bool* AllocateHostMemory(void);
|
||||
bool* AllocateDeviceMemory(void);
|
||||
void VerifyResult(bool* result_ech, bool* result_ecd);
|
||||
void FreeMem(bool* result_ech, bool* result_ecd);
|
||||
};
|
||||
@@ -1,52 +0,0 @@
|
||||
/*
|
||||
Copyright (c) 2015 - 2021 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:
|
||||
|
||||
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.
|
||||
*/
|
||||
|
||||
/* HIT_START
|
||||
* BUILD: %t %s ../test_common.cpp
|
||||
* TEST: %t
|
||||
* HIT_END
|
||||
*/
|
||||
|
||||
#include "hip/hip_runtime.h"
|
||||
#include "test_common.h"
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
HipTest::parseStandardArguments(argc, argv, true);
|
||||
|
||||
HIPCHECK(hipInit(0));
|
||||
|
||||
hipDevice_t device;
|
||||
hipDevice_t device1;
|
||||
hipCtx_t ctx;
|
||||
hipCtx_t ctx1;
|
||||
|
||||
HIPCHECK(hipDeviceGet(&device, 0));
|
||||
HIPCHECK(hipCtxCreate(&ctx, 0, device));
|
||||
HIPCHECK(hipCtxGetCurrent(&ctx1));
|
||||
HIPCHECK(hipCtxGetDevice(&device1));
|
||||
HIPCHECK(hipCtxPopCurrent(&ctx1));
|
||||
HIPCHECK(hipCtxGetCurrent(&ctx1));
|
||||
|
||||
HIPCHECK(hipCtxDestroy(ctx));
|
||||
|
||||
passed();
|
||||
};
|
||||
@@ -1,35 +0,0 @@
|
||||
/*
|
||||
Copyright (c) 2015 - 2021 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:
|
||||
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 WARRANNTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INNCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANNY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER INN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR INN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "hip/hip_runtime.h"
|
||||
#include "hip/hip_runtime_api.h"
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <vector>
|
||||
|
||||
int main() {
|
||||
hipInit(0);
|
||||
hipDevice_t device;
|
||||
hipDeviceGet(&device, 0);
|
||||
char pciBusId[10];
|
||||
memset(pciBusId, 0, 10);
|
||||
hipDeviceGetPCIBusId(pciBusId, 100, device);
|
||||
printf("PCI Bus ID= %s\n", pciBusId);
|
||||
return 0;
|
||||
}
|
||||
@@ -1,44 +0,0 @@
|
||||
#include <iostream>
|
||||
#include "hip/hip_runtime.h"
|
||||
#include "hip/hip_runtime_api.h"
|
||||
|
||||
#define LEN 1024
|
||||
#define SIZE LEN << 2
|
||||
|
||||
int main() {
|
||||
int *A, *B;
|
||||
hipDeviceptr_t Ad, Bd;
|
||||
A = new int[LEN];
|
||||
B = new int[LEN];
|
||||
|
||||
for (int i = 0; i < LEN; i++) {
|
||||
A[i] = i;
|
||||
}
|
||||
|
||||
hipMalloc((void**)&Ad, SIZE);
|
||||
hipMalloc((void**)&Bd, SIZE);
|
||||
|
||||
hipMemcpyHtoD(Ad, A, SIZE);
|
||||
hipMemcpyDtoD(Bd, Ad, SIZE);
|
||||
hipMemcpyDtoH(B, Bd, SIZE);
|
||||
|
||||
for (int i = 0; i < 16; i++) {
|
||||
std::cout << A[i] << " " << B[i] << std::endl;
|
||||
}
|
||||
|
||||
int *Ah, *Bh;
|
||||
hipHostMalloc(&Ah, SIZE, 0);
|
||||
hipHostMalloc(&Bh, SIZE, 0);
|
||||
memcpy(Ah, A, SIZE);
|
||||
hipStream_t stream;
|
||||
hipStreamCreate(&stream);
|
||||
|
||||
hipMemcpyHtoDAsync(Ad, Ah, SIZE, stream);
|
||||
hipStreamSynchronize(stream);
|
||||
hipMemcpyDtoDAsync(Bd, Ad, SIZE, stream);
|
||||
hipStreamSynchronize(stream);
|
||||
hipMemcpyDtoHAsync(Bh, Bd, SIZE, stream);
|
||||
hipStreamSynchronize(stream);
|
||||
|
||||
std::cout << Ah[10] << " " << Bh[10] << std::endl;
|
||||
}
|
||||
@@ -1,64 +0,0 @@
|
||||
/*
|
||||
Copyright (c) 2015 - 2021 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:
|
||||
|
||||
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.
|
||||
*/
|
||||
// Simple test for hipMemsetD8.
|
||||
// Also serves as a template for other tests.
|
||||
|
||||
/* HIT_START
|
||||
* BUILD: %t %s ../test_common.cpp
|
||||
* TEST: %t
|
||||
* //Small copy
|
||||
* TEST: %t -N 10 --memsetval 0x42
|
||||
* // Oddball size
|
||||
* TEST: %t -N 10013 --memsetval 0x5a
|
||||
* // Big copy
|
||||
* TEST: %t -N 256M --memsetval 0xa6
|
||||
* HIT_END
|
||||
*/
|
||||
|
||||
#include "hip/hip_runtime.h"
|
||||
#include "test_common.h"
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
HipTest::parseStandardArguments(argc, argv, true);
|
||||
size_t Nbytes = N * sizeof(char);
|
||||
char* A_h;
|
||||
hipDeviceptr_t A_d;
|
||||
A_h = new char[Nbytes];
|
||||
|
||||
HIPCHECK(hipMalloc((void**)&A_d, Nbytes));
|
||||
|
||||
printf("Size=%zu memsetval=%2x \n", Nbytes, memsetval);
|
||||
HIPCHECK(hipMemsetD8(A_d, memsetval, Nbytes));
|
||||
|
||||
HIPCHECK(hipMemcpy(A_h, (void*)A_d, Nbytes, hipMemcpyDeviceToHost));
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
hipFree((void*)A_d);
|
||||
delete[] A_h;
|
||||
passed();
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
/*
|
||||
Copyright (c) 2019 - 2021 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:
|
||||
|
||||
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.
|
||||
*/
|
||||
/* HIT_START
|
||||
* BUILD: %t %s ../test_common.cpp HIPCC_OPTIONS -std=c++11
|
||||
* TEST: %t
|
||||
* HIT_END
|
||||
*/
|
||||
|
||||
#include "is_callable_test.hpp"
|
||||
#include <test_common.h>
|
||||
|
||||
int main() { passed(); }
|
||||
@@ -1,34 +0,0 @@
|
||||
/*
|
||||
Copyright (c) 2019 - 2021 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:
|
||||
|
||||
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.
|
||||
*/
|
||||
/* HIT_START
|
||||
* BUILD: %t %s ../test_common.cpp HIPCC_OPTIONS -std=c++11
|
||||
* TEST: %t
|
||||
* HIT_END
|
||||
*/
|
||||
|
||||
// Ensure fallback path is chosen
|
||||
#define HIP_HAS_RESULT_OF_SFINAE 0
|
||||
#define HIP_HAS_INVOCABLE 0
|
||||
#include "is_callable_test.hpp"
|
||||
#include <test_common.h>
|
||||
|
||||
int main() { passed(); }
|
||||
@@ -1,31 +0,0 @@
|
||||
/*
|
||||
Copyright (c) 2019 - 2021 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:
|
||||
|
||||
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.
|
||||
*/
|
||||
/* HIT_START
|
||||
* BUILD: %t %s ../test_common.cpp HIPCC_OPTIONS -std=c++14
|
||||
* TEST: %t
|
||||
* HIT_END
|
||||
*/
|
||||
|
||||
#include "is_callable_test.hpp"
|
||||
#include <test_common.h>
|
||||
|
||||
int main() { passed(); }
|
||||
@@ -1,31 +0,0 @@
|
||||
/*
|
||||
Copyright (c) 2019 - 2021 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:
|
||||
|
||||
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.
|
||||
*/
|
||||
/* HIT_START
|
||||
* BUILD: %t %s ../test_common.cpp HIPCC_OPTIONS -std=c++17
|
||||
* TEST: %t
|
||||
* HIT_END
|
||||
*/
|
||||
|
||||
#include "is_callable_test.hpp"
|
||||
#include <test_common.h>
|
||||
|
||||
int main() { passed(); }
|
||||
@@ -1,209 +0,0 @@
|
||||
/*
|
||||
Copyright (c) 2017 - 2021 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:
|
||||
|
||||
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.
|
||||
*/
|
||||
|
||||
#include <hip/amd_detail/helpers.hpp>
|
||||
#include <memory>
|
||||
|
||||
using hip_impl::is_callable;
|
||||
|
||||
template<int N>
|
||||
struct callable_rank : callable_rank<N-1>
|
||||
{};
|
||||
|
||||
template<>
|
||||
struct callable_rank<0>
|
||||
{};
|
||||
|
||||
struct test1
|
||||
{
|
||||
struct is_callable_class
|
||||
{
|
||||
void operator()(int) const
|
||||
{
|
||||
}
|
||||
};
|
||||
struct callable_test_param {};
|
||||
|
||||
void is_callable_function(int)
|
||||
{
|
||||
}
|
||||
|
||||
struct is_callable_rank_class
|
||||
{
|
||||
void operator()(int, callable_rank<3>) const
|
||||
{
|
||||
}
|
||||
|
||||
void operator()(int, callable_rank<4>) const
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
static_assert(is_callable<is_callable_class(int)>::value, "Not callable");
|
||||
static_assert(is_callable<is_callable_class(long)>::value, "Not callable");
|
||||
static_assert(is_callable<is_callable_class(double)>::value, "Not callable");
|
||||
static_assert(is_callable<is_callable_class(const int&)>::value, "Not callable");
|
||||
static_assert(is_callable<is_callable_class(const long&)>::value, "Not callable");
|
||||
static_assert(is_callable<is_callable_class(const double&)>::value, "Not callable");
|
||||
static_assert(not is_callable<is_callable_class(callable_test_param)>::value, "callable failed");
|
||||
static_assert(not is_callable<is_callable_class()>::value, "callable failed");
|
||||
static_assert(not is_callable<is_callable_class(int, int)>::value, "callable failed");
|
||||
|
||||
typedef void (*is_callable_function_pointer)(int);
|
||||
static_assert(is_callable<is_callable_function_pointer(int)>::value, "Not callable");
|
||||
static_assert(is_callable<is_callable_function_pointer(long)>::value, "Not callable");
|
||||
static_assert(is_callable<is_callable_function_pointer(double)>::value, "Not callable");
|
||||
static_assert(is_callable<is_callable_function_pointer(const int&)>::value, "Not callable");
|
||||
static_assert(is_callable<is_callable_function_pointer(const long&)>::value, "Not callable");
|
||||
static_assert(is_callable<is_callable_function_pointer(const double&)>::value, "Not callable");
|
||||
static_assert(not is_callable<is_callable_function_pointer(callable_test_param)>::value, "callable failed");
|
||||
static_assert(not is_callable<is_callable_function_pointer()>::value, "callable failed");
|
||||
static_assert(not is_callable<is_callable_function_pointer(int, int)>::value, "callable failed");
|
||||
|
||||
static_assert(is_callable<is_callable_rank_class(int, callable_rank<3>)>::value, "Not callable");
|
||||
static_assert(is_callable<is_callable_rank_class(long, callable_rank<3>)>::value, "Not callable");
|
||||
static_assert(is_callable<is_callable_rank_class(double, callable_rank<3>)>::value, "Not callable");
|
||||
static_assert(is_callable<is_callable_rank_class(const int&, callable_rank<3>)>::value, "Not callable");
|
||||
static_assert(is_callable<is_callable_rank_class(const long&, callable_rank<3>)>::value, "Not callable");
|
||||
static_assert(is_callable<is_callable_rank_class(const double&, callable_rank<3>)>::value, "Not callable");
|
||||
|
||||
static_assert(is_callable<is_callable_rank_class(int, callable_rank<4>)>::value, "Not callable");
|
||||
static_assert(is_callable<is_callable_rank_class(long, callable_rank<4>)>::value, "Not callable");
|
||||
static_assert(is_callable<is_callable_rank_class(double, callable_rank<4>)>::value, "Not callable");
|
||||
static_assert(is_callable<is_callable_rank_class(const int&, callable_rank<4>)>::value, "Not callable");
|
||||
static_assert(is_callable<is_callable_rank_class(const long&, callable_rank<4>)>::value, "Not callable");
|
||||
static_assert(is_callable<is_callable_rank_class(const double&, callable_rank<4>)>::value, "Not callable");
|
||||
|
||||
static_assert(is_callable<is_callable_rank_class(int, callable_rank<5>)>::value, "Not callable");
|
||||
static_assert(is_callable<is_callable_rank_class(long, callable_rank<5>)>::value, "Not callable");
|
||||
static_assert(is_callable<is_callable_rank_class(double, callable_rank<5>)>::value, "Not callable");
|
||||
static_assert(is_callable<is_callable_rank_class(const int&, callable_rank<5>)>::value, "Not callable");
|
||||
static_assert(is_callable<is_callable_rank_class(const long&, callable_rank<5>)>::value, "Not callable");
|
||||
static_assert(is_callable<is_callable_rank_class(const double&, callable_rank<5>)>::value, "Not callable");
|
||||
|
||||
static_assert(is_callable<is_callable_rank_class(int, callable_rank<6>)>::value, "Not callable");
|
||||
static_assert(is_callable<is_callable_rank_class(long, callable_rank<6>)>::value, "Not callable");
|
||||
static_assert(is_callable<is_callable_rank_class(double, callable_rank<6>)>::value, "Not callable");
|
||||
static_assert(is_callable<is_callable_rank_class(const int&, callable_rank<6>)>::value, "Not callable");
|
||||
static_assert(is_callable<is_callable_rank_class(const long&, callable_rank<6>)>::value, "Not callable");
|
||||
static_assert(is_callable<is_callable_rank_class(const double&, callable_rank<6>)>::value, "Not callable");
|
||||
|
||||
static_assert(not is_callable<is_callable_rank_class(int, callable_rank<1>)>::value, "callable failed");
|
||||
static_assert(not is_callable<is_callable_rank_class(long, callable_rank<1>)>::value, "callable failed");
|
||||
static_assert(not is_callable<is_callable_rank_class(double, callable_rank<1>)>::value, "callable failed");
|
||||
static_assert(not is_callable<is_callable_rank_class(const int&, callable_rank<1>)>::value, "callable failed");
|
||||
static_assert(not is_callable<is_callable_rank_class(const long&, callable_rank<1>)>::value, "callable failed");
|
||||
static_assert(not is_callable<is_callable_rank_class(const double&, callable_rank<1>)>::value, "callable failed");
|
||||
|
||||
static_assert(not is_callable<is_callable_rank_class(callable_test_param, callable_test_param)>::value, "callable failed");
|
||||
static_assert(not is_callable<is_callable_rank_class(callable_rank<3>, callable_test_param)>::value, "callable failed");
|
||||
static_assert(not is_callable<is_callable_rank_class(callable_rank<4>, callable_test_param)>::value, "callable failed");
|
||||
static_assert(not is_callable<is_callable_rank_class(callable_test_param, callable_rank<3>)>::value, "callable failed");
|
||||
static_assert(not is_callable<is_callable_rank_class(callable_test_param, callable_rank<4>)>::value, "callable failed");
|
||||
static_assert(not is_callable<is_callable_rank_class()>::value, "callable failed");
|
||||
static_assert(not is_callable<is_callable_rank_class(int, int)>::value, "callable failed");
|
||||
};
|
||||
|
||||
struct test2
|
||||
{
|
||||
typedef int(callable_rank<0>::*fn)(int);
|
||||
|
||||
static_assert(is_callable<fn(callable_rank<0>&, int)>::value, "Failed");
|
||||
static_assert(is_callable<fn(callable_rank<1>&, int)>::value, "Failed");
|
||||
static_assert(not is_callable<fn(callable_rank<0>&)>::value, "Failed");
|
||||
static_assert(not is_callable<fn(callable_rank<0> const&, int)>::value, "Failed");
|
||||
};
|
||||
|
||||
struct test3
|
||||
{
|
||||
typedef int(callable_rank<0>::*fn)(int);
|
||||
|
||||
typedef callable_rank<0>* T;
|
||||
typedef callable_rank<1>* DT;
|
||||
typedef const callable_rank<0>* CT;
|
||||
typedef std::unique_ptr<callable_rank<0>> ST;
|
||||
|
||||
static_assert(is_callable<fn(T&, int)>::value, "Failed");
|
||||
static_assert(is_callable<fn(DT&, int)>::value, "Failed");
|
||||
static_assert(is_callable<fn(const T&, int)>::value, "Failed");
|
||||
static_assert(is_callable<fn(T&&, int)>::value, "Failed");
|
||||
static_assert(is_callable<fn(ST, int)>::value, "Failed");
|
||||
static_assert(not is_callable<fn(CT&, int)>::value, "Failed");
|
||||
|
||||
};
|
||||
|
||||
struct test4
|
||||
{
|
||||
typedef int(callable_rank<0>::*fn);
|
||||
|
||||
static_assert(not is_callable<fn()>::value, "Failed");
|
||||
};
|
||||
|
||||
struct test5
|
||||
{
|
||||
typedef int(callable_rank<0>::*fn);
|
||||
|
||||
static_assert(is_callable<fn(callable_rank<0>&)>::value, "Failed");
|
||||
static_assert(is_callable<fn(callable_rank<0>&&)>::value, "Failed");
|
||||
static_assert(is_callable<fn(const callable_rank<0>&)>::value, "Failed");
|
||||
static_assert(is_callable<fn(callable_rank<1>&)>::value, "Failed");
|
||||
};
|
||||
|
||||
struct test6
|
||||
{
|
||||
typedef int(callable_rank<0>::*fn);
|
||||
|
||||
typedef callable_rank<0>* T;
|
||||
typedef callable_rank<1>* DT;
|
||||
typedef const callable_rank<0>* CT;
|
||||
typedef std::unique_ptr<callable_rank<0>> ST;
|
||||
|
||||
static_assert(is_callable<fn(T&)>::value, "Failed");
|
||||
static_assert(is_callable<fn(DT&)>::value, "Failed");
|
||||
static_assert(is_callable<fn(const T&)>::value, "Failed");
|
||||
static_assert(is_callable<fn(T&&)>::value, "Failed");
|
||||
static_assert(is_callable<fn(ST)>::value, "Failed");
|
||||
static_assert(is_callable<fn(CT&)>::value, "Failed");
|
||||
|
||||
};
|
||||
|
||||
struct test7
|
||||
{
|
||||
typedef void(*fp)(callable_rank<0>&, int);
|
||||
|
||||
static_assert(is_callable<fp(callable_rank<0>&, int)>::value, "Failed");
|
||||
static_assert(is_callable<fp(callable_rank<1>&, int)>::value, "Failed");
|
||||
static_assert(not is_callable<fp(const callable_rank<0>&, int)>::value, "Failed");
|
||||
static_assert(not is_callable<fp()>::value, "Failed");
|
||||
static_assert(not is_callable<fp(callable_rank<0>&)>::value, "Failed");
|
||||
};
|
||||
|
||||
struct test8
|
||||
{
|
||||
typedef void(&fp)(callable_rank<0>&, int);
|
||||
|
||||
static_assert(is_callable<fp(callable_rank<0>&, int)>::value, "Failed");
|
||||
static_assert(is_callable<fp(callable_rank<1>&, int)>::value, "Failed");
|
||||
static_assert(not is_callable<fp(const callable_rank<0>&, int)>::value, "Failed");
|
||||
static_assert(not is_callable<fp()>::value, "Failed");
|
||||
static_assert(not is_callable<fp(callable_rank<0>&)>::value, "Failed");
|
||||
};
|
||||
@@ -1,90 +0,0 @@
|
||||
/*
|
||||
Copyright (c) 2015 - 2021 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:
|
||||
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.
|
||||
*/
|
||||
|
||||
#include<cuda.h>
|
||||
#include<cuda_runtime.h>
|
||||
#include<iostream>
|
||||
#include<unistd.h>
|
||||
#include<stdio.h>
|
||||
#include<malloc.h>
|
||||
|
||||
#define LEN 1024
|
||||
#define SIZE LEN * sizeof(float)
|
||||
#define ITER 1024*1024
|
||||
|
||||
#define check(msg, status){ \
|
||||
if(status != cudaSuccess) { \
|
||||
printf("%s failed. \n", #msg); \
|
||||
} \
|
||||
}
|
||||
|
||||
__global__ void Inc1(float *Ad, float *Bd){
|
||||
int tx = threadIdx.x + blockIdx.x * blockDim.x;
|
||||
if(tx < 1 ){
|
||||
for(int i=0;i<ITER;i++){
|
||||
Ad[tx] = Ad[tx] + 1.0f;
|
||||
for(int j=0;j<256;j++){
|
||||
Bd[tx] = Ad[tx];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
__global__ void Inc2(float *Ad, float *Bd){
|
||||
int tx = threadIdx.x + blockIdx.x * blockDim.x;
|
||||
if(tx < 1024){
|
||||
for(int i=0;i<ITER;i++){
|
||||
Ad[tx] = Ad[tx] + 1.0f;
|
||||
for(int j=0;j<256;j++){
|
||||
Bd[tx] = Ad[tx];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int main(){
|
||||
float *A, *Ad, *Bd;
|
||||
A = new float[LEN];
|
||||
for(int i=0;i<LEN;i++){
|
||||
A[i] = 0.0f;
|
||||
}
|
||||
cudaError_t status;
|
||||
status = cudaHostRegister(A, SIZE, cudaHostRegisterMapped);
|
||||
check("Registering A",status);
|
||||
cudaHostGetDevicePointer(&Ad, A, 0);
|
||||
cudaMalloc((void**)&Bd, SIZE);
|
||||
dim3 dimGrid(LEN/256,1,1);
|
||||
dim3 dimBlock(256,1,1);
|
||||
Inc1<<<dimGrid, dimBlock>>>(Ad, Bd);
|
||||
sleep(3);
|
||||
A[0] = -(ITER*1.0f);
|
||||
std::cout<<"Same cache line before completion: \t"<< A[0]<<std::endl;
|
||||
cudaDeviceSynchronize();
|
||||
std::cout<<"Same cache line after completion: \t"<< A[0]<<std::endl;
|
||||
|
||||
for(int i=0;i<LEN;i++){
|
||||
A[i] = 0.0f;
|
||||
}
|
||||
Inc2<<<dimGrid, dimBlock>>>(Ad, Bd);
|
||||
sleep(3);
|
||||
A[0] = -(ITER*1.0f);
|
||||
std::cout<<"Diff cache line before completion: \t"<<A[0]<<std::endl;
|
||||
cudaDeviceSynchronize();
|
||||
std::cout<<"Diff cache line after completion: \t"<<A[0]<<std::endl;
|
||||
}
|
||||
@@ -1,137 +0,0 @@
|
||||
/*
|
||||
Copyright (c) 2015 - 2021 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:
|
||||
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.
|
||||
*/
|
||||
|
||||
/* HIT_START
|
||||
* BUILD: %t %s ../test_common.cpp NVCC_OPTIONS -std=c++11 EXCLUDE_HIP_PLATFORM nvidia
|
||||
* TEST: %t
|
||||
* HIT_END
|
||||
*/
|
||||
#include "test_common.h"
|
||||
#include <hip/hip_runtime.h>
|
||||
#include <hip/hip_bfloat16.h>
|
||||
#include <type_traits>
|
||||
#include <random>
|
||||
#include <climits>
|
||||
|
||||
#define SIZE 100
|
||||
using namespace std;
|
||||
|
||||
static random_device dev;
|
||||
static mt19937 rng(dev());
|
||||
|
||||
inline float getRandomFloat(long min = 10, long max = LONG_MAX) {
|
||||
uniform_real_distribution<float> gen(min, max);
|
||||
return gen(rng);
|
||||
}
|
||||
|
||||
__host__ __device__ bool testRelativeAccuracy(float a, hip_bfloat16 b) {
|
||||
float c = float(b);
|
||||
// float relative error should be less than 1/(2^7) since bfloat16
|
||||
// has 7 bits mantissa.
|
||||
if(fabs(c - a) / a <= 1.0 / 128){
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
__host__ __device__ void testOperations(float &fa, float &fb) {
|
||||
|
||||
hip_bfloat16 bf_a(fa);
|
||||
hip_bfloat16 bf_b(fb);
|
||||
float fc = float(bf_a);
|
||||
float fd = float(bf_b);
|
||||
|
||||
assert(testRelativeAccuracy(fa, bf_a));
|
||||
assert(testRelativeAccuracy(fb, bf_b));
|
||||
|
||||
assert(testRelativeAccuracy(fc + fd, bf_a + bf_b));
|
||||
//when checked as above for add, operation sub fails on GPU
|
||||
assert(hip_bfloat16(fc - fd) == (bf_a - bf_b));
|
||||
assert(testRelativeAccuracy(fc * fd, bf_a * bf_b));
|
||||
assert(testRelativeAccuracy(fc / fd, bf_a / bf_b));
|
||||
|
||||
hip_bfloat16 bf_opNegate = -bf_a;
|
||||
assert(bf_opNegate == -bf_a);
|
||||
|
||||
hip_bfloat16 bf_x;
|
||||
bf_x = bf_a;
|
||||
bf_x++;
|
||||
bf_x--;
|
||||
++bf_x;
|
||||
--bf_x;
|
||||
//hip_bfloat16 is converted to float and then inc/decremented, hence check with reduced precision
|
||||
assert(testRelativeAccuracy(bf_x,bf_a));
|
||||
|
||||
bf_x = bf_a;
|
||||
bf_x += bf_b;
|
||||
assert(bf_x == (bf_a + bf_b));
|
||||
bf_x = bf_a;
|
||||
bf_x -= bf_b;
|
||||
assert(bf_x == (bf_a - bf_b));
|
||||
bf_x = bf_a;
|
||||
bf_x *= bf_b;
|
||||
assert(bf_x == (bf_a * bf_b));
|
||||
bf_x = bf_a;
|
||||
bf_x /= bf_b;
|
||||
assert(bf_x == (bf_a / bf_b));
|
||||
|
||||
hip_bfloat16 bf_rounded = hip_bfloat16::round_to_bfloat16(fa);
|
||||
if (isnan(bf_rounded)) {
|
||||
assert(isnan(bf_rounded) || isinf(bf_rounded));
|
||||
}
|
||||
}
|
||||
|
||||
__global__ void testOperationsGPU(float* d_a, float* d_b)
|
||||
{
|
||||
int id = threadIdx.x;
|
||||
if (id > SIZE) return;
|
||||
float &a = d_a[id];
|
||||
float &b = d_b[id];
|
||||
testOperations(a, b);
|
||||
}
|
||||
|
||||
int main(){
|
||||
float *h_fa, *h_fb;
|
||||
float *d_fa, *d_fb;
|
||||
|
||||
h_fa = new float[SIZE];
|
||||
h_fb = new float[SIZE];
|
||||
for (int i = 0; i < SIZE; i++) {
|
||||
h_fa[i] = getRandomFloat();
|
||||
h_fb[i] = getRandomFloat();
|
||||
testOperations(h_fa[i], h_fb[i]);
|
||||
}
|
||||
cout<<"Host bfloat16 Operations Successful!!"<<endl;
|
||||
hipMalloc(&d_fa, sizeof(float) * SIZE);
|
||||
hipMalloc(&d_fb, sizeof(float) * SIZE);
|
||||
|
||||
hipMemcpy(d_fa, h_fa, sizeof(float) * SIZE, hipMemcpyHostToDevice);
|
||||
hipMemcpy(d_fb, h_fb, sizeof(float) * SIZE, hipMemcpyHostToDevice);
|
||||
|
||||
hipLaunchKernelGGL(testOperationsGPU, 1, SIZE, 0, 0, d_fa, d_fb);
|
||||
hipDeviceSynchronize();
|
||||
cout<<"Device bfloat16 Operations Successful!!"<<endl;
|
||||
|
||||
delete[] h_fa;
|
||||
delete[] h_fb;
|
||||
hipFree(d_fa);
|
||||
hipFree(d_fb);
|
||||
passed();
|
||||
return 1;
|
||||
}
|
||||
@@ -1,527 +0,0 @@
|
||||
/*
|
||||
Copyright (c) 2020 - 2021 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:
|
||||
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 WARRANNTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INNCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANNY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER INN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR INN 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
|
||||
* TEST: %t --tests 0x01
|
||||
* TEST: %t --tests 0x02
|
||||
* TEST: %t --tests 0x03
|
||||
* TEST: %t --tests 0x04
|
||||
* TEST: %t --tests 0x05
|
||||
* TEST: %t --tests 0x06
|
||||
* TEST: %t --tests 0x07
|
||||
* TEST: %t --tests 0x08
|
||||
* TEST: %t --tests 0x09
|
||||
* TEST: %t --tests 0x0A
|
||||
* TEST: %t --tests 0x0B
|
||||
* TEST: %t --tests 0x0C
|
||||
* TEST: %t --tests 0x0D
|
||||
* TEST: %t --tests 0x0E
|
||||
* TEST: %t --tests 0x0F
|
||||
* TEST: %t --tests 0x10
|
||||
* TEST: %t --tests 0x11
|
||||
* TEST: %t --tests 0x12
|
||||
* TEST: %t --tests 0x13
|
||||
* TEST: %t --tests 0x14
|
||||
* TEST: %t --tests 0x15
|
||||
* TEST: %t --tests 0x16
|
||||
* TEST: %t --tests 0x17
|
||||
* HIT_END
|
||||
*/
|
||||
#include <math.h>
|
||||
#include <iostream>
|
||||
#include <type_traits>
|
||||
#include "test_common.h"
|
||||
#include "hip/hip_complex.h"
|
||||
|
||||
#define LEN 64
|
||||
/* Comparing 2 floating point/double variables using floating point
|
||||
precision. The precision is set at compile time using EPSILON. */
|
||||
#define COMPARE_REALNUM(A, B, EPSILON) (fabs(A-B) < EPSILON)
|
||||
|
||||
enum ComplexFuncType {
|
||||
COMPLEX_ADD,
|
||||
COMPLEX_SUB,
|
||||
COMPLEX_MUL,
|
||||
COMPLEX_DIV,
|
||||
COMPLEX_CONJ,
|
||||
COMPLEX_REAL,
|
||||
COMPLEX_IMAG,
|
||||
COMPLEX_SQABS,
|
||||
COMPLEX_ABS
|
||||
};
|
||||
|
||||
__global__ void testMakeComplexFunc(float* A, float* B,
|
||||
hipFloatComplex* C) {
|
||||
int tx = threadIdx.x + blockIdx.x * blockDim.x;
|
||||
C[tx] = make_hipFloatComplex(A[tx], B[tx]);
|
||||
}
|
||||
|
||||
__global__ void testMakeComplexFunc(double* A, double* B,
|
||||
hipDoubleComplex* C) {
|
||||
int tx = threadIdx.x + blockIdx.x * blockDim.x;
|
||||
C[tx] = make_hipDoubleComplex(A[tx], B[tx]);
|
||||
}
|
||||
|
||||
__global__ void testComplexMathFunc1(hipFloatComplex* A,
|
||||
hipFloatComplex* B,
|
||||
hipFloatComplex* C,
|
||||
enum ComplexFuncType type) {
|
||||
int tx = threadIdx.x + blockIdx.x * blockDim.x;
|
||||
switch (type) {
|
||||
case COMPLEX_ADD:
|
||||
C[tx] = hipCaddf(A[tx], B[tx]);
|
||||
break;
|
||||
case COMPLEX_SUB:
|
||||
C[tx] = hipCsubf(A[tx], B[tx]);
|
||||
break;
|
||||
case COMPLEX_MUL:
|
||||
C[tx] = hipCmulf(A[tx], B[tx]);
|
||||
break;
|
||||
case COMPLEX_DIV:
|
||||
C[tx] = hipCdivf(A[tx], B[tx]);
|
||||
break;
|
||||
case COMPLEX_CONJ:
|
||||
C[tx] = hipConjf(A[tx]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
__global__ void testComplexMathFunc1(hipDoubleComplex* A,
|
||||
hipDoubleComplex* B,
|
||||
hipDoubleComplex* C,
|
||||
enum ComplexFuncType type) {
|
||||
int tx = threadIdx.x + blockIdx.x * blockDim.x;
|
||||
switch (type) {
|
||||
case COMPLEX_ADD:
|
||||
C[tx] = hipCadd(A[tx], B[tx]);
|
||||
break;
|
||||
case COMPLEX_SUB:
|
||||
C[tx] = hipCsub(A[tx], B[tx]);
|
||||
break;
|
||||
case COMPLEX_MUL:
|
||||
C[tx] = hipCmul(A[tx], B[tx]);
|
||||
break;
|
||||
case COMPLEX_DIV:
|
||||
C[tx] = hipCdiv(A[tx], B[tx]);
|
||||
break;
|
||||
case COMPLEX_CONJ:
|
||||
C[tx] = hipConj(A[tx]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
__global__ void testComplexMathFunc2(hipFloatComplex* A,
|
||||
float* B,
|
||||
enum ComplexFuncType type) {
|
||||
int tx = threadIdx.x + blockIdx.x * blockDim.x;
|
||||
switch (type) {
|
||||
case COMPLEX_REAL:
|
||||
B[tx] = hipCrealf(A[tx]);
|
||||
break;
|
||||
case COMPLEX_IMAG:
|
||||
B[tx] = hipCimagf(A[tx]);
|
||||
break;
|
||||
case COMPLEX_SQABS:
|
||||
B[tx] = hipCsqabsf(A[tx]);
|
||||
break;
|
||||
case COMPLEX_ABS:
|
||||
B[tx] = hipCabsf(A[tx]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
__global__ void testComplexMathFunc2(hipDoubleComplex* A,
|
||||
double* B,
|
||||
enum ComplexFuncType type) {
|
||||
int tx = threadIdx.x + blockIdx.x * blockDim.x;
|
||||
switch (type) {
|
||||
case COMPLEX_REAL:
|
||||
B[tx] = hipCreal(A[tx]);
|
||||
break;
|
||||
case COMPLEX_IMAG:
|
||||
B[tx] = hipCimag(A[tx]);
|
||||
break;
|
||||
case COMPLEX_SQABS:
|
||||
B[tx] = hipCsqabs(A[tx]);
|
||||
break;
|
||||
case COMPLEX_ABS:
|
||||
B[tx] = hipCabs(A[tx]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Validates all hipComplex inline functions on device
|
||||
* Functions validated are: make_hipDoubleComplex, make_hipFloatComplex
|
||||
*/
|
||||
template<typename T1, typename T2> bool test_makehipComplex_dev() {
|
||||
T2 *A, *Ad, *B, *Bd;
|
||||
T1 *C, *Cd;
|
||||
bool TestPassed = true;
|
||||
A = new T2[LEN];
|
||||
B = new T2[LEN];
|
||||
C = new T1[LEN];
|
||||
for (uint32_t i = 0; i < LEN; i++) {
|
||||
A[i] = 2*i*1.0;
|
||||
B[i] = (2*i + 1)*1.0;
|
||||
}
|
||||
unsigned int size2 = LEN * sizeof(T2);
|
||||
unsigned int size1 = LEN * sizeof(T1);
|
||||
HIPCHECK(hipMalloc(reinterpret_cast<void**>(&Ad), size2));
|
||||
HIPCHECK(hipMalloc(reinterpret_cast<void**>(&Bd), size2));
|
||||
HIPCHECK(hipMalloc(reinterpret_cast<void**>(&Cd), size1));
|
||||
HIPCHECK(hipMemcpy(Ad, A, size2, hipMemcpyHostToDevice));
|
||||
HIPCHECK(hipMemcpy(Bd, B, size2, hipMemcpyHostToDevice));
|
||||
hipLaunchKernelGGL(testMakeComplexFunc, dim3(1), dim3(LEN),
|
||||
0, 0, Ad, Bd, Cd);
|
||||
HIPCHECK(hipMemcpy(C, Cd, size1, hipMemcpyDeviceToHost));
|
||||
// Validate the output of the kernel functions.
|
||||
for (uint32_t i = 0; i < LEN; i++) {
|
||||
if ((A[i] != C[i].x) || (B[i] != C[i].y)) {
|
||||
TestPassed = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
HIPCHECK(hipFree(Cd));
|
||||
HIPCHECK(hipFree(Bd));
|
||||
HIPCHECK(hipFree(Ad));
|
||||
delete[] C;
|
||||
delete[] B;
|
||||
delete[] A;
|
||||
return TestPassed;
|
||||
}
|
||||
/**
|
||||
* Validates all hipComplex inline functions on device
|
||||
* Functions validated are: hipCaddf, hipCsubf, hipCmulf and hipCdivf
|
||||
* hipCadd, hipCsub, hipCmul, hipCdiv
|
||||
*/
|
||||
template<typename T1, typename T2>
|
||||
bool test_complexMathFunc1_dev(enum ComplexFuncType mathFuncType) {
|
||||
T1 *A, *Ad, *B, *Bd;
|
||||
T1 *C, *Cd;
|
||||
bool TestPassed = true;
|
||||
A = new T1[LEN];
|
||||
B = new T1[LEN];
|
||||
C = new T1[LEN];
|
||||
for (uint32_t i = 0; i < LEN; i++) {
|
||||
A[i].x = 2*i*1.0;
|
||||
A[i].y = (2*i + 1)*1.0;
|
||||
B[i].x = 2*i*1.0 + 0.5;
|
||||
B[i].y = (2*i + 1)*1.0 + 0.5;
|
||||
}
|
||||
unsigned int size = LEN * sizeof(T1);
|
||||
HIPCHECK(hipMalloc(reinterpret_cast<void**>(&Ad), size));
|
||||
HIPCHECK(hipMalloc(reinterpret_cast<void**>(&Bd), size));
|
||||
HIPCHECK(hipMalloc(reinterpret_cast<void**>(&Cd), size));
|
||||
HIPCHECK(hipMemcpy(Ad, A, size, hipMemcpyHostToDevice));
|
||||
HIPCHECK(hipMemcpy(Bd, B, size, hipMemcpyHostToDevice));
|
||||
hipLaunchKernelGGL(testComplexMathFunc1, dim3(1), dim3(LEN),
|
||||
0, 0, Ad, Bd, Cd, mathFuncType);
|
||||
HIPCHECK(hipMemcpy(C, Cd, size, hipMemcpyDeviceToHost));
|
||||
// Validate the output of the kernel functions.
|
||||
T2 epsilon = 0.0001f;
|
||||
T2 real, imag;
|
||||
for (uint32_t i = 0; i < LEN; i++) {
|
||||
if (mathFuncType == COMPLEX_ADD) {
|
||||
real = (A[i].x + B[i].x);
|
||||
imag = (A[i].y + B[i].y);
|
||||
} else if (mathFuncType == COMPLEX_SUB) {
|
||||
real = (A[i].x - B[i].x);
|
||||
imag = (A[i].y - B[i].y);
|
||||
} else if (mathFuncType == COMPLEX_MUL) {
|
||||
real = (A[i].x*B[i].x - A[i].y*B[i].y);
|
||||
imag = (A[i].y*B[i].x + A[i].x*B[i].y);
|
||||
} else if (mathFuncType == COMPLEX_DIV) {
|
||||
T2 sqabs = (B[i].x*B[i].x + B[i].y*B[i].y);
|
||||
real = (A[i].x * B[i].x + A[i].y * B[i].y)/sqabs;
|
||||
imag = (A[i].y * B[i].x - A[i].x * B[i].y)/sqabs;
|
||||
} else if (mathFuncType == COMPLEX_CONJ) {
|
||||
real = A[i].x;
|
||||
imag = -A[i].y;
|
||||
}
|
||||
if (!COMPARE_REALNUM(real, C[i].x, epsilon) ||
|
||||
!COMPARE_REALNUM(imag, C[i].y, epsilon)) {
|
||||
TestPassed = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
HIPCHECK(hipFree(Cd));
|
||||
HIPCHECK(hipFree(Bd));
|
||||
HIPCHECK(hipFree(Ad));
|
||||
delete[] C;
|
||||
delete[] B;
|
||||
delete[] A;
|
||||
return TestPassed;
|
||||
}
|
||||
/**
|
||||
* Validates all hipComplex inline functions on device
|
||||
* Functions validated are: hipCrealf, hipCimagf, hipCsqabsf and hipCabsf
|
||||
* hipCreal, hipCimag, hipCsqabs, hipCabs
|
||||
*/
|
||||
template<typename T1, typename T2>
|
||||
bool test_complexMathFunc2_dev(enum ComplexFuncType mathFuncType) {
|
||||
T1 *A, *Ad;
|
||||
T2 *B, *Bd;
|
||||
bool TestPassed = true;
|
||||
A = new T1[LEN];
|
||||
B = new T2[LEN];
|
||||
for (uint32_t i = 0; i < LEN; i++) {
|
||||
A[i].x = 2*i*1.0;
|
||||
A[i].y = (2*i + 1)*1.0;
|
||||
}
|
||||
unsigned int size1 = LEN * sizeof(T1);
|
||||
unsigned int size2 = LEN * sizeof(T2);
|
||||
HIPCHECK(hipMalloc(reinterpret_cast<void**>(&Ad), size1));
|
||||
HIPCHECK(hipMalloc(reinterpret_cast<void**>(&Bd), size2));
|
||||
HIPCHECK(hipMemcpy(Ad, A, size1, hipMemcpyHostToDevice));
|
||||
hipLaunchKernelGGL(testComplexMathFunc2, dim3(1), dim3(LEN),
|
||||
0, 0, Ad, Bd, mathFuncType);
|
||||
HIPCHECK(hipMemcpy(B, Bd, size2, hipMemcpyDeviceToHost));
|
||||
// Validate the output of the kernel functions.
|
||||
T2 epsilon = 0.0001f;
|
||||
if (mathFuncType == COMPLEX_REAL) {
|
||||
for (uint32_t i = 0; i < LEN; i++) {
|
||||
if (!COMPARE_REALNUM(A[i].x, B[i], epsilon)) {
|
||||
TestPassed = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else if (mathFuncType == COMPLEX_IMAG) {
|
||||
for (uint32_t i = 0; i < LEN; i++) {
|
||||
if (!COMPARE_REALNUM(A[i].y, B[i], epsilon)) {
|
||||
TestPassed = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else if (mathFuncType == COMPLEX_SQABS) {
|
||||
for (uint32_t i = 0; i < LEN; i++) {
|
||||
T2 sqabs = A[i].x * A[i].x + A[i].y * A[i].y;
|
||||
#ifdef __HIP_PLATFORM_NVCC__
|
||||
/* Setting the Floating Point precision to 0.01 as this scenario
|
||||
is failing on NVIDIA targets. */
|
||||
epsilon = 0.01f;
|
||||
#endif
|
||||
if (!COMPARE_REALNUM(sqabs, B[i], epsilon)) {
|
||||
TestPassed = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else if (mathFuncType == COMPLEX_ABS) {
|
||||
for (uint32_t i = 0; i < LEN; i++) {
|
||||
T2 sqabs = A[i].x * A[i].x + A[i].y * A[i].y;
|
||||
if (!COMPARE_REALNUM(sqrtf(sqabs), B[i], epsilon)) {
|
||||
TestPassed = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
HIPCHECK(hipFree(Bd));
|
||||
HIPCHECK(hipFree(Ad));
|
||||
delete[] B;
|
||||
delete[] A;
|
||||
return TestPassed;
|
||||
}
|
||||
/**
|
||||
* Validates all hipComplex inline functions on host
|
||||
*/
|
||||
bool test_allcomplexMathFunc_host() {
|
||||
bool TestPassed = true;
|
||||
float fa = 2.0, fb = 3.0;
|
||||
hipFloatComplex fc = make_hipFloatComplex(fa, fb);
|
||||
if ((fc.x != fa) || (fc.y != fb)) {
|
||||
printf("make_hipFloatComplex test failed. \n");
|
||||
TestPassed &= false;
|
||||
}
|
||||
double da = 2.0, db = 3.0;
|
||||
hipDoubleComplex dc = make_hipDoubleComplex(da, db);
|
||||
if ((dc.x != da) || (dc.y != db)) {
|
||||
printf("make_hipDoubleComplex test failed. \n");
|
||||
TestPassed &= false;
|
||||
}
|
||||
hipFloatComplex fp, fq, fx;
|
||||
fp.x = 2.0;
|
||||
fp.y = 3.0;
|
||||
fq.x = 4.0;
|
||||
fq.y = 5.0;
|
||||
fx = hipCaddf(fp, fq);
|
||||
if ((fx.x != (fp.x + fq.x)) || (fx.y != (fp.y + fq.y))) {
|
||||
printf("hipCaddf test failed. \n");
|
||||
TestPassed &= false;
|
||||
}
|
||||
fx = hipCsubf(fp, fq);
|
||||
if ((fx.x != (fp.x - fq.x)) || (fx.y != (fp.y - fq.y))) {
|
||||
printf("hipCsubf test failed. \n");
|
||||
TestPassed &= false;
|
||||
}
|
||||
fx = hipCmulf(fp, fq);
|
||||
if ((fx.x != (fp.x*fq.x - fp.y*fq.y)) ||
|
||||
(fx.y != (fp.y*fq.x + fp.x*fq.y))) {
|
||||
printf("hipCmulf test failed. \n");
|
||||
TestPassed &= false;
|
||||
}
|
||||
fx = hipCdivf(fp, fq);
|
||||
float fsqabs = fq.x*fq.x + fq.y*fq.y;
|
||||
float epsilon = 0.0001f;
|
||||
if ((!COMPARE_REALNUM(fx.x, (fp.x*fq.x + fp.y*fq.y)/fsqabs, epsilon)) ||
|
||||
(!COMPARE_REALNUM(fx.y, (fp.y*fq.x - fp.x*fq.y)/fsqabs, epsilon))) {
|
||||
printf("hipCdivf test failed. \n");
|
||||
TestPassed &= false;
|
||||
}
|
||||
if ((fp.x != hipCrealf(fp)) || (fp.y != hipCimagf(fp))) {
|
||||
printf("hipCrealf/hipCimagf test failed. \n");
|
||||
TestPassed &= false;
|
||||
}
|
||||
fx = hipConjf(fp);
|
||||
if ((fx.x != fp.x) || (fx.y != -fp.y)) {
|
||||
printf("hipConjf test failed. \n");
|
||||
TestPassed &= false;
|
||||
}
|
||||
if (!COMPARE_REALNUM((fp.x*fp.x + fp.y*fp.y), hipCsqabsf(fp), epsilon)) {
|
||||
printf("hipCsqabsf test failed. \n");
|
||||
TestPassed &= false;
|
||||
}
|
||||
if (!COMPARE_REALNUM(sqrtf(fp.x*fp.x + fp.y*fp.y), hipCabsf(fp), epsilon)) {
|
||||
printf("hipCabsf test failed. \n");
|
||||
TestPassed &= false;
|
||||
}
|
||||
hipDoubleComplex dp, dq, dx;
|
||||
dp.x = 2.0;
|
||||
dp.y = 3.0;
|
||||
dq.x = 4.0;
|
||||
dq.y = 5.0;
|
||||
dx = hipCadd(dp, dq);
|
||||
if ((dx.x != (dp.x + dq.x)) || (dx.y != (dp.y + dq.y))) {
|
||||
printf("hipCadd test failed. \n");
|
||||
TestPassed &= false;
|
||||
}
|
||||
dx = hipCsub(dp, dq);
|
||||
if ((dx.x != (dp.x - dq.x)) || (dx.y != (dp.y - dq.y))) {
|
||||
printf("hipCsub test failed. \n");
|
||||
TestPassed &= false;
|
||||
}
|
||||
dx = hipCmul(dp, dq);
|
||||
if ((dx.x != (dp.x*dq.x - dp.y*dq.y)) ||
|
||||
(dx.y != (dp.y*dq.x + dp.x*dq.y))) {
|
||||
printf("hipCmul test failed. \n");
|
||||
TestPassed &= false;
|
||||
}
|
||||
dx = hipCdiv(dp, dq);
|
||||
float dsqabs = dq.x*dq.x + dq.y*dq.y;
|
||||
if ((!COMPARE_REALNUM(dx.x, (dp.x*dq.x + dp.y*dq.y)/dsqabs, epsilon)) ||
|
||||
(!COMPARE_REALNUM(dx.y, (dp.y*dq.x - dp.x*dq.y)/dsqabs, epsilon))) {
|
||||
printf("hipCdiv test failed. \n");
|
||||
TestPassed &= false;
|
||||
}
|
||||
if ((dp.x != hipCreal(dp)) || (dp.y != hipCimag(dp))) {
|
||||
printf("hipCreal/hipCimag test failed. \n");
|
||||
TestPassed &= false;
|
||||
}
|
||||
dx = hipConj(dp);
|
||||
if ((dx.x != dp.x) || (dx.y != -dp.y)) {
|
||||
printf("hipConj test failed. \n");
|
||||
TestPassed &= false;
|
||||
}
|
||||
if (!COMPARE_REALNUM((dp.x*dp.x + dp.y*dp.y), hipCsqabs(dp), epsilon)) {
|
||||
printf("hipCsqabs test failed. \n");
|
||||
TestPassed &= false;
|
||||
}
|
||||
if (!COMPARE_REALNUM(sqrtf(dp.x*dp.x + dp.y*dp.y), hipCabs(dp), epsilon)) {
|
||||
printf("hipCabs test failed. \n");
|
||||
TestPassed &= false;
|
||||
}
|
||||
return TestPassed;
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
HipTest::parseStandardArguments(argc, argv, true);
|
||||
bool TestPassed = true;
|
||||
if (p_tests == 0x01) {
|
||||
TestPassed = test_makehipComplex_dev<hipFloatComplex, float>();
|
||||
} else if (p_tests == 0x02) {
|
||||
TestPassed = test_makehipComplex_dev<float2, float>();
|
||||
} else if (p_tests == 0x03) {
|
||||
TestPassed = test_makehipComplex_dev<hipDoubleComplex, double>();
|
||||
} else if (p_tests == 0x04) {
|
||||
TestPassed = test_makehipComplex_dev<double2, double>();
|
||||
} else if (p_tests == 0x05) {
|
||||
TestPassed =
|
||||
test_complexMathFunc1_dev<hipFloatComplex, float>(COMPLEX_ADD);
|
||||
} else if (p_tests == 0x06) {
|
||||
TestPassed =
|
||||
test_complexMathFunc1_dev<hipDoubleComplex, double>(COMPLEX_ADD);
|
||||
} else if (p_tests == 0x07) {
|
||||
TestPassed =
|
||||
test_complexMathFunc1_dev<hipFloatComplex, float>(COMPLEX_SUB);
|
||||
} else if (p_tests == 0x08) {
|
||||
TestPassed =
|
||||
test_complexMathFunc1_dev<hipDoubleComplex, double>(COMPLEX_SUB);
|
||||
} else if (p_tests == 0x09) {
|
||||
TestPassed =
|
||||
test_complexMathFunc1_dev<hipFloatComplex, float>(COMPLEX_MUL);
|
||||
} else if (p_tests == 0x0A) {
|
||||
TestPassed =
|
||||
test_complexMathFunc1_dev<hipDoubleComplex, double>(COMPLEX_MUL);
|
||||
} else if (p_tests == 0x0B) {
|
||||
TestPassed =
|
||||
test_complexMathFunc1_dev<hipFloatComplex, float>(COMPLEX_DIV);
|
||||
} else if (p_tests == 0x0C) {
|
||||
TestPassed =
|
||||
test_complexMathFunc1_dev<hipDoubleComplex, double>(COMPLEX_DIV);
|
||||
} else if (p_tests == 0x0D) {
|
||||
TestPassed =
|
||||
test_complexMathFunc1_dev<hipFloatComplex, float>(COMPLEX_CONJ);
|
||||
} else if (p_tests == 0x0E) {
|
||||
TestPassed =
|
||||
test_complexMathFunc1_dev<hipDoubleComplex, double>(COMPLEX_CONJ);
|
||||
} else if (p_tests == 0x0F) {
|
||||
TestPassed =
|
||||
test_complexMathFunc2_dev<hipFloatComplex, float>(COMPLEX_REAL);
|
||||
} else if (p_tests == 0x10) {
|
||||
TestPassed =
|
||||
test_complexMathFunc2_dev<hipDoubleComplex, double>(COMPLEX_REAL);
|
||||
} else if (p_tests == 0x11) {
|
||||
TestPassed =
|
||||
test_complexMathFunc2_dev<hipFloatComplex, float>(COMPLEX_IMAG);
|
||||
} else if (p_tests == 0x12) {
|
||||
TestPassed =
|
||||
test_complexMathFunc2_dev<hipDoubleComplex, double>(COMPLEX_IMAG);
|
||||
} else if (p_tests == 0x13) {
|
||||
TestPassed =
|
||||
test_complexMathFunc2_dev<hipFloatComplex, float>(COMPLEX_SQABS);
|
||||
} else if (p_tests == 0x14) {
|
||||
TestPassed =
|
||||
test_complexMathFunc2_dev<hipDoubleComplex, double>(COMPLEX_SQABS);
|
||||
} else if (p_tests == 0x15) {
|
||||
TestPassed =
|
||||
test_complexMathFunc2_dev<hipFloatComplex, float>(COMPLEX_ABS);
|
||||
} else if (p_tests == 0x16) {
|
||||
TestPassed =
|
||||
test_complexMathFunc2_dev<hipDoubleComplex, double>(COMPLEX_ABS);
|
||||
} else if (p_tests == 0x17) {
|
||||
TestPassed = test_allcomplexMathFunc_host();
|
||||
} else {
|
||||
printf("Invalid Test Case \n");
|
||||
passed();
|
||||
}
|
||||
if (TestPassed) {
|
||||
passed();
|
||||
} else {
|
||||
failed("Test Case %x Failed!", p_tests);
|
||||
}
|
||||
}
|
||||
@@ -1,188 +0,0 @@
|
||||
/*
|
||||
Copyright (c) 2015 - 2021 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:
|
||||
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 WARRANNTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INNCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANNY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER INN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR INN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
/* HIT_START
|
||||
* BUILD: %t %s ../../src/test_common.cpp
|
||||
* TEST: %t
|
||||
* HIT_END
|
||||
*/
|
||||
#include "test_common.h"
|
||||
#include <iostream>
|
||||
#include <complex>
|
||||
|
||||
// Tolerance for error
|
||||
const double tolerance = 1e-6;
|
||||
const bool verbose = false;
|
||||
|
||||
#define BLKDIM_X 64
|
||||
#define BLKDIM_Y 1
|
||||
#define BLKDIM_Z 1
|
||||
#define NUM_BLK_X 1
|
||||
#define NUM_BLK_Y 1
|
||||
#define NUM_BLK_Z 1
|
||||
|
||||
#define LEN (BLKDIM_X * BLKDIM_Y * BLKDIM_Z * NUM_BLK_X * NUM_BLK_Y * NUM_BLK_Z)
|
||||
|
||||
#define ALL_FUN \
|
||||
OP(add) \
|
||||
OP(sub) \
|
||||
OP(mul) \
|
||||
OP(div)
|
||||
|
||||
#define OP(x) CK_##x,
|
||||
enum CalcKind {
|
||||
ALL_FUN
|
||||
};
|
||||
#undef OP
|
||||
|
||||
#define OP(x) case CK_##x: return #x;
|
||||
std::string getName(enum CalcKind CK) {
|
||||
switch(CK){
|
||||
ALL_FUN
|
||||
}
|
||||
}
|
||||
#undef OP
|
||||
|
||||
// Calculates function.
|
||||
// If the function has one argument, B is ignored.
|
||||
#define ONE_ARG(func) \
|
||||
case CK_##func: \
|
||||
return std::func(A);
|
||||
|
||||
template <typename FloatT>
|
||||
__device__ __host__ FloatT calc(FloatT A, FloatT B, enum CalcKind CK) {
|
||||
switch (CK) {
|
||||
case CK_add:
|
||||
return A + B;
|
||||
case CK_sub:
|
||||
return A - B;
|
||||
case CK_mul:
|
||||
return A * B;
|
||||
case CK_div:
|
||||
return A / B;
|
||||
}
|
||||
}
|
||||
|
||||
// Allocate memory in kernel and save the address to pA and pB.
|
||||
// Copy value from A, B to allocated memory.
|
||||
template <typename FloatT>
|
||||
__global__ void kernel_alloc(FloatT* A, FloatT* B, FloatT** pA, FloatT** pB) {
|
||||
int tx = threadIdx.x + blockDim.x * blockIdx.x
|
||||
+ (threadIdx.y + blockDim.y * blockIdx.y) * blockDim.x
|
||||
+ (threadIdx.z + blockDim.z * blockIdx.z) * blockDim.x
|
||||
* blockDim.y;
|
||||
if (tx == 0) {
|
||||
*pA = (FloatT*)malloc(sizeof(FloatT) * LEN);
|
||||
*pB = (FloatT*)malloc(sizeof(FloatT) * LEN);
|
||||
for (int i = 0; i < LEN; i++) {
|
||||
(*pA)[i] = A[i];
|
||||
(*pB)[i] = B[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Do calculation using values saved in allocated memmory. pA, pB are buffers
|
||||
// containing the address of the device-side allocated array.
|
||||
template <typename FloatT>
|
||||
__global__ void kernel_free(FloatT** pA, FloatT** pB, FloatT* C, enum CalcKind CK) {
|
||||
int tx = threadIdx.x + blockDim.x * blockIdx.x
|
||||
+ (threadIdx.y + blockDim.y * blockIdx.y) * blockDim.x
|
||||
+ (threadIdx.z + blockDim.z * blockIdx.z) * blockDim.x
|
||||
* blockDim.y;
|
||||
C[tx] = calc<FloatT>((*pA)[tx], (*pB)[tx], CK);
|
||||
if (tx == 0) {
|
||||
free(*pA);
|
||||
free(*pB);
|
||||
}
|
||||
}
|
||||
|
||||
template<typename FloatT>
|
||||
void test() {
|
||||
FloatT *A, *Ad, *B, *Bd, *C, *Cd, *D;
|
||||
A = new FloatT[LEN];
|
||||
B = new FloatT[LEN];
|
||||
C = new FloatT[LEN];
|
||||
D = new FloatT[LEN];
|
||||
hipMalloc((void**)&Ad, sizeof(FloatT) * LEN);
|
||||
hipMalloc((void**)&Bd, sizeof(FloatT) * LEN);
|
||||
hipMalloc((void**)&Cd, sizeof(FloatT) * LEN);
|
||||
|
||||
for (uint32_t i = 0; i < LEN; i++) {
|
||||
A[i] = (i + 1) * 1.0f;
|
||||
B[i] = A[i];
|
||||
C[i] = A[i];
|
||||
}
|
||||
hipMemcpy(Ad, A, sizeof(FloatT) * LEN, hipMemcpyHostToDevice);
|
||||
hipMemcpy(Bd, B, sizeof(FloatT) * LEN, hipMemcpyHostToDevice);
|
||||
|
||||
// Run kernel for a calculation kind and verify by comparing with host
|
||||
// calculation result. Returns false if fails.
|
||||
auto test_fun = [&](enum CalcKind CK) {
|
||||
// kernel_alloc allocates memory on device side and initialize it.
|
||||
// kernel_free uses allocated memory from kernel_alloc and does the
|
||||
// calculation then free the memory.
|
||||
// pA and pB are buffers to pass the device-side allocated memory address
|
||||
// from kernel_alloc to kernel_free.
|
||||
FloatT **pA, **pB;
|
||||
hipMalloc((FloatT***)&pA, sizeof(FloatT*));
|
||||
hipMalloc((FloatT***)&pB, sizeof(FloatT*));
|
||||
dim3 blkDim(BLKDIM_X, BLKDIM_Y, BLKDIM_Z);
|
||||
dim3 numBlk(NUM_BLK_X, NUM_BLK_Y, NUM_BLK_Z);
|
||||
hipLaunchKernelGGL(kernel_alloc<FloatT>, numBlk, blkDim, 0, 0,
|
||||
Ad, Bd, pA, pB);
|
||||
hipDeviceSynchronize();
|
||||
hipLaunchKernelGGL(kernel_free<FloatT>, numBlk, blkDim, 0, 0,
|
||||
pA, pB, Cd, CK);
|
||||
hipMemcpy(C, Cd, sizeof(FloatT) * LEN, hipMemcpyDeviceToHost);
|
||||
hipFree(pA);
|
||||
hipFree(pB);
|
||||
for (int i = 0; i < LEN; i++) {
|
||||
FloatT Expected = calc(A[i], B[i], CK);
|
||||
FloatT error = std::abs(C[i] - Expected);
|
||||
if (std::abs(Expected) > tolerance) error /= std::abs(Expected);
|
||||
bool pass = error < tolerance;
|
||||
if (verbose || !pass) {
|
||||
std::cout << "Function: " << getName(CK) << " Operands: " << A[i] << " " << B[i]
|
||||
<< " Result: " << C[i] << " Expected: " << Expected << " Error: " << error
|
||||
<< " Pass: " << pass << std::endl;
|
||||
}
|
||||
if (!pass)
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
};
|
||||
|
||||
#define OP(x) assert(test_fun(CK_##x));
|
||||
ALL_FUN
|
||||
#undef OP
|
||||
|
||||
hipFree(Ad);
|
||||
hipFree(Bd);
|
||||
hipFree(Cd);
|
||||
delete[] A;
|
||||
delete[] B;
|
||||
delete[] C;
|
||||
delete[] D;
|
||||
}
|
||||
|
||||
int main() {
|
||||
test<float>();
|
||||
test<double>();
|
||||
passed();
|
||||
return 0;
|
||||
}
|
||||
@@ -1,60 +0,0 @@
|
||||
#include <iostream>
|
||||
#include "hip/hip_runtime.h"
|
||||
#include "hip/hip_runtime_api.h"
|
||||
#include "../test_common.h"
|
||||
|
||||
|
||||
#define LEN 1024
|
||||
#define SIZE LEN << 2
|
||||
|
||||
/* HIT_START
|
||||
* BUILD: %t %s ../test_common.cpp
|
||||
* TEST: %t
|
||||
* HIT_END
|
||||
*/
|
||||
|
||||
|
||||
__global__ void cpy(uint32_t* Out, uint32_t* In) {
|
||||
int tx = threadIdx.x;
|
||||
memcpy(Out + tx, In + tx, sizeof(uint32_t));
|
||||
}
|
||||
|
||||
__global__ void set(uint32_t* ptr, uint8_t val, size_t size) {
|
||||
int tx = threadIdx.x;
|
||||
memset(ptr + tx, val, sizeof(uint32_t));
|
||||
}
|
||||
|
||||
int main() {
|
||||
uint32_t *A, *Ad, *B, *Bd;
|
||||
uint32_t* Val;
|
||||
A = new uint32_t[LEN];
|
||||
B = new uint32_t[LEN];
|
||||
Val = new uint32_t;
|
||||
*Val = 0;
|
||||
for (int i = 0; i < LEN; i++) {
|
||||
A[i] = i;
|
||||
B[i] = 0;
|
||||
}
|
||||
hipMalloc((void**)&Ad, SIZE);
|
||||
hipMalloc((void**)&Bd, SIZE);
|
||||
hipMemcpy(Ad, A, SIZE, hipMemcpyHostToDevice);
|
||||
|
||||
hipLaunchKernelGGL(cpy, dim3(1), dim3(LEN), 0, 0, Bd, Ad);
|
||||
|
||||
hipMemcpy(B, Bd, SIZE, hipMemcpyDeviceToHost);
|
||||
for (int i = LEN - 16; i < LEN; i++) {
|
||||
if (A[i] != B[i]) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
hipLaunchKernelGGL(set, dim3(1), dim3(LEN), 0, 0, Bd, 0x1, LEN);
|
||||
|
||||
hipMemcpy(B, Bd, SIZE, hipMemcpyDeviceToHost);
|
||||
for (int i = LEN - 16; i < LEN; i++) {
|
||||
if (0x01010101 != B[i]) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
passed();
|
||||
}
|
||||
@@ -1,90 +0,0 @@
|
||||
/*
|
||||
Copyright (c) 2015 - 2021 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:
|
||||
|
||||
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.
|
||||
*/
|
||||
|
||||
/* HIT_START
|
||||
* BUILD: %t %s ../test_common.cpp
|
||||
* TEST: %t
|
||||
* HIT_END
|
||||
*/
|
||||
|
||||
#include <hip/hip_runtime.h>
|
||||
#include <hip/device_functions.h>
|
||||
#include "test_common.h"
|
||||
|
||||
#pragma GCC diagnostic ignored "-Wall"
|
||||
#pragma clang diagnostic ignored "-Wunused-variable"
|
||||
|
||||
__device__ void double_precision_intrinsics() {
|
||||
#if defined OCML_BASIC_ROUNDED_OPERATIONS
|
||||
__dadd_rd(0.0, 1.0);
|
||||
#endif
|
||||
__dadd_rn(0.0, 1.0);
|
||||
#if defined OCML_BASIC_ROUNDED_OPERATIONS
|
||||
__dadd_ru(0.0, 1.0);
|
||||
__dadd_rz(0.0, 1.0);
|
||||
__ddiv_rd(0.0, 1.0);
|
||||
#endif
|
||||
__ddiv_rn(0.0, 1.0);
|
||||
#if defined OCML_BASIC_ROUNDED_OPERATIONS
|
||||
__ddiv_ru(0.0, 1.0);
|
||||
__ddiv_rz(0.0, 1.0);
|
||||
__dmul_rd(1.0, 2.0);
|
||||
#endif
|
||||
__dmul_rn(1.0, 2.0);
|
||||
#if defined OCML_BASIC_ROUNDED_OPERATIONS
|
||||
__dmul_ru(1.0, 2.0);
|
||||
__dmul_rz(1.0, 2.0);
|
||||
__drcp_rd(2.0);
|
||||
#endif
|
||||
__drcp_rn(2.0);
|
||||
#if defined OCML_BASIC_ROUNDED_OPERATIONS
|
||||
__drcp_ru(2.0);
|
||||
__drcp_rz(2.0);
|
||||
__dsqrt_rd(4.0);
|
||||
#endif
|
||||
__dsqrt_rn(4.0);
|
||||
#if defined OCML_BASIC_ROUNDED_OPERATIONS
|
||||
__dsqrt_ru(4.0);
|
||||
__dsqrt_rz(4.0);
|
||||
__dsub_rd(2.0, 1.0);
|
||||
#endif
|
||||
__dsub_rn(2.0, 1.0);
|
||||
#if defined OCML_BASIC_ROUNDED_OPERATIONS
|
||||
__dsub_ru(2.0, 1.0);
|
||||
__dsub_rz(2.0, 1.0);
|
||||
__fma_rd(1.0, 2.0, 3.0);
|
||||
#endif
|
||||
__fma_rn(1.0, 2.0, 3.0);
|
||||
#if defined OCML_BASIC_ROUNDED_OPERATIONS
|
||||
__fma_ru(1.0, 2.0, 3.0);
|
||||
__fma_rz(1.0, 2.0, 3.0);
|
||||
#endif
|
||||
}
|
||||
|
||||
__global__ void compileDoublePrecisionIntrinsics(int ignored) {
|
||||
double_precision_intrinsics();
|
||||
}
|
||||
|
||||
int main() {
|
||||
hipLaunchKernelGGL(compileDoublePrecisionIntrinsics, dim3(1, 1, 1), dim3(1, 1, 1), 0, 0, 1);
|
||||
passed();
|
||||
}
|
||||
@@ -1,147 +0,0 @@
|
||||
/*
|
||||
Copyright (c) 2015 - 2021 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:
|
||||
|
||||
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.
|
||||
*/
|
||||
|
||||
/* HIT_START
|
||||
* BUILD: %t %s ../test_common.cpp
|
||||
* TEST: %t
|
||||
* HIT_END
|
||||
*/
|
||||
|
||||
#include <hip/hip_runtime.h>
|
||||
#include <hip/math_functions.h>
|
||||
#include "test_common.h"
|
||||
|
||||
#pragma GCC diagnostic ignored "-Wall"
|
||||
#pragma clang diagnostic ignored "-Wunused-variable"
|
||||
|
||||
__device__ void double_precision_math_functions() {
|
||||
int iX;
|
||||
double fX, fY;
|
||||
|
||||
acos(1.0);
|
||||
acosh(1.0);
|
||||
asin(0.0);
|
||||
asinh(0.0);
|
||||
atan(0.0);
|
||||
atan2(0.0, 1.0);
|
||||
atanh(0.0);
|
||||
cbrt(0.0);
|
||||
ceil(0.0);
|
||||
copysign(1.0, -2.0);
|
||||
cos(0.0);
|
||||
cosh(0.0);
|
||||
cospi(0.0);
|
||||
cyl_bessel_i0(0.0);
|
||||
cyl_bessel_i1(0.0);
|
||||
erf(0.0);
|
||||
erfc(0.0);
|
||||
erfcinv(2.0);
|
||||
erfcx(0.0);
|
||||
erfinv(1.0);
|
||||
exp(0.0);
|
||||
exp10(0.0);
|
||||
exp2(0.0);
|
||||
expm1(0.0);
|
||||
fabs(1.0);
|
||||
fdim(1.0, 0.0);
|
||||
floor(0.0);
|
||||
fma(1.0, 2.0, 3.0);
|
||||
fmax(0.0, 0.0);
|
||||
fmin(0.0, 0.0);
|
||||
fmod(0.0, 1.0);
|
||||
frexp(0.0, &iX);
|
||||
hypot(1.0, 0.0);
|
||||
ilogb(1.0);
|
||||
isfinite(0.0);
|
||||
isinf(0.0);
|
||||
isnan(0.0);
|
||||
j0(0.0);
|
||||
j1(0.0);
|
||||
jn(-1.0, 1.0);
|
||||
ldexp(0.0, 0);
|
||||
lgamma(1.0);
|
||||
llrint(0.0);
|
||||
llround(0.0);
|
||||
log(1.0);
|
||||
log10(1.0);
|
||||
log1p(-1.0);
|
||||
log2(1.0);
|
||||
logb(1.0);
|
||||
lrint(0.0);
|
||||
lround(0.0);
|
||||
modf(0.0, &fX);
|
||||
nan("1");
|
||||
nearbyint(0.0);
|
||||
nextafter(0.0, 0.0);
|
||||
fX = 1.0;
|
||||
norm(1, &fX);
|
||||
norm3d(1.0, 0.0, 0.0);
|
||||
norm4d(1.0, 0.0, 0.0, 0.0);
|
||||
normcdf(0.0);
|
||||
normcdfinv(1.0);
|
||||
pow(1.0, 0.0);
|
||||
rcbrt(1.0);
|
||||
remainder(2.0, 1.0);
|
||||
remquo(1.0, 2.0, &iX);
|
||||
rhypot(0.0, 1.0);
|
||||
rint(1.0);
|
||||
fX = 1.0;
|
||||
rnorm(1, &fX);
|
||||
rnorm3d(0.0, 0.0, 1.0);
|
||||
rnorm4d(0.0, 0.0, 0.0, 1.0);
|
||||
round(0.0);
|
||||
rsqrt(1.0);
|
||||
scalbln(0.0, 1);
|
||||
scalbn(0.0, 1);
|
||||
signbit(1.0);
|
||||
sin(0.0);
|
||||
#if not(defined(__HIP_PLATFORM_NVIDIA__) && (CUDA_VERSION == 11030 || CUDA_VERSION == 11020))
|
||||
//NV A100 has a bug in sincos(), so temporarily disbale it
|
||||
sincos(0.0, &fX, &fY);
|
||||
#endif
|
||||
sincospi(0.0, &fX, &fY);
|
||||
sinh(0.0);
|
||||
sinpi(0.0);
|
||||
sqrt(0.0);
|
||||
tan(0.0);
|
||||
tanh(0.0);
|
||||
tgamma(2.0);
|
||||
trunc(0.0);
|
||||
y0(1.0);
|
||||
y1(1.0);
|
||||
yn(1, 1.0);
|
||||
}
|
||||
|
||||
__global__ void compileDoublePrecisionMathOnDevice(int) {
|
||||
double_precision_math_functions();
|
||||
}
|
||||
|
||||
int main() {
|
||||
hipLaunchKernelGGL(
|
||||
compileDoublePrecisionMathOnDevice,
|
||||
dim3(1, 1, 1),
|
||||
dim3(1, 1, 1),
|
||||
0,
|
||||
0,
|
||||
1);
|
||||
passed();
|
||||
}
|
||||
@@ -1,158 +0,0 @@
|
||||
/*
|
||||
Copyright (c) 2015 - 2021 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:
|
||||
|
||||
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.
|
||||
*/
|
||||
|
||||
/* HIT_START
|
||||
* BUILD: %t %s ../test_common.cpp
|
||||
* TEST: %t
|
||||
* HIT_END
|
||||
*/
|
||||
|
||||
#include <hip/hip_runtime.h>
|
||||
//#include <hip/math_functions.h>
|
||||
#include "test_common.h"
|
||||
#include <cmath>
|
||||
|
||||
#pragma GCC diagnostic ignored "-Wall"
|
||||
#pragma clang diagnostic ignored "-Wunused-variable"
|
||||
|
||||
__host__ void double_precision_math_functions() {
|
||||
int iX;
|
||||
double fX, fY;
|
||||
|
||||
acos(1.0);
|
||||
acosh(1.0);
|
||||
asin(0.0);
|
||||
asinh(0.0);
|
||||
atan(0.0);
|
||||
atan2(0.0, 1.0);
|
||||
atanh(0.0);
|
||||
cbrt(0.0);
|
||||
ceil(0.0);
|
||||
copysign(1.0, -2.0);
|
||||
cos(0.0);
|
||||
cosh(0.0);
|
||||
// cospi(0.0);
|
||||
// cyl_bessel_i0(0.0);
|
||||
// cyl_bessel_i1(0.0);
|
||||
erf(0.0);
|
||||
erfc(0.0);
|
||||
// erfcinv(2.0);
|
||||
// erfcx(0.0);
|
||||
// erfinv(1.0);
|
||||
exp(0.0);
|
||||
#ifdef __unix__
|
||||
exp10(0.0);
|
||||
#endif
|
||||
exp2(0.0);
|
||||
expm1(0.0);
|
||||
fabs(1.0);
|
||||
fdim(1.0, 0.0);
|
||||
floor(0.0);
|
||||
fma(1.0, 2.0, 3.0);
|
||||
fmax(0.0, 0.0);
|
||||
fmin(0.0, 0.0);
|
||||
fmod(0.0, 1.0);
|
||||
frexp(0.0, &iX);
|
||||
hypot(1.0, 0.0);
|
||||
ilogb(1.0);
|
||||
std::isfinite(0.0);
|
||||
std::isinf(0.0);
|
||||
std::isnan(0.0);
|
||||
#ifdef __unix__
|
||||
j0(0.0);
|
||||
j1(0.0);
|
||||
jn(-1.0, 1.0);
|
||||
#elif _WIN64
|
||||
_j0(0.0);
|
||||
_j1(0.0);
|
||||
_jn(-1.0, 1.0);
|
||||
#endif
|
||||
ldexp(0.0, 0);
|
||||
// lgamma(1.0);
|
||||
llrint(0.0);
|
||||
llround(0.0);
|
||||
log(1.0);
|
||||
log10(1.0);
|
||||
log1p(-1.0);
|
||||
log2(1.0);
|
||||
logb(1.0);
|
||||
lrint(0.0);
|
||||
lround(0.0);
|
||||
modf(0.0, &fX);
|
||||
nan("1");
|
||||
nearbyint(0.0);
|
||||
// nextafter(0.0);
|
||||
fX = 1.0; // norm(1, &fX);
|
||||
#if defined(__HIP_PLATFORM_AMD__)
|
||||
// norm3d(1.0, 0.0, 0.0);
|
||||
// norm4d(1.0, 0.0, 0.0, 0.0);
|
||||
#endif
|
||||
// normcdf(0.0);
|
||||
// normcdfinv(1.0);
|
||||
pow(1.0, 0.0);
|
||||
// rcbrt(1.0);
|
||||
|
||||
remainder(2.0, 1.0);
|
||||
remquo(1.0, 2.0, &iX);
|
||||
#if defined(__HIP_PLATFORM_AMD__)
|
||||
// rhypot(0.0, 1.0);
|
||||
#endif
|
||||
rint(1.0);
|
||||
#if defined(__HIP_PLATFORM_AMD__)
|
||||
fX = 1.0; // rnorm(1, &fX);
|
||||
// rnorm3d(0.0, 0.0, 1.0);
|
||||
// rnorm4d(0.0, 0.0, 0.0, 1.0);
|
||||
#endif
|
||||
round(0.0);
|
||||
// rsqrt(1.0);
|
||||
scalbln(0.0, 1);
|
||||
scalbn(0.0, 1);
|
||||
std::signbit(1.0);
|
||||
sin(0.0);
|
||||
#ifdef _unix__
|
||||
sincos(0.0, &fX, &fY);
|
||||
#endif
|
||||
// sincospi(0.0, &fX, &fY);
|
||||
sinh(0.0);
|
||||
// sinpi(0.0);
|
||||
sqrt(0.0);
|
||||
tan(0.0);
|
||||
tanh(0.0);
|
||||
tgamma(2.0);
|
||||
trunc(0.0);
|
||||
#ifdef __unix__
|
||||
y0(1.0);
|
||||
y1(1.0);
|
||||
yn(1, 1.0);
|
||||
#elif _WIN64
|
||||
_y0(1.0);
|
||||
_y1(1.0);
|
||||
_yn(1, 1.0);
|
||||
#endif
|
||||
}
|
||||
|
||||
static void compileOnHost() { double_precision_math_functions(); }
|
||||
|
||||
int main() {
|
||||
compileOnHost();
|
||||
passed();
|
||||
}
|
||||
@@ -1,66 +0,0 @@
|
||||
/*
|
||||
Copyright (c) 2015 - 2021 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:
|
||||
|
||||
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.
|
||||
*/
|
||||
|
||||
/* HIT_START
|
||||
* BUILD: %t %s
|
||||
* TEST: %t
|
||||
* HIT_END
|
||||
*/
|
||||
|
||||
#include "test_common.h"
|
||||
#include <hip/device_functions.h>
|
||||
|
||||
#define LEN 512
|
||||
#define SIZE LEN << 2
|
||||
|
||||
|
||||
__global__ void floatMath(float* In, float* Out) {
|
||||
int tid = threadIdx.x + blockIdx.x * blockDim.x;
|
||||
Out[tid] = __cosf(In[tid]);
|
||||
Out[tid] = __exp10f(Out[tid]);
|
||||
Out[tid] = __expf(Out[tid]);
|
||||
Out[tid] = __frsqrt_rn(Out[tid]);
|
||||
#if defined OCML_BASIC_ROUNDED_OPERATIONS
|
||||
Out[tid] = __fsqrt_rd(Out[tid]);
|
||||
#endif
|
||||
Out[tid] = __fsqrt_rn(Out[tid]);
|
||||
#if defined OCML_BASIC_ROUNDED_OPERATIONS
|
||||
Out[tid] = __fsqrt_ru(Out[tid]);
|
||||
Out[tid] = __fsqrt_rz(Out[tid]);
|
||||
#endif
|
||||
Out[tid] = __log10f(Out[tid]);
|
||||
Out[tid] = __log2f(Out[tid]);
|
||||
Out[tid] = __logf(Out[tid]);
|
||||
Out[tid] = __powf(2.0f, Out[tid]);
|
||||
__sincosf(Out[tid], &In[tid], &Out[tid]);
|
||||
Out[tid] = __sinf(Out[tid]);
|
||||
Out[tid] = __cosf(Out[tid]);
|
||||
Out[tid] = __tanf(Out[tid]);
|
||||
}
|
||||
|
||||
int main() {
|
||||
float *Ind, *Outd;
|
||||
hipMalloc((void**)&Ind, SIZE);
|
||||
hipMalloc((void**)&Outd, SIZE);
|
||||
hipLaunchKernelGGL(floatMath, dim3(LEN, 1, 1), dim3(1, 1, 1), 0, 0, Ind, Outd);
|
||||
passed();
|
||||
}
|
||||
@@ -1,132 +0,0 @@
|
||||
/*
|
||||
Copyright (c) 2015 - 2021 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:
|
||||
|
||||
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.
|
||||
*/
|
||||
|
||||
/* HIT_START
|
||||
* BUILD: %t %s ../test_common.cpp
|
||||
* TEST: %t
|
||||
* HIT_END
|
||||
*/
|
||||
|
||||
#include <hip/hip_runtime.h>
|
||||
#include <hip/math_functions.h>
|
||||
#include "test_common.h"
|
||||
|
||||
__global__ void FloatMathPrecise() {
|
||||
int iX;
|
||||
float fX, fY;
|
||||
|
||||
acosf(1.0f);
|
||||
acoshf(1.0f);
|
||||
asinf(0.0f);
|
||||
asinhf(0.0f);
|
||||
atan2f(0.0f, 1.0f);
|
||||
atanf(0.0f);
|
||||
atanhf(0.0f);
|
||||
cbrtf(0.0f);
|
||||
fX = ceilf(0.0f);
|
||||
fX = copysignf(1.0f, -2.0f);
|
||||
cosf(0.0f);
|
||||
coshf(0.0f);
|
||||
cospif(0.0f);
|
||||
cyl_bessel_i0f(0.0f);
|
||||
cyl_bessel_i1f(0.0f);
|
||||
erfcf(0.0f);
|
||||
erfcinvf(2.0f);
|
||||
erfcxf(0.0f);
|
||||
erff(0.0f);
|
||||
erfinvf(1.0f);
|
||||
exp10f(0.0f);
|
||||
exp2f(0.0f);
|
||||
expf(0.0f);
|
||||
expm1f(0.0f);
|
||||
fX = fabsf(1.0f);
|
||||
fdimf(1.0f, 0.0f);
|
||||
fdividef(0.0f, 1.0f);
|
||||
fX = floorf(0.0f);
|
||||
fmaf(1.0f, 2.0f, 3.0f);
|
||||
fX = fmaxf(0.0f, 0.0f);
|
||||
fX = fminf(0.0f, 0.0f);
|
||||
fmodf(0.0f, 1.0f);
|
||||
frexpf(0.0f, &iX);
|
||||
hypotf(1.0f, 0.0f);
|
||||
ilogbf(1.0f);
|
||||
isfinite(0.0f);
|
||||
fX = isinf(0.0f);
|
||||
fX = isnan(0.0f);
|
||||
j0f(0.0f);
|
||||
j1f(0.0f);
|
||||
jnf(-1.0f, 1.0f);
|
||||
ldexpf(0.0f, 0);
|
||||
lgammaf(1.0f);
|
||||
llrintf(0.0f);
|
||||
llroundf(0.0f);
|
||||
log10f(1.0f);
|
||||
log1pf(-1.0f);
|
||||
log2f(1.0f);
|
||||
logbf(1.0f);
|
||||
logf(1.0f);
|
||||
lrintf(0.0f);
|
||||
lroundf(0.0f);
|
||||
modff(0.0f, &fX);
|
||||
fX = nanf("1");
|
||||
fX = nearbyintf(0.0f);
|
||||
nextafterf(0.0f, 0.0f);
|
||||
norm3df(1.0f, 0.0f, 0.0f);
|
||||
norm4df(1.0f, 0.0f, 0.0f, 0.0f);
|
||||
normcdff(0.0f);
|
||||
normcdfinvf(1.0f);
|
||||
fX = 1.0f;
|
||||
normf(1, &fX);
|
||||
powf(1.0f, 0.0f);
|
||||
rcbrtf(1.0f);
|
||||
remainderf(2.0f, 1.0f);
|
||||
remquof(1.0f, 2.0f, &iX);
|
||||
rhypotf(0.0f, 1.0f);
|
||||
fY = rintf(1.0f);
|
||||
rnorm3df(0.0f, 0.0f, 1.0f);
|
||||
rnorm4df(0.0f, 0.0f, 0.0f, 1.0f);
|
||||
fX = 1.0f;
|
||||
rnormf(1, &fX);
|
||||
fY = roundf(0.0f);
|
||||
rsqrtf(1.0f);
|
||||
scalblnf(0.0f, 1);
|
||||
scalbnf(0.0f, 1);
|
||||
signbit(1.0f);
|
||||
sincosf(0.0f, &fX, &fY);
|
||||
sincospif(0.0f, &fX, &fY);
|
||||
sinf(0.0f);
|
||||
sinhf(0.0f);
|
||||
sinpif(0.0f);
|
||||
sqrtf(0.0f);
|
||||
tanf(0.0f);
|
||||
tanhf(0.0f);
|
||||
tgammaf(2.0f);
|
||||
fY = truncf(0.0f);
|
||||
y0f(1.0f);
|
||||
y1f(1.0f);
|
||||
ynf(1, 1.0f);
|
||||
}
|
||||
|
||||
int main() {
|
||||
hipLaunchKernelGGL(FloatMathPrecise, dim3(1, 1, 1), dim3(1, 1, 1), 0, 0);
|
||||
passed();
|
||||
}
|
||||
@@ -1,341 +0,0 @@
|
||||
/*
|
||||
Copyright (c) 2020 - 2021 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:
|
||||
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.
|
||||
*/
|
||||
|
||||
|
||||
/* HIT_START
|
||||
* BUILD: %t %s ../test_common.cpp NVCC_OPTIONS -std=c++11 EXCLUDE_HIP_PLATFORM nvidia
|
||||
* TEST: %t
|
||||
* HIT_END
|
||||
*/
|
||||
|
||||
#include "test_common.h"
|
||||
#include <hip/hip_runtime.h>
|
||||
#include "hip/hip_fp16.h"
|
||||
|
||||
#define test_passed(test_name) \
|
||||
printf("%s %s PASSED!%s\n", KGRN, #test_name, KNRM);
|
||||
|
||||
enum half2Op {
|
||||
HALF2_OP_HEQ2 = 0,
|
||||
HALF2_OP_HNE2,
|
||||
HALF2_OP_HLE2,
|
||||
HALF2_OP_HGE2,
|
||||
HALF2_OP_HLT2,
|
||||
HALF2_OP_HGT2,
|
||||
HALF2_OP_MAX
|
||||
};
|
||||
|
||||
enum half2Test {
|
||||
HALF2_TEST_FUNCTION = 0,
|
||||
HALF2_TEST_NAN,
|
||||
HALF2_TEST_MAX
|
||||
};
|
||||
|
||||
// Kernels for half2 comparision functions
|
||||
|
||||
__global__
|
||||
void __half2Compare(float* result_D, __half2 a, int n, int half2Op,
|
||||
int testType) {
|
||||
size_t gputhread = (blockIdx.x * blockDim.x + threadIdx.x);
|
||||
size_t stride = blockDim.x * gridDim.x;
|
||||
|
||||
for (size_t i = gputhread; i < n; i += stride) {
|
||||
switch (half2Op) {
|
||||
case HALF2_OP_HEQ2:
|
||||
if (testType == HALF2_TEST_FUNCTION) {
|
||||
result_D[i] = __high2float(__heq2(__hadd2(a, __half2{1, 1}),
|
||||
__half2{2, 2}));
|
||||
} else {
|
||||
result_D[i] = __high2float(__heq2(__h2div(a, __half2{0, 0}),
|
||||
__half2{0, 0}));
|
||||
}
|
||||
break;
|
||||
case HALF2_OP_HNE2:
|
||||
result_D[i] = __high2float(__hne2(__hadd2(a, __half2{1, 1}),
|
||||
__half2{2, 2}));
|
||||
break;
|
||||
case HALF2_OP_HLE2:
|
||||
if (testType == HALF2_TEST_FUNCTION) {
|
||||
result_D[i] = __high2float(__hle2(__hadd2(a, __half2{1, 1}),
|
||||
__half2{3, 3}));
|
||||
} else {
|
||||
result_D[i] = __high2float(__hle2(__h2div(a, __half2{0, 0}),
|
||||
__half2{0, 0}));
|
||||
}
|
||||
break;
|
||||
case HALF2_OP_HGE2:
|
||||
if (testType == HALF2_TEST_FUNCTION) {
|
||||
result_D[i] = __high2float(__hge2(__hadd2(a, __half2{1, 1}),
|
||||
__half2{2, 2}));
|
||||
} else {
|
||||
result_D[i] = __high2float(__hge2(__h2div(a, __half2{0, 0}),
|
||||
__half2{0, 0}));
|
||||
}
|
||||
break;
|
||||
case HALF2_OP_HLT2:
|
||||
if (testType == HALF2_TEST_FUNCTION) {
|
||||
result_D[i] = __high2float(__hlt2(__hadd2(a, __half2{1, 1}),
|
||||
__half2{3, 3}));
|
||||
} else {
|
||||
result_D[i] = __high2float(__hlt2(__h2div(a, __half2{0, 0}),
|
||||
__half2{0, 0}));
|
||||
}
|
||||
break;
|
||||
case HALF2_OP_HGT2:
|
||||
if (testType == HALF2_TEST_FUNCTION) {
|
||||
result_D[i] = __high2float(__hgt2(__hadd2(a, __half2{1, 1}),
|
||||
__half2{3, 3}));
|
||||
} else {
|
||||
result_D[i] = __high2float(__hgt2(__h2div(a, __half2{0, 0}),
|
||||
__half2{0, 0}));
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static bool isFailed(float expectedValue, float *result_H, int size) {
|
||||
for (int index = 0; index < size; index++) {
|
||||
if (expectedValue != result_H[index]) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
int main() {
|
||||
const int n = 64;
|
||||
float* result_H = reinterpret_cast<float*>(malloc(n*sizeof(float)));
|
||||
float* result_D;
|
||||
bool bFunctionalTestFailed = false;
|
||||
bool bNanTestFailed = false;
|
||||
int index = 0;
|
||||
HIPCHECK(hipMalloc(&result_D, n*sizeof(float)));
|
||||
|
||||
// kernel launch and hipmemcpy operation to get return value for heq2
|
||||
hipLaunchKernelGGL(__half2Compare, dim3(1, 1, 1), dim3(1, 1, 1), 0, 0,
|
||||
result_D, __half2{1, 1}, n, HALF2_OP_HEQ2,
|
||||
HALF2_TEST_FUNCTION);
|
||||
hipDeviceSynchronize();
|
||||
HIPCHECK(hipMemcpy(result_H, result_D, n*sizeof(float),
|
||||
hipMemcpyDeviceToHost));
|
||||
if (isFailed(1.0, result_H, n)) {
|
||||
printf("heq2: failure when arguments are equal\n");
|
||||
bFunctionalTestFailed = true;
|
||||
}
|
||||
|
||||
hipLaunchKernelGGL(__half2Compare, dim3(1, 1, 1), dim3(1, 1, 1), 0, 0,
|
||||
result_D, __half2{2, 2}, n, HALF2_OP_HEQ2,
|
||||
HALF2_TEST_FUNCTION);
|
||||
hipDeviceSynchronize();
|
||||
HIPCHECK(hipMemcpy(result_H, result_D, n*sizeof(float),
|
||||
hipMemcpyDeviceToHost));
|
||||
if (isFailed(0.0, result_H, n)) {
|
||||
printf("heq2: failure when arguments are not equal\n");
|
||||
bFunctionalTestFailed = true;
|
||||
}
|
||||
|
||||
// kernel launch and hipmemcpy operation to get return value for hne2
|
||||
hipLaunchKernelGGL(__half2Compare, dim3(1, 1, 1), dim3(1, 1, 1), 0, 0,
|
||||
result_D, __half2{2, 2}, n, HALF2_OP_HNE2,
|
||||
HALF2_TEST_FUNCTION);
|
||||
hipDeviceSynchronize();
|
||||
HIPCHECK(hipMemcpy(result_H, result_D, n*sizeof(float),
|
||||
hipMemcpyDeviceToHost));
|
||||
if (isFailed(1.0, result_H, n)) {
|
||||
printf("hne2: failure when arguments are not equal\n");
|
||||
bFunctionalTestFailed = true;
|
||||
}
|
||||
|
||||
hipLaunchKernelGGL(__half2Compare, dim3(1, 1, 1), dim3(1, 1, 1), 0, 0,
|
||||
result_D, __half2{1, 1}, n, HALF2_OP_HNE2,
|
||||
HALF2_TEST_FUNCTION);
|
||||
hipDeviceSynchronize();
|
||||
HIPCHECK(hipMemcpy(result_H, result_D, n*sizeof(float),
|
||||
hipMemcpyDeviceToHost));
|
||||
if (isFailed(0.0, result_H, n)) {
|
||||
printf("hne2: failure when arguments are equal\n");
|
||||
bFunctionalTestFailed = true;
|
||||
}
|
||||
|
||||
// kernel launch and hipmemcpy operation to get return value for hle2
|
||||
hipLaunchKernelGGL(__half2Compare, dim3(1, 1, 1), dim3(1, 1, 1), 0, 0,
|
||||
result_D, __half2{1, 1}, n, HALF2_OP_HLE2,
|
||||
HALF2_TEST_FUNCTION);
|
||||
hipDeviceSynchronize();
|
||||
HIPCHECK(hipMemcpy(result_H, result_D, n*sizeof(float),
|
||||
hipMemcpyDeviceToHost));
|
||||
if (isFailed(1.0, result_H, n)) {
|
||||
printf("hle2: failure when argument is less than equal\n");
|
||||
bFunctionalTestFailed = true;
|
||||
}
|
||||
|
||||
hipLaunchKernelGGL(__half2Compare, dim3(1, 1, 1), dim3(1, 1, 1), 0, 0,
|
||||
result_D, __half2{2, 2}, n, HALF2_OP_HLE2,
|
||||
HALF2_TEST_FUNCTION);
|
||||
hipDeviceSynchronize();
|
||||
HIPCHECK(hipMemcpy(result_H, result_D, n*sizeof(float),
|
||||
hipMemcpyDeviceToHost));
|
||||
if (isFailed(1.0, result_H, n)) {
|
||||
printf("hle2: failure when argument is equal\n");
|
||||
bFunctionalTestFailed = true;
|
||||
}
|
||||
|
||||
hipLaunchKernelGGL(__half2Compare, dim3(1, 1, 1), dim3(1, 1, 1), 0, 0,
|
||||
result_D, __half2{3, 3}, n, HALF2_OP_HLE2,
|
||||
HALF2_TEST_FUNCTION);
|
||||
hipDeviceSynchronize();
|
||||
HIPCHECK(hipMemcpy(result_H, result_D, n*sizeof(float),
|
||||
hipMemcpyDeviceToHost));
|
||||
if (isFailed(0.0, result_H, n)) {
|
||||
printf("hle2: failure when argument is greater\n");
|
||||
bFunctionalTestFailed = true;
|
||||
}
|
||||
|
||||
// kernel launch and hipmemcpy operation to get return value for hge2
|
||||
hipLaunchKernelGGL(__half2Compare, dim3(1, 1, 1), dim3(1, 1, 1), 0, 0,
|
||||
result_D, __half2{2, 2}, n, HALF2_OP_HGE2,
|
||||
HALF2_TEST_FUNCTION);
|
||||
hipDeviceSynchronize();
|
||||
HIPCHECK(hipMemcpy(result_H, result_D, n*sizeof(float),
|
||||
hipMemcpyDeviceToHost));
|
||||
if (isFailed(1.0, result_H, n)) {
|
||||
printf("hge2: failure when argument is greater\n");
|
||||
bFunctionalTestFailed = true;
|
||||
}
|
||||
|
||||
hipLaunchKernelGGL(__half2Compare, dim3(1, 1, 1), dim3(1, 1, 1), 0, 0,
|
||||
result_D, __half2{1, 1}, n, HALF2_OP_HGE2,
|
||||
HALF2_TEST_FUNCTION);
|
||||
hipDeviceSynchronize();
|
||||
HIPCHECK(hipMemcpy(result_H, result_D, n*sizeof(float),
|
||||
hipMemcpyDeviceToHost));
|
||||
if (isFailed(1.0, result_H, n)) {
|
||||
printf("hge2: failure when argument is equal\n");
|
||||
bFunctionalTestFailed = true;
|
||||
}
|
||||
|
||||
hipLaunchKernelGGL(__half2Compare, dim3(1, 1, 1), dim3(1, 1, 1), 0, 0,
|
||||
result_D, __half2{0, 0}, n, HALF2_OP_HGE2,
|
||||
HALF2_TEST_FUNCTION);
|
||||
hipDeviceSynchronize();
|
||||
HIPCHECK(hipMemcpy(result_H, result_D, n*sizeof(float),
|
||||
hipMemcpyDeviceToHost));
|
||||
if (isFailed(0.0, result_H, n)) {
|
||||
printf("hge2: failure when argument is less\n");
|
||||
bFunctionalTestFailed = true;
|
||||
}
|
||||
|
||||
// kernel launch and hipmemcpy operation to get return value for hlt2
|
||||
hipLaunchKernelGGL(__half2Compare, dim3(1, 1, 1), dim3(1, 1, 1), 0, 0,
|
||||
result_D, __half2{1, 1}, n, HALF2_OP_HLT2,
|
||||
HALF2_TEST_FUNCTION);
|
||||
hipDeviceSynchronize();
|
||||
HIPCHECK(hipMemcpy(result_H, result_D, n*sizeof(float),
|
||||
hipMemcpyDeviceToHost));
|
||||
if (isFailed(1.0, result_H, n)) {
|
||||
printf("hlt2: failure when argument is less\n");
|
||||
bFunctionalTestFailed = true;
|
||||
}
|
||||
|
||||
hipLaunchKernelGGL(__half2Compare, dim3(1, 1, 1), dim3(1, 1, 1), 0, 0,
|
||||
result_D, __half2{2, 2}, n, HALF2_OP_HLT2,
|
||||
HALF2_TEST_FUNCTION);
|
||||
hipDeviceSynchronize();
|
||||
HIPCHECK(hipMemcpy(result_H, result_D, n*sizeof(float),
|
||||
hipMemcpyDeviceToHost));
|
||||
if (isFailed(0.0, result_H, n)) {
|
||||
printf("hlt2: failure when argument is equal\n");
|
||||
bFunctionalTestFailed = true;
|
||||
}
|
||||
|
||||
hipLaunchKernelGGL(__half2Compare, dim3(1, 1, 1), dim3(1, 1, 1), 0, 0,
|
||||
result_D, __half2{3, 3}, n, HALF2_OP_HLT2,
|
||||
HALF2_TEST_FUNCTION);
|
||||
hipDeviceSynchronize();
|
||||
HIPCHECK(hipMemcpy(result_H, result_D, n*sizeof(float),
|
||||
hipMemcpyDeviceToHost));
|
||||
if (isFailed(0.0, result_H, n)) {
|
||||
printf("hlt2: failure when argument is greater\n");
|
||||
bFunctionalTestFailed = true;
|
||||
}
|
||||
|
||||
// kernel launch and hipmemcpy operation to get return value for hgt2
|
||||
hipLaunchKernelGGL(__half2Compare, dim3(1, 1, 1), dim3(1, 1, 1), 0, 0,
|
||||
result_D, __half2{3, 3}, n, HALF2_OP_HGT2,
|
||||
HALF2_TEST_FUNCTION);
|
||||
hipDeviceSynchronize();
|
||||
HIPCHECK(hipMemcpy(result_H, result_D, n*sizeof(float),
|
||||
hipMemcpyDeviceToHost));
|
||||
if (isFailed(1.0, result_H, n)) {
|
||||
printf("hgt2: failure when argument is greater\n");
|
||||
bFunctionalTestFailed = true;
|
||||
}
|
||||
|
||||
hipLaunchKernelGGL(__half2Compare, dim3(1, 1, 1), dim3(1, 1, 1), 0, 0,
|
||||
result_D, __half2{2, 2}, n, HALF2_OP_HGT2,
|
||||
HALF2_TEST_FUNCTION);
|
||||
hipDeviceSynchronize();
|
||||
HIPCHECK(hipMemcpy(result_H, result_D, n*sizeof(float),
|
||||
hipMemcpyDeviceToHost));
|
||||
if (isFailed(0.0, result_H, n)) {
|
||||
printf("hgt2: failure when argument is equal\n");
|
||||
bFunctionalTestFailed = true;
|
||||
}
|
||||
|
||||
hipLaunchKernelGGL(__half2Compare, dim3(1, 1, 1), dim3(1, 1, 1), 0, 0,
|
||||
result_D, __half2{1, 1}, n, HALF2_OP_HGT2,
|
||||
HALF2_TEST_FUNCTION);
|
||||
hipDeviceSynchronize();
|
||||
HIPCHECK(hipMemcpy(result_H, result_D, n*sizeof(float),
|
||||
hipMemcpyDeviceToHost));
|
||||
if (isFailed(0.0, result_H, n)) {
|
||||
printf("hgt2: failure when argument is less\n");
|
||||
bFunctionalTestFailed = true;
|
||||
}
|
||||
|
||||
for (int nanFunctionTest = HALF2_OP_HEQ2; nanFunctionTest < HALF2_OP_MAX;
|
||||
nanFunctionTest++) {
|
||||
// HNE2 will not have a NaN test
|
||||
if (nanFunctionTest != HALF2_OP_HNE2) {
|
||||
hipLaunchKernelGGL(__half2Compare, dim3(1, 1, 1), dim3(1, 1, 1), 0, 0,
|
||||
result_D, __half2{0, 0}, n, nanFunctionTest,
|
||||
HALF2_TEST_NAN);
|
||||
hipDeviceSynchronize();
|
||||
HIPCHECK(hipMemcpy(result_H, result_D, n*sizeof(float),
|
||||
hipMemcpyDeviceToHost));
|
||||
if (isFailed(0.0, result_H, n)) {
|
||||
printf("NaN test failed for half function: %d\n", nanFunctionTest);
|
||||
bNanTestFailed = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
hipFree(result_D);
|
||||
free(result_H);
|
||||
|
||||
if ((false == bFunctionalTestFailed) && (false == bNanTestFailed)) {
|
||||
passed();
|
||||
} else {
|
||||
failed("Some Half2 tests failed");
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1,78 +0,0 @@
|
||||
/*
|
||||
Copyright (c) 2015 - 2021 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:
|
||||
|
||||
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.
|
||||
*/
|
||||
|
||||
/* HIT_START
|
||||
* BUILD: %t %s ../test_common.cpp
|
||||
* TEST: %t
|
||||
* HIT_END
|
||||
*/
|
||||
|
||||
|
||||
#include <hip/hip_runtime.h>
|
||||
#include <hip/device_functions.h>
|
||||
#include "test_common.h"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
using namespace std;
|
||||
|
||||
#pragma GCC diagnostic ignored "-Wall"
|
||||
#pragma clang diagnostic ignored "-Wunused-variable"
|
||||
|
||||
__device__ void integer_intrinsics() {
|
||||
__brev((unsigned int)10);
|
||||
__brevll((unsigned long long)10);
|
||||
__byte_perm((unsigned int)0, (unsigned int)0, 0);
|
||||
__clz((int)10);
|
||||
__clzll((long long)10);
|
||||
__ffs((int)10);
|
||||
__ffsll((long long)10);
|
||||
__funnelshift_l((unsigned int)0xfacefeed, (unsigned int)0xdeadbeef, 0);
|
||||
__funnelshift_lc((unsigned int)0xfacefeed, (unsigned int)0xdeadbeef, 0);
|
||||
__funnelshift_r((unsigned int)0xfacefeed, (unsigned int)0xdeadbeef, 0);
|
||||
__funnelshift_rc((unsigned int)0xfacefeed, (unsigned int)0xdeadbeef, 0);
|
||||
__hadd((int)1, (int)3);
|
||||
__mul24((int)1, (int)2);
|
||||
__mul64hi((long long)1, (long long)2);
|
||||
__mulhi((int)1, (int)2);
|
||||
__popc((unsigned int)4);
|
||||
__popcll((unsigned long long)4);
|
||||
int a = min((int)4, (int)5);
|
||||
int b = max((int)4, (int)5);
|
||||
__rhadd((int)1, (int)2);
|
||||
__sad((int)1, (int)2, 0);
|
||||
__uhadd((unsigned int)1, (unsigned int)3);
|
||||
__umul24((unsigned int)1, (unsigned int)2);
|
||||
__umul64hi((unsigned long long)1, (unsigned long long)2);
|
||||
__umulhi((unsigned int)1, (unsigned int)2);
|
||||
__urhadd((unsigned int)1, (unsigned int)2);
|
||||
__usad((unsigned int)1, (unsigned int)2, 0);
|
||||
|
||||
assert(1);
|
||||
}
|
||||
|
||||
__global__ void compileIntegerIntrinsics(int ignored) { integer_intrinsics(); }
|
||||
|
||||
int main() {
|
||||
hipLaunchKernelGGL(compileIntegerIntrinsics, dim3(1, 1, 1), dim3(1, 1, 1), 0, 0, 1);
|
||||
passed();
|
||||
}
|
||||
@@ -1,193 +0,0 @@
|
||||
/*
|
||||
Copyright (c) 2015 - 2021 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:
|
||||
|
||||
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.
|
||||
*/
|
||||
|
||||
/* HIT_START
|
||||
* BUILD: %t %s ../test_common.cpp CLANG_OPTIONS -Xclang -fallow-half-arguments-and-returns EXCLUDE_HIP_PLATFORM nvidia
|
||||
* TEST: %t
|
||||
* HIT_END
|
||||
*/
|
||||
|
||||
#define HIP_TEMPLATE_KERNEL_LAUNCH
|
||||
#include "hip/hip_runtime.h"
|
||||
#include "test_common.h"
|
||||
|
||||
__global__ void kernel_abs_int64(long long* input, long long* output) {
|
||||
int tx = threadIdx.x;
|
||||
output[tx] = abs(input[tx]);
|
||||
}
|
||||
|
||||
__global__ void kernel_lgamma_double(double* input, double* output) {
|
||||
int tx = threadIdx.x;
|
||||
output[tx] = lgamma(input[tx]);
|
||||
}
|
||||
|
||||
#define CHECK_LGAMMA_DOUBLE(IN, OUT, EXP) \
|
||||
{ \
|
||||
if (OUT != EXP) { \
|
||||
failed("check_abs_int64 failed on %f (output = %f, expected = %fd)\n", IN, OUT, EXP); \
|
||||
} \
|
||||
}
|
||||
|
||||
#define CHECK_ABS_INT64(IN, OUT, EXP) \
|
||||
{ \
|
||||
if (OUT != EXP) { \
|
||||
failed("check_abs_int64 failed on %lld (output = %lld, expected = %lld)\n", IN, OUT, \
|
||||
EXP); \
|
||||
} \
|
||||
}
|
||||
|
||||
void check_lgamma_double() {
|
||||
using datatype_t = double;
|
||||
|
||||
const int NUM_INPUTS = 8;
|
||||
auto memsize = NUM_INPUTS * sizeof(datatype_t);
|
||||
|
||||
// allocate memories
|
||||
datatype_t* inputCPU = (datatype_t*)malloc(memsize);
|
||||
datatype_t* outputCPU = (datatype_t*)malloc(memsize);
|
||||
datatype_t* inputGPU = nullptr;
|
||||
hipMalloc((void**)&inputGPU, memsize);
|
||||
datatype_t* outputGPU = nullptr;
|
||||
hipMalloc((void**)&outputGPU, memsize);
|
||||
|
||||
// populate input
|
||||
for (int i = 0; i < NUM_INPUTS; i++) {
|
||||
inputCPU[i] = -3.5 + i;
|
||||
}
|
||||
|
||||
// copy inputs to device
|
||||
hipMemcpy(inputGPU, inputCPU, memsize, hipMemcpyHostToDevice);
|
||||
|
||||
// launch kernel
|
||||
hipLaunchKernelGGL(kernel_lgamma_double, dim3(1), dim3(NUM_INPUTS), 0, 0, inputGPU, outputGPU);
|
||||
|
||||
// copy outputs from device
|
||||
hipMemcpy(outputCPU, outputGPU, memsize, hipMemcpyDeviceToHost);
|
||||
|
||||
// check outputs
|
||||
for (int i = 0; i < NUM_INPUTS; i++) {
|
||||
CHECK_LGAMMA_DOUBLE(inputCPU[i], outputCPU[i], lgamma(inputCPU[i]));
|
||||
}
|
||||
|
||||
// free memories
|
||||
hipFree(inputGPU);
|
||||
hipFree(outputGPU);
|
||||
free(inputCPU);
|
||||
free(outputCPU);
|
||||
|
||||
// done
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
void check_abs_int64() {
|
||||
using datatype_t = long long;
|
||||
|
||||
const int NUM_INPUTS = 8;
|
||||
auto memsize = NUM_INPUTS * sizeof(datatype_t);
|
||||
|
||||
// allocate memories
|
||||
datatype_t* inputCPU = (datatype_t*)malloc(memsize);
|
||||
datatype_t* outputCPU = (datatype_t*)malloc(memsize);
|
||||
datatype_t* inputGPU = nullptr;
|
||||
hipMalloc((void**)&inputGPU, memsize);
|
||||
datatype_t* outputGPU = nullptr;
|
||||
hipMalloc((void**)&outputGPU, memsize);
|
||||
|
||||
// populate input
|
||||
inputCPU[0] = -81985529216486895ll;
|
||||
inputCPU[1] = 81985529216486895ll;
|
||||
inputCPU[2] = -1250999896491ll;
|
||||
inputCPU[3] = 1250999896491ll;
|
||||
inputCPU[4] = -19088743ll;
|
||||
inputCPU[5] = 19088743ll;
|
||||
inputCPU[6] = -291ll;
|
||||
inputCPU[7] = 291ll;
|
||||
|
||||
// copy inputs to device
|
||||
hipMemcpy(inputGPU, inputCPU, memsize, hipMemcpyHostToDevice);
|
||||
|
||||
// launch kernel
|
||||
hipLaunchKernelGGL(kernel_abs_int64, dim3(1), dim3(NUM_INPUTS), 0, 0, inputGPU, outputGPU);
|
||||
|
||||
// copy outputs from device
|
||||
hipMemcpy(outputCPU, outputGPU, memsize, hipMemcpyDeviceToHost);
|
||||
|
||||
// check outputs
|
||||
CHECK_ABS_INT64(inputCPU[0], outputCPU[0], outputCPU[1]);
|
||||
CHECK_ABS_INT64(inputCPU[1], outputCPU[1], outputCPU[1]);
|
||||
CHECK_ABS_INT64(inputCPU[2], outputCPU[2], outputCPU[3]);
|
||||
CHECK_ABS_INT64(inputCPU[3], outputCPU[3], outputCPU[3]);
|
||||
CHECK_ABS_INT64(inputCPU[4], outputCPU[4], outputCPU[5]);
|
||||
CHECK_ABS_INT64(inputCPU[5], outputCPU[5], outputCPU[5]);
|
||||
CHECK_ABS_INT64(inputCPU[6], outputCPU[6], outputCPU[7]);
|
||||
CHECK_ABS_INT64(inputCPU[7], outputCPU[7], outputCPU[7]);
|
||||
|
||||
// free memories
|
||||
hipFree(inputGPU);
|
||||
hipFree(outputGPU);
|
||||
free(inputCPU);
|
||||
free(outputCPU);
|
||||
|
||||
// done
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
template <class T, class F>
|
||||
__global__ void kernel_simple(F f, T* out) {
|
||||
*out = f();
|
||||
}
|
||||
|
||||
template <class T, class F>
|
||||
void check_simple(F f, T expected, const char* file, unsigned line) {
|
||||
auto memsize = sizeof(T);
|
||||
T* outputCPU = (T*)malloc(memsize);
|
||||
T* outputGPU = nullptr;
|
||||
hipMalloc((void**)&outputGPU, memsize);
|
||||
hipLaunchKernelGGL(kernel_simple, 1, 1, 0, 0, f, outputGPU);
|
||||
hipMemcpy(outputCPU, outputGPU, memsize, hipMemcpyDeviceToHost);
|
||||
if (*outputCPU != expected) {
|
||||
failed("%s line %u : check failed (output = %lf, expected = %lf)\n", file, line,
|
||||
(double)(*outputCPU), (double)expected);
|
||||
}
|
||||
hipFree(outputGPU);
|
||||
free(outputCPU);
|
||||
}
|
||||
#define CHECK_SIMPLE(lambda, expected) check_simple(lambda, expected, __FILE__, __LINE__);
|
||||
|
||||
void test_fp16() {
|
||||
CHECK_SIMPLE([] __device__() { return max<__fp16>(1.0f, 2.0f); }, 2.0f);
|
||||
CHECK_SIMPLE([] __device__() { return min<__fp16>(1.0f, 2.0f); }, 1.0f);
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
HipTest::parseStandardArguments(argc, argv, true);
|
||||
|
||||
check_abs_int64();
|
||||
|
||||
// check_lgamma_double();
|
||||
|
||||
test_fp16();
|
||||
|
||||
passed();
|
||||
}
|
||||
@@ -1,200 +0,0 @@
|
||||
/*
|
||||
Copyright (c) 2015 - 2021 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:
|
||||
|
||||
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.
|
||||
*/
|
||||
|
||||
/* HIT_START
|
||||
* BUILD: %t %s ../test_common.cpp CLANG_OPTIONS -Xclang -fallow-half-arguments-and-returns EXCLUDE_HIP_PLATFORM nvidia
|
||||
* TEST: %t
|
||||
* HIT_END
|
||||
*/
|
||||
|
||||
#include "hip/hip_runtime.h"
|
||||
#include "test_common.h"
|
||||
|
||||
__global__ void kernel_abs_int64(long long *input, long long *output) {
|
||||
int tx = threadIdx.x;
|
||||
output[tx] = abs(input[tx]);
|
||||
}
|
||||
|
||||
__global__ void kernel_lgamma_double(double *input, double *output) {
|
||||
int tx = threadIdx.x;
|
||||
output[tx] = lgamma(input[tx]);
|
||||
}
|
||||
|
||||
#define CHECK_LGAMMA_DOUBLE(IN, OUT, EXP) \
|
||||
{ \
|
||||
if (OUT != EXP) { \
|
||||
failed("check_abs_int64 failed on %f (output = %f, expected = %fd)\n", IN, OUT, EXP); \
|
||||
} \
|
||||
}
|
||||
|
||||
#define CHECK_ABS_INT64(IN, OUT, EXP) \
|
||||
{ \
|
||||
if (OUT != EXP) { \
|
||||
failed("check_abs_int64 failed on %lld (output = %lld, expected = %lld)\n", IN, OUT, EXP); \
|
||||
} \
|
||||
}
|
||||
|
||||
void check_lgamma_double() {
|
||||
|
||||
using datatype_t = double;
|
||||
|
||||
const int NUM_INPUTS = 8;
|
||||
auto memsize = NUM_INPUTS * sizeof(datatype_t);
|
||||
|
||||
// allocate memories
|
||||
datatype_t *inputCPU = (datatype_t *) malloc(memsize);
|
||||
datatype_t *outputCPU = (datatype_t *) malloc(memsize);
|
||||
datatype_t *inputGPU = nullptr; hipMalloc((void**)&inputGPU, memsize);
|
||||
datatype_t *outputGPU = nullptr; hipMalloc((void**)&outputGPU, memsize);
|
||||
|
||||
// populate input
|
||||
for (int i=0; i<NUM_INPUTS; i++) {
|
||||
inputCPU[i] = -3.5 + i;
|
||||
}
|
||||
|
||||
// copy inputs to device
|
||||
hipMemcpy(inputGPU, inputCPU, memsize, hipMemcpyHostToDevice);
|
||||
|
||||
// launch kernel
|
||||
hipLaunchKernelGGL(kernel_lgamma_double, dim3(1), dim3(NUM_INPUTS), 0, 0, inputGPU, outputGPU);
|
||||
|
||||
// copy outputs from device
|
||||
hipMemcpy(outputCPU, outputGPU, memsize, hipMemcpyDeviceToHost);
|
||||
|
||||
// check outputs
|
||||
for (int i=0; i<NUM_INPUTS; i++) {
|
||||
CHECK_LGAMMA_DOUBLE(inputCPU[i], outputCPU[i], lgamma(inputCPU[i]));
|
||||
}
|
||||
|
||||
// free memories
|
||||
hipFree(inputGPU);
|
||||
hipFree(outputGPU);
|
||||
free(inputCPU);
|
||||
free(outputCPU);
|
||||
|
||||
// done
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
void check_abs_int64() {
|
||||
|
||||
using datatype_t = long long;
|
||||
|
||||
const int NUM_INPUTS = 8;
|
||||
auto memsize = NUM_INPUTS * sizeof(datatype_t);
|
||||
|
||||
// allocate memories
|
||||
datatype_t *inputCPU = (datatype_t *) malloc(memsize);
|
||||
datatype_t *outputCPU = (datatype_t *) malloc(memsize);
|
||||
datatype_t *inputGPU = nullptr; hipMalloc((void**)&inputGPU, memsize);
|
||||
datatype_t *outputGPU = nullptr; hipMalloc((void**)&outputGPU, memsize);
|
||||
|
||||
// populate input
|
||||
inputCPU[0] = -81985529216486895ll;
|
||||
inputCPU[1] = 81985529216486895ll;
|
||||
inputCPU[2] = -1250999896491ll;
|
||||
inputCPU[3] = 1250999896491ll;
|
||||
inputCPU[4] = -19088743ll;
|
||||
inputCPU[5] = 19088743ll;
|
||||
inputCPU[6] = -291ll;
|
||||
inputCPU[7] = 291ll;
|
||||
|
||||
// copy inputs to device
|
||||
hipMemcpy(inputGPU, inputCPU, memsize, hipMemcpyHostToDevice);
|
||||
|
||||
// launch kernel
|
||||
hipLaunchKernelGGL(kernel_abs_int64, dim3(1), dim3(NUM_INPUTS), 0, 0, inputGPU, outputGPU);
|
||||
|
||||
// copy outputs from device
|
||||
hipMemcpy(outputCPU, outputGPU, memsize, hipMemcpyDeviceToHost);
|
||||
|
||||
// check outputs
|
||||
CHECK_ABS_INT64(inputCPU[0], outputCPU[0], outputCPU[1]);
|
||||
CHECK_ABS_INT64(inputCPU[1], outputCPU[1], outputCPU[1]);
|
||||
CHECK_ABS_INT64(inputCPU[2], outputCPU[2], outputCPU[3]);
|
||||
CHECK_ABS_INT64(inputCPU[3], outputCPU[3], outputCPU[3]);
|
||||
CHECK_ABS_INT64(inputCPU[4], outputCPU[4], outputCPU[5]);
|
||||
CHECK_ABS_INT64(inputCPU[5], outputCPU[5], outputCPU[5]);
|
||||
CHECK_ABS_INT64(inputCPU[6], outputCPU[6], outputCPU[7]);
|
||||
CHECK_ABS_INT64(inputCPU[7], outputCPU[7], outputCPU[7]);
|
||||
|
||||
// free memories
|
||||
hipFree(inputGPU);
|
||||
hipFree(outputGPU);
|
||||
free(inputCPU);
|
||||
free(outputCPU);
|
||||
|
||||
// done
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
template<class T, class F>
|
||||
__global__ void kernel_simple(F f, T *out) {
|
||||
*out = f();
|
||||
}
|
||||
|
||||
template<class T, class F>
|
||||
void check_simple(F f, T expected, const char* file, unsigned line) {
|
||||
auto memsize = sizeof(T);
|
||||
T *outputCPU = (T *) malloc(memsize);
|
||||
T *outputGPU = nullptr;
|
||||
hipMalloc((void**)&outputGPU, memsize);
|
||||
hipLaunchKernelGGL(kernel_simple, 1, 1, 0, 0, f, outputGPU);
|
||||
hipMemcpy(outputCPU, outputGPU, memsize, hipMemcpyDeviceToHost);
|
||||
if (*outputCPU != expected) {
|
||||
failed("%s line %u : check failed (output = %lf, expected = %lf)\n",
|
||||
file, line, (double)(*outputCPU), (double)expected);
|
||||
}
|
||||
hipFree(outputGPU);
|
||||
free(outputCPU);
|
||||
}
|
||||
#define CHECK_SIMPLE(lambda, expected) \
|
||||
check_simple(lambda, expected, __FILE__, __LINE__);
|
||||
|
||||
void test_fp16() {
|
||||
CHECK_SIMPLE([]__device__(){ return max<__fp16>(1.0f, 2.0f); }, 2.0f);
|
||||
CHECK_SIMPLE([]__device__(){ return min<__fp16>(1.0f, 2.0f); }, 1.0f);
|
||||
}
|
||||
|
||||
void test_pown() {
|
||||
CHECK_SIMPLE([]__device__(){ return powif(2.0f, 2); }, 4.0f);
|
||||
CHECK_SIMPLE([]__device__(){ return powi(2.0, 2); }, 4.0);
|
||||
CHECK_SIMPLE([]__device__(){ return pow(2.0f, 2); }, 4.0f);
|
||||
CHECK_SIMPLE([]__device__(){ return pow(2.0, 2); }, 4.0);
|
||||
CHECK_SIMPLE([]__device__(){ return pow(2.0f16, 2); }, 4.0f16);
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
HipTest::parseStandardArguments(argc, argv, true);
|
||||
|
||||
check_abs_int64();
|
||||
|
||||
// check_lgamma_double();
|
||||
|
||||
test_fp16();
|
||||
|
||||
test_pown();
|
||||
|
||||
passed();
|
||||
}
|
||||
@@ -1,365 +0,0 @@
|
||||
/*
|
||||
Copyright (c) 2015 - 2021 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:
|
||||
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.
|
||||
*/
|
||||
|
||||
/* HIT_START
|
||||
* BUILD: %t %s ../test_common.cpp NVCC_OPTIONS -std=c++11 --gpu-architecture=sm_60
|
||||
* TEST: %t
|
||||
* HIT_END
|
||||
*/
|
||||
|
||||
// Includes HIP Runtime
|
||||
#include "hip/hip_runtime.h"
|
||||
#include <test_common.h>
|
||||
|
||||
// includes, system
|
||||
#include <algorithm>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
#include <type_traits>
|
||||
|
||||
using namespace std;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Auto-Verification Code
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
bool verifyBitwise(...) {
|
||||
return true;
|
||||
}
|
||||
|
||||
template<typename T, typename enable_if<is_integral<T>{}>::type* = nullptr>
|
||||
bool verifyBitwise(T* gpuData, int len) {
|
||||
T val = 0xff;
|
||||
|
||||
for (int i = 0; i < len; ++i) {
|
||||
// 9th element should be 1
|
||||
val &= (2 * i + 7);
|
||||
}
|
||||
|
||||
if (val != gpuData[8]) {
|
||||
printf("atomicAnd failed: gpuData[8]=%llu, expect=%llu\n",
|
||||
(unsigned long long)gpuData[8], (unsigned long long)val);
|
||||
return false;
|
||||
}
|
||||
|
||||
val = 0;
|
||||
|
||||
for (int i = 0; i < len; ++i) {
|
||||
// 10th element should be 0xff
|
||||
val |= (1 << i);
|
||||
}
|
||||
|
||||
if (val != gpuData[9]) {
|
||||
printf("atomicOr failed\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
val = 0xff;
|
||||
|
||||
for (int i = 0; i < len; ++i) {
|
||||
// 11th element should be 0xff
|
||||
val ^= i;
|
||||
}
|
||||
|
||||
if (val != gpuData[10]) {
|
||||
printf("atomicXor failed\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool verifySub(...) {
|
||||
return true;
|
||||
}
|
||||
|
||||
template<
|
||||
typename T,
|
||||
typename enable_if<
|
||||
is_same<T, int>{} || is_same<T, unsigned int>{}>::type* = nullptr>
|
||||
bool verifySub(T* gpuData, int len) {
|
||||
T val = 0;
|
||||
|
||||
for (int i = 0; i < len; ++i) {
|
||||
val -= 10;
|
||||
}
|
||||
|
||||
if (val != gpuData[1]) {
|
||||
printf("atomicSub failed: gpuData[1]=%d, expected=%d\n",
|
||||
(int)gpuData[1], (int)val);
|
||||
return false;
|
||||
} else {
|
||||
printf("atomicSub succeeded: gpuData[1]=%d, expected=%d\n",
|
||||
(int)gpuData[1], (int)val);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool verifyExch(...) {
|
||||
return true;
|
||||
}
|
||||
|
||||
template<typename T, typename enable_if<!is_same<T, double> {}>::type* = nullptr>
|
||||
bool computeExchExch(T* gpuData, int len) {
|
||||
T val = 0;
|
||||
|
||||
bool found = false;
|
||||
|
||||
for (T i = 0; i < len; ++i) {
|
||||
if (i == gpuData[2]) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!found) {
|
||||
printf("atomicExch failed\n");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool VerifyIntegral(...) {
|
||||
return true;
|
||||
}
|
||||
|
||||
template<typename T, typename enable_if<is_integral<T>{}>::type* = nullptr>
|
||||
bool VerifyIntegral(T* gpuData, int len) {
|
||||
T val = 0;
|
||||
|
||||
bool found = false;
|
||||
|
||||
for (T i = 0; i < len; ++i) {
|
||||
// fourth element should be len-1
|
||||
val = max(val, i);
|
||||
}
|
||||
|
||||
if (val != gpuData[3]) {
|
||||
printf("atomicMax failed: gpuData[3]=%llu, expected=%llu\n",
|
||||
(unsigned long long)gpuData[3], (unsigned long long)val);
|
||||
return false;
|
||||
} else {
|
||||
printf("atomicMax succeeded: gpuData[3]=%llu, expected=%llu\n",
|
||||
(unsigned long long)gpuData[3], (unsigned long long)val);
|
||||
}
|
||||
|
||||
val = 1 << 8;
|
||||
|
||||
for (T i = 0; i < len; ++i) {
|
||||
val = min(val, i);
|
||||
}
|
||||
|
||||
if (val != gpuData[4]) {
|
||||
printf("atomicMin failed\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
int limit = 17;
|
||||
val = 0;
|
||||
|
||||
for (int i = 0; i < len; ++i) {
|
||||
val = (val >= limit) ? 0 : val + 1;
|
||||
}
|
||||
|
||||
if (val != gpuData[5]) {
|
||||
printf("atomicInc failed\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
limit = 137;
|
||||
val = 0;
|
||||
|
||||
for (int i = 0; i < len; ++i) {
|
||||
val = ((val == 0) || (val > limit)) ? limit : val - 1;
|
||||
}
|
||||
|
||||
if (val != gpuData[6]) {
|
||||
printf("atomicDec failed\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
found = false;
|
||||
|
||||
for (T i = 0; i < len; ++i) {
|
||||
// eighth element should be a member of [0, len)
|
||||
if (i == gpuData[7]) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!found) {
|
||||
printf("atomicCAS failed\n");
|
||||
return false;
|
||||
}
|
||||
return verifyBitwise(gpuData, len) && verifySub(gpuData, len);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
bool verifyData(T* gpuData, int len) {
|
||||
T val = 0;
|
||||
|
||||
for (int i = 0; i < len; ++i) {
|
||||
val += 10;
|
||||
}
|
||||
|
||||
if (val != gpuData[0]) {
|
||||
printf("atomicAdd failed\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
return VerifyIntegral(gpuData, len) && verifyExch(gpuData, len);
|
||||
}
|
||||
|
||||
__device__
|
||||
void testKernelExch(...) {}
|
||||
|
||||
template<typename T, typename enable_if<!is_same<T, double>{}>::type* = nullptr>
|
||||
__device__
|
||||
void testKernelExch(T* g_odata) {
|
||||
// access thread id
|
||||
const T tid = blockDim.x * blockIdx.x + threadIdx.x;
|
||||
|
||||
// Atomic exchange
|
||||
atomicExch(&g_odata[2], tid);
|
||||
}
|
||||
|
||||
__device__
|
||||
void testKernelSub(...) {}
|
||||
|
||||
template<
|
||||
typename T,
|
||||
typename enable_if<
|
||||
is_same<T, int>{} || is_same<T, unsigned int>{}>::type* = nullptr>
|
||||
__device__
|
||||
void testKernelSub(T* g_odata) {
|
||||
// Atomic subtraction (final should be 0)
|
||||
atomicSub(&g_odata[1], 10);
|
||||
}
|
||||
|
||||
__device__
|
||||
void testKernelIntegral(...) {}
|
||||
|
||||
template<typename T, typename enable_if<is_integral<T>{}>::type* = nullptr>
|
||||
__device__
|
||||
void testKernelIntegral(T* g_odata) {
|
||||
// access thread id
|
||||
const T tid = blockDim.x * blockIdx.x + threadIdx.x;
|
||||
|
||||
// Atomic maximum
|
||||
atomicMax(&g_odata[3], tid);
|
||||
|
||||
// Atomic minimum
|
||||
atomicMin(&g_odata[4], tid);
|
||||
|
||||
// Atomic increment (modulo 17+1)
|
||||
atomicInc((unsigned int*)&g_odata[5], 17);
|
||||
|
||||
// Atomic decrement
|
||||
atomicDec((unsigned int*)&g_odata[6], 137);
|
||||
|
||||
// Atomic compare-and-swap
|
||||
atomicCAS(&g_odata[7], tid - 1, tid);
|
||||
|
||||
// Bitwise atomic instructions
|
||||
|
||||
// Atomic AND
|
||||
atomicAnd(&g_odata[8], 2 * tid + 7);
|
||||
|
||||
// Atomic OR
|
||||
atomicOr(&g_odata[9], 1 << tid);
|
||||
|
||||
// Atomic XOR
|
||||
atomicXor(&g_odata[10], tid);
|
||||
|
||||
testKernelSub(g_odata);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
__global__ void testKernel(T* g_odata) {
|
||||
// Atomic addition
|
||||
atomicAdd(&g_odata[0], 10);
|
||||
|
||||
testKernelIntegral(g_odata);
|
||||
testKernelExch(g_odata);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void runTest() {
|
||||
bool testResult = true;
|
||||
unsigned int numThreads = 256;
|
||||
unsigned int numBlocks = 64;
|
||||
unsigned int numData = 11;
|
||||
unsigned int memSize = sizeof(T) * numData;
|
||||
|
||||
printf("runTest<%s>, total thread=%u\n", typeid(T).name(), numThreads*numBlocks);
|
||||
|
||||
// allocate mem for the result on host side
|
||||
T* hOData = (T*)malloc(memSize);
|
||||
|
||||
// initialize the memory
|
||||
for (unsigned int i = 0; i < numData; i++) hOData[i] = 0;
|
||||
|
||||
// To make the AND and XOR tests generate something other than 0...
|
||||
hOData[8] = hOData[10] = 0xff;
|
||||
|
||||
// allocate device memory for result
|
||||
T* dOData;
|
||||
hipMalloc((void**)&dOData, memSize);
|
||||
// copy host memory to device to initialize to zero
|
||||
hipMemcpy(dOData, hOData, memSize, hipMemcpyHostToDevice);
|
||||
|
||||
// execute the kernel
|
||||
hipLaunchKernelGGL(
|
||||
testKernel, dim3(numBlocks), dim3(numThreads), 0, 0, dOData);
|
||||
|
||||
// Copy result from device to host
|
||||
hipMemcpy(hOData, dOData, memSize, hipMemcpyDeviceToHost);
|
||||
|
||||
// Compute reference solution
|
||||
testResult = verifyData(hOData, numThreads * numBlocks);
|
||||
|
||||
// Cleanup memory
|
||||
free(hOData);
|
||||
hipFree(dOData);
|
||||
|
||||
if(!testResult) {
|
||||
failed("runTest<%s> failed\n", typeid(T).name());
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
hipDeviceProp_t deviceProp;
|
||||
hipGetDeviceProperties(&deviceProp, 0);
|
||||
// Statistics about the GPU device
|
||||
printf(
|
||||
"> GPU device has %d Multi-Processors, "
|
||||
"SM %d.%d compute capabilities\n\n",
|
||||
deviceProp.multiProcessorCount, deviceProp.major, deviceProp.minor);
|
||||
|
||||
runTest<int>();
|
||||
runTest<unsigned int>();
|
||||
runTest<unsigned long long>();
|
||||
runTest<float>();
|
||||
runTest<double>();
|
||||
|
||||
hipDeviceReset();
|
||||
passed();
|
||||
}
|
||||
@@ -1,111 +0,0 @@
|
||||
/*
|
||||
Copyright (c) 2015 - 2021 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:
|
||||
|
||||
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.
|
||||
*/
|
||||
/* HIT_START
|
||||
* BUILD: %t %s ../test_common.cpp
|
||||
* TEST: %t
|
||||
* HIT_END
|
||||
*/
|
||||
|
||||
#include <hip/hip_runtime.h>
|
||||
#include <hip/device_functions.h>
|
||||
|
||||
#include "test_common.h"
|
||||
|
||||
#pragma GCC diagnostic ignored "-Wall"
|
||||
#pragma clang diagnostic ignored "-Wunused-variable"
|
||||
|
||||
__device__ void single_precision_intrinsics() {
|
||||
float fX, fY;
|
||||
|
||||
__cosf(0.0f);
|
||||
__exp10f(0.0f);
|
||||
__expf(0.0f);
|
||||
#if defined OCML_BASIC_ROUNDED_OPERATIONS
|
||||
__fadd_rd(0.0f, 1.0f);
|
||||
#endif
|
||||
__fadd_rn(0.0f, 1.0f);
|
||||
#if defined OCML_BASIC_ROUNDED_OPERATIONS
|
||||
__fadd_ru(0.0f, 1.0f);
|
||||
__fadd_rz(0.0f, 1.0f);
|
||||
__fdiv_rd(4.0f, 2.0f);
|
||||
#endif
|
||||
__fdiv_rn(4.0f, 2.0f);
|
||||
#if defined OCML_BASIC_ROUNDED_OPERATIONS
|
||||
__fdiv_ru(4.0f, 2.0f);
|
||||
__fdiv_rz(4.0f, 2.0f);
|
||||
#endif
|
||||
__fdividef(4.0f, 2.0f);
|
||||
#if defined OCML_BASIC_ROUNDED_OPERATIONS
|
||||
__fmaf_rd(1.0f, 2.0f, 3.0f);
|
||||
#endif
|
||||
__fmaf_rn(1.0f, 2.0f, 3.0f);
|
||||
#if defined OCML_BASIC_ROUNDED_OPERATIONS
|
||||
__fmaf_ru(1.0f, 2.0f, 3.0f);
|
||||
__fmaf_rz(1.0f, 2.0f, 3.0f);
|
||||
__fmul_rd(1.0f, 2.0f);
|
||||
#endif
|
||||
__fmul_rn(1.0f, 2.0f);
|
||||
#if defined OCML_BASIC_ROUNDED_OPERATIONS
|
||||
__fmul_ru(1.0f, 2.0f);
|
||||
__fmul_rz(1.0f, 2.0f);
|
||||
__frcp_rd(2.0f);
|
||||
#endif
|
||||
__frcp_rn(2.0f);
|
||||
#if defined OCML_BASIC_ROUNDED_OPERATIONS
|
||||
__frcp_ru(2.0f);
|
||||
__frcp_rz(2.0f);
|
||||
#endif
|
||||
__frsqrt_rn(4.0f);
|
||||
#if defined OCML_BASIC_ROUNDED_OPERATIONS
|
||||
__fsqrt_rd(4.0f);
|
||||
#endif
|
||||
__fsqrt_rn(4.0f);
|
||||
#if defined OCML_BASIC_ROUNDED_OPERATIONS
|
||||
__fsqrt_ru(4.0f);
|
||||
__fsqrt_rz(4.0f);
|
||||
__fsub_rd(2.0f, 1.0f);
|
||||
#endif
|
||||
__fsub_rn(2.0f, 1.0f);
|
||||
#if defined OCML_BASIC_ROUNDED_OPERATIONS
|
||||
__fsub_ru(2.0f, 1.0f);
|
||||
__fsub_rz(2.0f, 1.0f);
|
||||
#endif
|
||||
__log10f(1.0f);
|
||||
__log2f(1.0f);
|
||||
__logf(1.0f);
|
||||
__powf(1.0f, 0.0f);
|
||||
__saturatef(0.1f);
|
||||
__sincosf(0.0f, &fX, &fY);
|
||||
__sinf(0.0f);
|
||||
__tanf(0.0f);
|
||||
}
|
||||
|
||||
|
||||
__global__ void compileSinglePrecisionIntrinsics(int ignored) {
|
||||
single_precision_intrinsics();
|
||||
}
|
||||
|
||||
|
||||
int main() {
|
||||
hipLaunchKernelGGL(compileSinglePrecisionIntrinsics, dim3(1, 1, 1), dim3(1, 1, 1), 0, 0, 1);
|
||||
passed();
|
||||
}
|
||||
@@ -1,139 +0,0 @@
|
||||
/*
|
||||
Copyright (c) 2015 - 2021 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:
|
||||
|
||||
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.
|
||||
*/
|
||||
|
||||
/* HIT_START
|
||||
* BUILD: %t %s ../test_common.cpp
|
||||
* TEST: %t
|
||||
* HIT_END
|
||||
*/
|
||||
|
||||
#include <hip/hip_runtime.h>
|
||||
#include <hip/math_functions.h>
|
||||
#include "test_common.h"
|
||||
|
||||
#pragma GCC diagnostic ignored "-Wall"
|
||||
#pragma clang diagnostic ignored "-Wunused-variable"
|
||||
|
||||
__device__ void single_precision_math_functions() {
|
||||
int iX;
|
||||
float fX, fY;
|
||||
|
||||
acosf(1.0f);
|
||||
acoshf(1.0f);
|
||||
asinf(0.0f);
|
||||
asinhf(0.0f);
|
||||
atan2f(0.0f, 1.0f);
|
||||
atanf(0.0f);
|
||||
atanhf(0.0f);
|
||||
cbrtf(0.0f);
|
||||
ceilf(0.0f);
|
||||
copysignf(1.0f, -2.0f);
|
||||
cosf(0.0f);
|
||||
coshf(0.0f);
|
||||
cospif(0.0f);
|
||||
// cyl_bessel_i0f(0.0f);
|
||||
// cyl_bessel_i1f(0.0f);
|
||||
erfcf(0.0f);
|
||||
erfcinvf(2.0f);
|
||||
erfcxf(0.0f);
|
||||
erff(0.0f);
|
||||
erfinvf(1.0f);
|
||||
exp10f(0.0f);
|
||||
exp2f(0.0f);
|
||||
expf(0.0f);
|
||||
expm1f(0.0f);
|
||||
fabsf(1.0f);
|
||||
fdimf(1.0f, 0.0f);
|
||||
fdividef(0.0f, 1.0f);
|
||||
floorf(0.0f);
|
||||
fmaf(1.0f, 2.0f, 3.0f);
|
||||
fmaxf(0.0f, 0.0f);
|
||||
fminf(0.0f, 0.0f);
|
||||
fmodf(0.0f, 1.0f);
|
||||
frexpf(0.0f, &iX);
|
||||
hypotf(1.0f, 0.0f);
|
||||
ilogbf(1.0f);
|
||||
isfinite(0.0f);
|
||||
isinf(0.0f);
|
||||
isnan(0.0f);
|
||||
j0f(0.0f);
|
||||
j1f(0.0f);
|
||||
jnf(-1.0f, 1.0f);
|
||||
ldexpf(0.0f, 0);
|
||||
// lgammaf(1.0f);
|
||||
llrintf(0.0f);
|
||||
llroundf(0.0f);
|
||||
log10f(1.0f);
|
||||
log1pf(-1.0f);
|
||||
log2f(1.0f);
|
||||
logbf(1.0f);
|
||||
logf(1.0f);
|
||||
lrintf(0.0f);
|
||||
lroundf(0.0f);
|
||||
// modff(0.0f, &fX);
|
||||
nanf("1");
|
||||
nearbyintf(0.0f);
|
||||
// nextafterf(0.0f);
|
||||
norm3df(1.0f, 0.0f, 0.0f);
|
||||
norm4df(1.0f, 0.0f, 0.0f, 0.0f);
|
||||
normcdff(0.0f);
|
||||
normcdfinvf(1.0f);
|
||||
fX = 1.0f;
|
||||
normf(1, &fX);
|
||||
powf(1.0f, 0.0f);
|
||||
// rcbrtf(1.0f);
|
||||
remainderf(2.0f, 1.0f);
|
||||
// remquof(1.0f, 2.0f, &iX);
|
||||
rhypotf(0.0f, 1.0f);
|
||||
rintf(1.0f);
|
||||
rnorm3df(0.0f, 0.0f, 1.0f);
|
||||
rnorm4df(0.0f, 0.0f, 0.0f, 1.0f);
|
||||
fX = 1.0f;
|
||||
rnormf(1, &fX);
|
||||
roundf(0.0f);
|
||||
rsqrtf(1.0f);
|
||||
// scalblnf(0.0f, 1);
|
||||
// scalbnf(0.0f, 1);
|
||||
signbit(1.0f);
|
||||
sincosf(0.0f, &fX, &fY);
|
||||
sincospif(0.0f, &fX, &fY);
|
||||
sinf(0.0f);
|
||||
sinhf(0.0f);
|
||||
sinpif(0.0f);
|
||||
sqrtf(0.0f);
|
||||
tanf(0.0f);
|
||||
tanhf(0.0f);
|
||||
tgammaf(2.0f);
|
||||
truncf(0.0f);
|
||||
y0f(1.0f);
|
||||
y1f(1.0f);
|
||||
ynf(1, 1.0f);
|
||||
}
|
||||
|
||||
__global__ void compileSinglePrecisionMathOnDevice(int ignored) {
|
||||
single_precision_math_functions();
|
||||
}
|
||||
|
||||
int main() {
|
||||
hipLaunchKernelGGL(compileSinglePrecisionMathOnDevice, dim3(1, 1, 1), dim3(1, 1, 1), 0, 0, 1);
|
||||
passed();
|
||||
}
|
||||
@@ -1,152 +0,0 @@
|
||||
/*
|
||||
Copyright (c) 2015 - 2021 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:
|
||||
|
||||
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.
|
||||
*/
|
||||
|
||||
/* HIT_START
|
||||
* BUILD: %t %s ../test_common.cpp
|
||||
* TEST: %t
|
||||
* HIT_END
|
||||
*/
|
||||
|
||||
#include <hip/hip_runtime.h>
|
||||
//#include <hip/math_functions.h>
|
||||
#include "test_common.h"
|
||||
#include <cmath>
|
||||
|
||||
#pragma GCC diagnostic ignored "-Wall"
|
||||
#pragma clang diagnostic ignored "-Wunused-variable"
|
||||
|
||||
__host__ void single_precision_math_functions() {
|
||||
int iX;
|
||||
float fX, fY;
|
||||
|
||||
acosf(1.0f);
|
||||
acoshf(1.0f);
|
||||
asinf(0.0f);
|
||||
asinhf(0.0f);
|
||||
atan2f(0.0f, 1.0f);
|
||||
atanf(0.0f);
|
||||
atanhf(0.0f);
|
||||
cbrtf(0.0f);
|
||||
ceilf(0.0f);
|
||||
copysignf(1.0f, -2.0f);
|
||||
cosf(0.0f);
|
||||
coshf(0.0f);
|
||||
// cospif(0.0f);
|
||||
// cyl_bessel_i0f(0.0f);
|
||||
// cyl_bessel_i1f(0.0f);
|
||||
erfcf(0.0f);
|
||||
// erfcinvf(2.0f);
|
||||
// erfcxf(0.0f);
|
||||
erff(0.0f);
|
||||
// erfinvf(1.0f);
|
||||
#ifdef __unix__
|
||||
exp10f(0.0f);
|
||||
#endif
|
||||
exp2f(0.0f);
|
||||
expf(0.0f);
|
||||
expm1f(0.0f);
|
||||
fabsf(1.0f);
|
||||
fdimf(1.0f, 0.0f);
|
||||
#if defined(__HIP_PLATFORM_AMD__)
|
||||
// fdividef(0.0f, 1.0f);
|
||||
#endif
|
||||
floorf(0.0f);
|
||||
fmaf(1.0f, 2.0f, 3.0f);
|
||||
fmaxf(0.0f, 0.0f);
|
||||
fminf(0.0f, 0.0f);
|
||||
fmodf(0.0f, 1.0f);
|
||||
frexpf(0.0f, &iX);
|
||||
hypotf(1.0f, 0.0f);
|
||||
ilogbf(1.0f);
|
||||
std::isfinite(0.0f);
|
||||
std::isinf(0.0f);
|
||||
std::isnan(0.0f);
|
||||
#ifdef __unix__
|
||||
j0f(0.0f);
|
||||
j1f(0.0f);
|
||||
jnf(-1.0f, 1.0f);
|
||||
#endif
|
||||
ldexpf(0.0f, 0);
|
||||
lgammaf(1.0f);
|
||||
llrintf(0.0f);
|
||||
llroundf(0.0f);
|
||||
log10f(1.0f);
|
||||
log1pf(-1.0f);
|
||||
log2f(1.0f);
|
||||
logbf(1.0f);
|
||||
logf(1.0f);
|
||||
lrintf(0.0f);
|
||||
lroundf(0.0f);
|
||||
modff(0.0f, &fX);
|
||||
nanf("1");
|
||||
nearbyintf(0.0f);
|
||||
// nextafterf(0.0f);
|
||||
#if defined(__HIP_PLATFORM_AMD__)
|
||||
// norm3df(1.0f, 0.0f, 0.0f);
|
||||
// norm4df(1.0f, 0.0f, 0.0f, 0.0f);
|
||||
#endif
|
||||
// normcdff(0.0f);
|
||||
// normcdfinvf(1.0f);
|
||||
// fX = 1.0f; normf(1, &fX);
|
||||
powf(1.0f, 0.0f);
|
||||
// rcbrtf(1.0f);
|
||||
remainderf(2.0f, 1.0f);
|
||||
remquof(1.0f, 2.0f, &iX);
|
||||
#if defined(__HIP_PLATFORM_AMD__)
|
||||
// rhypotf(0.0f, 1.0f);
|
||||
#endif
|
||||
rintf(1.0f);
|
||||
#if defined(__HIP_PLATFORM_AMD__)
|
||||
// rnorm3df(0.0f, 0.0f, 1.0f);
|
||||
// rnorm4df(0.0f, 0.0f, 0.0f, 1.0f);
|
||||
fX = 1.0f; // rnormf(1, &fX);
|
||||
#endif
|
||||
roundf(0.0f);
|
||||
/// rsqrtf(1.0f);
|
||||
scalblnf(0.0f, 1);
|
||||
scalbnf(0.0f, 1);
|
||||
std::signbit(1.0f);
|
||||
#ifdef __unix__
|
||||
sincosf(0.0f, &fX, &fY);
|
||||
#endif
|
||||
// sincospif(0.0f, &fX, &fY);
|
||||
sinf(0.0f);
|
||||
sinhf(0.0f);
|
||||
// sinpif(0.0f);
|
||||
sqrtf(0.0f);
|
||||
tanf(0.0f);
|
||||
tanhf(0.0f);
|
||||
tgammaf(2.0f);
|
||||
truncf(0.0f);
|
||||
#ifdef __unix__
|
||||
y0f(1.0f);
|
||||
y1f(1.0f);
|
||||
ynf(1, 1.0f);
|
||||
#endif
|
||||
}
|
||||
|
||||
static void compileOnHost() { single_precision_math_functions(); }
|
||||
|
||||
int main() {
|
||||
compileOnHost();
|
||||
passed();
|
||||
}
|
||||
@@ -1,167 +0,0 @@
|
||||
/*
|
||||
Copyright (c) 2015 - 2021 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:
|
||||
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 WARRANNTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INNCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANNY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER INN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR INN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
/* HIT_START
|
||||
* BUILD: %t %s NVCC_OPTIONS -std=c++11
|
||||
* TEST: %t
|
||||
* HIT_END
|
||||
*/
|
||||
#include "test_common.h"
|
||||
#include <iostream>
|
||||
#ifdef __HIP_PLATFORM_AMD__
|
||||
#include <complex>
|
||||
using namespace std;
|
||||
#else
|
||||
#include <cuda/std/complex>
|
||||
using namespace cuda::std;
|
||||
#endif
|
||||
|
||||
// Tolerance for error
|
||||
const double tolerance = 1e-6;
|
||||
const bool verbose = false;
|
||||
|
||||
#define LEN 64
|
||||
|
||||
#define ALL_FUN \
|
||||
OP(add) \
|
||||
OP(sub) \
|
||||
OP(mul) \
|
||||
OP(div) \
|
||||
OP(abs) \
|
||||
OP(arg) \
|
||||
OP(sin) \
|
||||
OP(cos)
|
||||
|
||||
#define OP(x) CK_##x,
|
||||
enum CalcKind {
|
||||
ALL_FUN
|
||||
};
|
||||
#undef OP
|
||||
|
||||
#define OP(x) case CK_##x: return #x;
|
||||
std::string getName(enum CalcKind CK) {
|
||||
switch(CK){
|
||||
ALL_FUN
|
||||
}
|
||||
return ""; // To prevent compile warning
|
||||
}
|
||||
#undef OP
|
||||
|
||||
// Calculates function.
|
||||
// If the function has one argument, B is ignored.
|
||||
// If the function returns real number, converts it to a complex number.
|
||||
#define ONE_ARG(func) \
|
||||
case CK_##func: \
|
||||
return complex<FloatT>(func(A));
|
||||
|
||||
template<typename FloatT>
|
||||
__device__ __host__ complex<FloatT> calc(complex<FloatT> A,
|
||||
complex<FloatT> B,
|
||||
enum CalcKind CK) {
|
||||
switch(CK) {
|
||||
case CK_add:
|
||||
return A + B;
|
||||
case CK_sub:
|
||||
return A - B;
|
||||
case CK_mul:
|
||||
return A * B;
|
||||
case CK_div:
|
||||
return A / B;
|
||||
|
||||
ONE_ARG(abs)
|
||||
ONE_ARG(arg)
|
||||
ONE_ARG(sin)
|
||||
ONE_ARG(cos)
|
||||
}
|
||||
return A; // To prevent compile warning
|
||||
}
|
||||
|
||||
template<typename FloatT>
|
||||
__global__ void kernel(complex<FloatT>* A,
|
||||
complex<FloatT>* B, complex<FloatT>* C,
|
||||
enum CalcKind CK) {
|
||||
int tx = threadIdx.x + blockIdx.x * blockDim.x;
|
||||
C[tx] = calc<FloatT>(A[tx], B[tx], CK);
|
||||
}
|
||||
|
||||
template<typename FloatT>
|
||||
void test() {
|
||||
typedef complex<FloatT> ComplexT;
|
||||
|
||||
ComplexT *A, *Ad, *B, *Bd, *C, *Cd, *D;
|
||||
A = new ComplexT[LEN];
|
||||
B = new ComplexT[LEN];
|
||||
C = new ComplexT[LEN];
|
||||
D = new ComplexT[LEN];
|
||||
hipMalloc((void**)&Ad, sizeof(ComplexT)*LEN);
|
||||
hipMalloc((void**)&Bd, sizeof(ComplexT)*LEN);
|
||||
hipMalloc((void**)&Cd, sizeof(ComplexT)*LEN);
|
||||
|
||||
for (uint32_t i = 0; i < LEN; i++) {
|
||||
A[i] = ComplexT((i + 1) * 1.0f, (i + 2) * 1.0f);
|
||||
B[i] = A[i];
|
||||
C[i] = A[i];
|
||||
}
|
||||
hipMemcpy(Ad, A, sizeof(ComplexT)*LEN, hipMemcpyHostToDevice);
|
||||
hipMemcpy(Bd, B, sizeof(ComplexT)*LEN, hipMemcpyHostToDevice);
|
||||
|
||||
// Run kernel for a calculation kind and verify by comparing with host
|
||||
// calculation result. Returns false if fails.
|
||||
auto test_fun = [&](enum CalcKind CK) {
|
||||
hipLaunchKernelGGL(kernel<FloatT>, dim3(1), dim3(LEN), 0, 0, Ad, Bd, Cd, CK);
|
||||
hipMemcpy(C, Cd, sizeof(ComplexT)*LEN, hipMemcpyDeviceToHost);
|
||||
for (int i = 0; i < LEN; i++) {
|
||||
ComplexT Expected = calc(A[i], B[i], CK);
|
||||
FloatT error = abs(C[i] - Expected);
|
||||
if (abs(Expected) > tolerance)
|
||||
error /= abs(Expected);
|
||||
bool pass = error < tolerance;
|
||||
if (verbose || !pass) {
|
||||
std::cout << "Function: " << getName(CK)
|
||||
<< " Operands: " << A[i].real() << ", " << A[i].imag() << "; " <<B[i].real() << ", " << B[i].imag()
|
||||
<< " Result: " << C[i].real() << ", " << C[i].imag()
|
||||
<< " Expected: " << Expected.real() << ", " << Expected.imag()
|
||||
<< " Error: " << error
|
||||
<< " Pass: " << pass
|
||||
<< std::endl;
|
||||
}
|
||||
if (!pass)
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
};
|
||||
|
||||
#define OP(x) assert(test_fun(CK_##x));
|
||||
ALL_FUN
|
||||
#undef OP
|
||||
|
||||
hipFree(Ad);
|
||||
hipFree(Bd);
|
||||
hipFree(Cd);
|
||||
delete[] A;
|
||||
delete[] B;
|
||||
delete[] C;
|
||||
delete[] D;
|
||||
}
|
||||
|
||||
int main() {
|
||||
test<float>();
|
||||
test<double>();
|
||||
passed();
|
||||
return 0;
|
||||
}
|
||||
@@ -1,329 +0,0 @@
|
||||
/*
|
||||
Copyright (c) 2020 - 2021 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:
|
||||
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 WARRANNTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNNESS 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 INN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR INN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
/**
|
||||
Testcase Scenarios :
|
||||
|
||||
(TestCase 1)::
|
||||
1) Execute atomicAdd in multi threaded scenario by diverging the data across
|
||||
multiple threads and validate the output at the end of all operations.
|
||||
2) Execute atomicAddNoRet in multi threaded scenario by diverging the data
|
||||
across multiple threads and validate the output at the end of all operations.
|
||||
|
||||
(TestCase 2)::
|
||||
3) Execute atomicAdd API and validate the result.
|
||||
4) Execute atomicAddNoRet API and validate the result.
|
||||
|
||||
(TestCase 3)::
|
||||
5) atomicadd/NoRet negative scenarios (TBD).
|
||||
|
||||
*/
|
||||
|
||||
|
||||
/* HIT_START
|
||||
* BUILD: %t %s ../test_common.cpp NVCC_OPTIONS --gpu-architecture=compute_60
|
||||
* TEST_NAMED: %t hipTestAtomicnoret-manywaves --atomicnoret --tests 1
|
||||
* TEST_NAMED: %t hipTestAtomicnoret-simple --atomicnoret --tests 2
|
||||
* TEST_NAMED: %t hipTestAtomic-manywaves --tests 1
|
||||
* TEST_NAMED: %t hipTestAtomic-simple --tests 2
|
||||
* HIT_END
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include "test_common.h"
|
||||
|
||||
/*
|
||||
* Defines initial and increment values
|
||||
*/
|
||||
#define INCREMENT_VALUE 10
|
||||
|
||||
#define INT_INITIAL_VALUE 10
|
||||
#define FLOAT_INITIAL_VALUE 10.50
|
||||
#define DOUBLE_INITIAL_VALUE 200.12
|
||||
#define LONG_INITIAL_VALUE 10000
|
||||
#define UNSIGNED_INITIAL_VALUE 20
|
||||
|
||||
#ifdef __HIP_PLATFORM_NVIDIA__
|
||||
// atomicAddNoRet is unavailable in cuda
|
||||
template <typename T>
|
||||
__device__ void atomicAddNoRet(T* x, int y) {
|
||||
atomicAdd(x, static_cast<T>(y));
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
* Square each element in the array A and write to array C.
|
||||
*/
|
||||
bool p_atomicNoRet = false;
|
||||
|
||||
template <typename T>
|
||||
__global__ void atomicnoret_manywaves(T* C_d) {
|
||||
size_t tid = (blockIdx.x * blockDim.x + threadIdx.x);
|
||||
switch (tid % 9) {
|
||||
case 0:
|
||||
atomicAddNoRet(C_d, INCREMENT_VALUE);
|
||||
break;
|
||||
case 1:
|
||||
atomicAddNoRet(C_d, INCREMENT_VALUE);
|
||||
break;
|
||||
case 2:
|
||||
atomicAddNoRet(C_d, INCREMENT_VALUE);
|
||||
break;
|
||||
case 3:
|
||||
atomicAddNoRet(C_d, INCREMENT_VALUE);
|
||||
break;
|
||||
case 4:
|
||||
atomicAddNoRet(C_d, INCREMENT_VALUE);
|
||||
break;
|
||||
case 5:
|
||||
atomicAddNoRet(C_d, INCREMENT_VALUE);
|
||||
break;
|
||||
case 6:
|
||||
atomicAddNoRet(C_d, INCREMENT_VALUE);
|
||||
break;
|
||||
case 7:
|
||||
atomicAddNoRet(C_d, INCREMENT_VALUE);
|
||||
break;
|
||||
case 8:
|
||||
atomicAddNoRet(C_d, INCREMENT_VALUE);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
template <typename T>
|
||||
__global__ void atomic_manywaves(T* C_d) {
|
||||
size_t tid = (hipBlockIdx_x * hipBlockDim_x + hipThreadIdx_x);
|
||||
|
||||
switch (tid % 9) {
|
||||
case 0:
|
||||
atomicAdd(C_d, INCREMENT_VALUE);
|
||||
break;
|
||||
case 1:
|
||||
atomicAdd(C_d, INCREMENT_VALUE);
|
||||
break;
|
||||
case 2:
|
||||
atomicAdd(C_d, INCREMENT_VALUE);
|
||||
break;
|
||||
case 3:
|
||||
atomicAdd(C_d, INCREMENT_VALUE);
|
||||
break;
|
||||
case 4:
|
||||
atomicAdd(C_d, INCREMENT_VALUE);
|
||||
break;
|
||||
case 5:
|
||||
atomicAdd(C_d, INCREMENT_VALUE);
|
||||
break;
|
||||
case 6:
|
||||
atomicAdd(C_d, INCREMENT_VALUE);
|
||||
break;
|
||||
case 7:
|
||||
atomicAdd(C_d, INCREMENT_VALUE);
|
||||
break;
|
||||
case 8:
|
||||
atomicAdd(C_d, INCREMENT_VALUE);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template <typename T>
|
||||
__global__ void atomicnoret_simple(T* C_d) {
|
||||
atomicAddNoRet(C_d, INCREMENT_VALUE);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
__global__ void atomic_simple(T* C_d) {
|
||||
atomicAdd(C_d, INCREMENT_VALUE);
|
||||
}
|
||||
|
||||
|
||||
template <typename T>
|
||||
bool atomictest_manywaves(const T& initial_val) {
|
||||
unsigned int ThreadsperBlock = 10;
|
||||
unsigned int numBlocks = 1;
|
||||
bool testPassed = true;
|
||||
T memSize = sizeof(T);
|
||||
T* hOData = reinterpret_cast<T*>(malloc(memSize));
|
||||
*hOData = initial_val;
|
||||
T* dOData;
|
||||
HIPCHECK(hipMalloc(&dOData, memSize));
|
||||
// copy host memory to device to initialize to zero
|
||||
HIPCHECK(hipMemcpy(dOData, hOData, memSize, hipMemcpyHostToDevice));
|
||||
|
||||
// execute the kernel
|
||||
hipLaunchKernelGGL(atomic_manywaves, dim3(numBlocks),
|
||||
dim3(ThreadsperBlock), 0, 0, dOData);
|
||||
|
||||
// Copy result from device to host
|
||||
HIPCHECK(hipMemcpy(hOData, dOData, memSize, hipMemcpyDeviceToHost));
|
||||
if (hOData[0] != initial_val+(INCREMENT_VALUE*(ThreadsperBlock*numBlocks)))
|
||||
testPassed = false;
|
||||
|
||||
// Cleanup memory
|
||||
free(hOData);
|
||||
hipFree(dOData);
|
||||
|
||||
return testPassed;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
bool atomictestnoret_manywaves(const T& initial_val) {
|
||||
unsigned int ThreadsperBlock = 10;
|
||||
unsigned int numBlocks = 1;
|
||||
bool testPassed = true;
|
||||
T memSize = sizeof(T);
|
||||
T* hOData = reinterpret_cast<T*>(malloc(memSize));
|
||||
*hOData = initial_val;
|
||||
T* dOData;
|
||||
HIPCHECK(hipMalloc(&dOData, memSize));
|
||||
// copy host memory to device to initialize to zero
|
||||
HIPCHECK(hipMemcpy(dOData, hOData, memSize, hipMemcpyHostToDevice));
|
||||
|
||||
// execute the kernel
|
||||
hipLaunchKernelGGL(atomicnoret_manywaves, dim3(numBlocks),
|
||||
dim3(ThreadsperBlock), 0, 0, dOData);
|
||||
|
||||
// Copy result from device to host
|
||||
HIPCHECK(hipMemcpy(hOData, dOData, memSize, hipMemcpyDeviceToHost));
|
||||
if (hOData[0] != initial_val+(INCREMENT_VALUE*(ThreadsperBlock*numBlocks)))
|
||||
testPassed = false;
|
||||
|
||||
// Cleanup memory
|
||||
free(hOData);
|
||||
hipFree(dOData);
|
||||
|
||||
return testPassed;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
bool atomictest_simple(const T& initial_val) {
|
||||
unsigned int ThreadsperBlock = 1;
|
||||
unsigned int numBlocks = 1;
|
||||
bool testPassed = true;
|
||||
T memSize = sizeof(T);
|
||||
T* hOData = reinterpret_cast<T*>(malloc(memSize));
|
||||
*hOData = initial_val;
|
||||
T* dOData;
|
||||
HIPCHECK(hipMalloc(&dOData, memSize));
|
||||
// copy host memory to device to initialize to zero
|
||||
HIPCHECK(hipMemcpy(dOData, hOData, memSize, hipMemcpyHostToDevice));
|
||||
|
||||
// execute the kernel
|
||||
hipLaunchKernelGGL(atomic_simple, dim3(numBlocks),
|
||||
dim3(ThreadsperBlock), 0, 0, dOData);
|
||||
|
||||
// Copy result from device to host
|
||||
HIPCHECK(hipMemcpy(hOData, dOData, memSize, hipMemcpyDeviceToHost));
|
||||
if (hOData[0] != initial_val+INCREMENT_VALUE)
|
||||
testPassed = false;
|
||||
|
||||
// Cleanup memory
|
||||
free(hOData);
|
||||
hipFree(dOData);
|
||||
|
||||
return testPassed;
|
||||
}
|
||||
|
||||
|
||||
template <typename T>
|
||||
bool atomictestnoret_simple(const T& initial_val) {
|
||||
unsigned int ThreadsperBlock = 1;
|
||||
unsigned int numBlocks = 1;
|
||||
bool testPassed = true;
|
||||
T memSize = sizeof(T);
|
||||
T* hOData = reinterpret_cast<T*>(malloc(memSize));
|
||||
*hOData = initial_val;
|
||||
T* dOData;
|
||||
HIPCHECK(hipMalloc(&dOData, memSize));
|
||||
// copy host memory to device to initialize to zero
|
||||
HIPCHECK(hipMemcpy(dOData, hOData, memSize, hipMemcpyHostToDevice));
|
||||
|
||||
// execute the kernel
|
||||
hipLaunchKernelGGL(atomicnoret_simple, dim3(numBlocks),
|
||||
dim3(ThreadsperBlock), 0, 0, dOData);
|
||||
|
||||
// Copy result from device to host
|
||||
HIPCHECK(hipMemcpy(hOData, dOData, memSize, hipMemcpyDeviceToHost));
|
||||
if (hOData[0] != initial_val+INCREMENT_VALUE)
|
||||
testPassed = false;
|
||||
|
||||
// Cleanup memory
|
||||
free(hOData);
|
||||
hipFree(dOData);
|
||||
|
||||
return testPassed;
|
||||
}
|
||||
|
||||
|
||||
// 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];
|
||||
if (!strcmp(arg, "--atomicnoret")) {
|
||||
p_atomicNoRet = true;
|
||||
} else {
|
||||
failed("Bad argument '%s'", arg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
parseMyArguments(argc, argv);
|
||||
HIPCHECK(hipSetDevice(p_gpuDevice));
|
||||
bool TestPassed = true;
|
||||
|
||||
if (p_tests == 1) {
|
||||
if (!p_atomicNoRet) {
|
||||
TestPassed &= atomictest_manywaves<int>(INT_INITIAL_VALUE);
|
||||
TestPassed &= atomictest_manywaves<unsigned int>(UNSIGNED_INITIAL_VALUE);
|
||||
TestPassed &= atomictest_manywaves<float>(FLOAT_INITIAL_VALUE);
|
||||
TestPassed &=
|
||||
atomictest_manywaves<unsigned long long>(LONG_INITIAL_VALUE);
|
||||
TestPassed &=
|
||||
atomictest_manywaves<double>(DOUBLE_INITIAL_VALUE);
|
||||
} else {
|
||||
atomictestnoret_manywaves<float>(FLOAT_INITIAL_VALUE);
|
||||
}
|
||||
} else if (p_tests == 2) {
|
||||
if (!p_atomicNoRet) {
|
||||
TestPassed &= atomictest_simple<int>(INT_INITIAL_VALUE);
|
||||
TestPassed &= atomictest_simple<unsigned int>(UNSIGNED_INITIAL_VALUE);
|
||||
TestPassed &= atomictest_simple<float>(FLOAT_INITIAL_VALUE);
|
||||
TestPassed &= atomictest_simple<unsigned long long>(LONG_INITIAL_VALUE);
|
||||
TestPassed &= atomictest_simple<double>(DOUBLE_INITIAL_VALUE);
|
||||
} else {
|
||||
TestPassed &= atomictestnoret_simple<float>(FLOAT_INITIAL_VALUE);
|
||||
}
|
||||
} else {
|
||||
printf("Didnt receive any valid option. Try options 1 or 2\n");
|
||||
TestPassed = false;
|
||||
}
|
||||
|
||||
if (TestPassed) {
|
||||
passed();
|
||||
} else {
|
||||
failed("hipTestAtomicAdd TC validation Failed!");
|
||||
}
|
||||
}
|
||||
@@ -1,86 +0,0 @@
|
||||
/*
|
||||
Copyright (c) 2015 - 2021 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:
|
||||
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.
|
||||
*/
|
||||
|
||||
/* HIT_START
|
||||
* BUILD: %t %s ../test_common.cpp
|
||||
* TEST: %t
|
||||
* HIT_END
|
||||
*/
|
||||
|
||||
#include <hip/hip_runtime.h>
|
||||
#include <hip/hip_runtime_api.h>
|
||||
#include <iostream>
|
||||
#include "test_common.h"
|
||||
|
||||
#define HIP_ASSERT(status) assert(status == hipSuccess)
|
||||
|
||||
#define LEN 512
|
||||
#define SIZE (LEN * sizeof(long long))
|
||||
|
||||
static __global__ void kernel1(long long* Ad) {
|
||||
int tid = threadIdx.x + blockIdx.x * blockDim.x;
|
||||
Ad[tid] = clock() + clock64() + __clock() + __clock64();
|
||||
}
|
||||
|
||||
static __global__ void kernel2(long long* Ad) {
|
||||
int tid = threadIdx.x + blockIdx.x * blockDim.x;
|
||||
Ad[tid] = clock() + clock64() + __clock() + __clock64() - Ad[tid];
|
||||
}
|
||||
|
||||
static __global__ void kernel1_gfx11(long long* Ad) {
|
||||
#ifdef __HIP_PLATFORM_AMD__
|
||||
int tid = threadIdx.x + blockIdx.x * blockDim.x;
|
||||
Ad[tid] = clock() + wall_clock64() + __clock() + __clock64();
|
||||
#endif
|
||||
}
|
||||
|
||||
static __global__ void kernel2_gfx11(long long* Ad) {
|
||||
#ifdef __HIP_PLATFORM_AMD__
|
||||
int tid = threadIdx.x + blockIdx.x * blockDim.x;
|
||||
Ad[tid] = clock() + wall_clock64() + __clock() + __clock64() - Ad[tid];
|
||||
#endif
|
||||
}
|
||||
|
||||
void run() {
|
||||
long long *A, *Ad;
|
||||
A = new long long[LEN];
|
||||
for (unsigned i = 0; i < LEN; i++) {
|
||||
A[i] = 0;
|
||||
}
|
||||
|
||||
auto kernel1_used = IsGfx11() ? kernel1_gfx11 : kernel1;
|
||||
auto kernel2_used = IsGfx11() ? kernel2_gfx11 : kernel2;
|
||||
|
||||
HIP_ASSERT(hipMalloc((void**)&Ad, SIZE));
|
||||
|
||||
hipLaunchKernelGGL(kernel1_used, dim3(1, 1, 1),
|
||||
dim3(LEN, 1, 1), 0, 0, Ad);
|
||||
hipLaunchKernelGGL(kernel2_used, dim3(1, 1, 1),
|
||||
dim3(LEN, 1, 1), 0, 0, Ad);
|
||||
HIP_ASSERT(hipMemcpy(A, Ad, SIZE, hipMemcpyDeviceToHost));
|
||||
|
||||
for (unsigned i = 0; i < LEN; i++) {
|
||||
assert(0 != A[i]);
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
run();
|
||||
passed();
|
||||
}
|
||||
@@ -1,742 +0,0 @@
|
||||
/*
|
||||
Copyright (c) 2015 - 2021 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:
|
||||
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.
|
||||
*/
|
||||
|
||||
/* HIT_START
|
||||
* BUILD: %t %s ../test_common.cpp
|
||||
* TEST: %t
|
||||
* HIT_END
|
||||
*/
|
||||
|
||||
#include "test_common.h"
|
||||
#include <hip/hip_runtime.h>
|
||||
#include <hip/math_functions.h>
|
||||
#include <hip/hip_runtime_api.h>
|
||||
|
||||
#define N 512
|
||||
#define SIZE N * sizeof(float)
|
||||
|
||||
__global__ void test_sincosf(float* a, float* b, float* c) {
|
||||
int tid = threadIdx.x;
|
||||
sincosf(a[tid], b + tid, c + tid);
|
||||
}
|
||||
|
||||
__global__ void test_sincospif(float* a, float* b, float* c) {
|
||||
int tid = threadIdx.x;
|
||||
sincospif(a[tid], b + tid, c + tid);
|
||||
}
|
||||
|
||||
__global__ void test_fdividef(float* a, float* b, float* c) {
|
||||
int tid = threadIdx.x;
|
||||
c[tid] = fdividef(a[tid], b[tid]);
|
||||
}
|
||||
|
||||
__global__ void test_llrintf(float* a, long long int* b) {
|
||||
int tid = threadIdx.x;
|
||||
b[tid] = llrintf(a[tid]);
|
||||
}
|
||||
|
||||
__global__ void test_lrintf(float* a, long int* b) {
|
||||
int tid = threadIdx.x;
|
||||
b[tid] = lrintf(a[tid]);
|
||||
}
|
||||
|
||||
__global__ void test_rintf(float* a, float* b) {
|
||||
int tid = threadIdx.x;
|
||||
b[tid] = rintf(a[tid]);
|
||||
}
|
||||
|
||||
__global__ void test_llroundf(float* a, long long int* b) {
|
||||
int tid = threadIdx.x;
|
||||
b[tid] = llroundf(a[tid]);
|
||||
}
|
||||
|
||||
__global__ void test_lroundf(float* a, long int* b) {
|
||||
int tid = threadIdx.x;
|
||||
b[tid] = lroundf(a[tid]);
|
||||
}
|
||||
|
||||
__global__ void test_rhypotf(float* a, float* b, float* c) {
|
||||
int tid = threadIdx.x;
|
||||
c[tid] = rhypotf(a[tid], b[tid]);
|
||||
}
|
||||
|
||||
__global__ void test_norm3df(float* a, float* b, float* c, float* d) {
|
||||
int tid = threadIdx.x;
|
||||
d[tid] = norm3df(a[tid], b[tid], c[tid]);
|
||||
}
|
||||
|
||||
__global__ void test_norm4df(float* a, float* b, float* c, float* d, float* e) {
|
||||
int tid = threadIdx.x;
|
||||
e[tid] = norm4df(a[tid], b[tid], c[tid], d[tid]);
|
||||
}
|
||||
|
||||
__global__ void test_normf(float* a, float* b) {
|
||||
int tid = threadIdx.x;
|
||||
b[tid] = normf(N, a);
|
||||
}
|
||||
|
||||
__global__ void test_rnorm3df(float* a, float* b, float* c, float* d) {
|
||||
int tid = threadIdx.x;
|
||||
d[tid] = rnorm3df(a[tid], b[tid], c[tid]);
|
||||
}
|
||||
|
||||
__global__ void test_rnorm4df(float* a, float* b, float* c, float* d, float* e) {
|
||||
int tid = threadIdx.x;
|
||||
e[tid] = rnorm4df(a[tid], b[tid], c[tid], d[tid]);
|
||||
}
|
||||
|
||||
__global__ void test_rnormf(float* a, float* b) {
|
||||
int tid = threadIdx.x;
|
||||
b[tid] = rnormf(N, a);
|
||||
}
|
||||
|
||||
__global__ void test_erfinvf(float* a, float* b) {
|
||||
int tid = threadIdx.x;
|
||||
b[tid] = erff(erfinvf(a[tid]));
|
||||
}
|
||||
|
||||
|
||||
bool run_sincosf() {
|
||||
float *A, *Ad, *B, *C, *Bd, *Cd;
|
||||
A = new float[N];
|
||||
B = new float[N];
|
||||
C = new float[N];
|
||||
for (int i = 0; i < N; i++) {
|
||||
A[i] = 1.0f;
|
||||
}
|
||||
hipMalloc((void**)&Ad, SIZE);
|
||||
hipMalloc((void**)&Bd, SIZE);
|
||||
hipMalloc((void**)&Cd, SIZE);
|
||||
hipMemcpy(Ad, A, SIZE, hipMemcpyHostToDevice);
|
||||
hipLaunchKernelGGL(test_sincosf, dim3(1), dim3(N), 0, 0, Ad, Bd, Cd);
|
||||
hipMemcpy(B, Bd, SIZE, hipMemcpyDeviceToHost);
|
||||
hipMemcpy(C, Cd, SIZE, hipMemcpyDeviceToHost);
|
||||
int passed = 0;
|
||||
for (int i = 0; i < 512; i++) {
|
||||
if (B[i] == sinf(1.0f)) {
|
||||
passed = 1;
|
||||
}
|
||||
}
|
||||
passed = 0;
|
||||
for (int i = 0; i < 512; i++) {
|
||||
if (C[i] == cosf(1.0f)) {
|
||||
passed = 1;
|
||||
}
|
||||
}
|
||||
|
||||
delete[] A;
|
||||
delete[] B;
|
||||
delete[] C;
|
||||
hipFree(Ad);
|
||||
hipFree(Bd);
|
||||
hipFree(Cd);
|
||||
|
||||
if (passed == 1) {
|
||||
return true;
|
||||
}
|
||||
assert(passed == 1);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool run_sincospif() {
|
||||
float *A, *Ad, *B, *C, *Bd, *Cd;
|
||||
A = new float[N];
|
||||
B = new float[N];
|
||||
C = new float[N];
|
||||
for (int i = 0; i < N; i++) {
|
||||
A[i] = 1.0f;
|
||||
}
|
||||
hipMalloc((void**)&Ad, SIZE);
|
||||
hipMalloc((void**)&Bd, SIZE);
|
||||
hipMalloc((void**)&Cd, SIZE);
|
||||
hipMemcpy(Ad, A, SIZE, hipMemcpyHostToDevice);
|
||||
hipLaunchKernelGGL(test_sincospif, dim3(1), dim3(N), 0, 0, Ad, Bd, Cd);
|
||||
hipMemcpy(B, Bd, SIZE, hipMemcpyDeviceToHost);
|
||||
hipMemcpy(C, Cd, SIZE, hipMemcpyDeviceToHost);
|
||||
int passed = 0;
|
||||
for (int i = 0; i < 512; i++) {
|
||||
if (B[i] - sinf(3.14 * 1.0f) < 0.1) {
|
||||
passed = 1;
|
||||
}
|
||||
}
|
||||
passed = 0;
|
||||
for (int i = 0; i < 512; i++) {
|
||||
if (C[i] - cosf(3.14 * 1.0f) < 0.1) {
|
||||
passed = 1;
|
||||
}
|
||||
}
|
||||
|
||||
delete[] A;
|
||||
delete[] B;
|
||||
delete[] C;
|
||||
hipFree(Ad);
|
||||
hipFree(Bd);
|
||||
hipFree(Cd);
|
||||
|
||||
if (passed == 1) {
|
||||
return true;
|
||||
}
|
||||
assert(passed == 1);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool run_fdividef() {
|
||||
float *A, *Ad, *B, *C, *Bd, *Cd;
|
||||
A = new float[N];
|
||||
B = new float[N];
|
||||
C = new float[N];
|
||||
for (int i = 0; i < N; i++) {
|
||||
A[i] = 1.0f;
|
||||
B[i] = 2.0f;
|
||||
}
|
||||
hipMalloc((void**)&Ad, SIZE);
|
||||
hipMalloc((void**)&Bd, SIZE);
|
||||
hipMalloc((void**)&Cd, SIZE);
|
||||
hipMemcpy(Ad, A, SIZE, hipMemcpyHostToDevice);
|
||||
hipMemcpy(Bd, B, SIZE, hipMemcpyHostToDevice);
|
||||
hipLaunchKernelGGL(test_fdividef, dim3(1), dim3(N), 0, 0, Ad, Bd, Cd);
|
||||
hipMemcpy(C, Cd, SIZE, hipMemcpyDeviceToHost);
|
||||
int passed = 0;
|
||||
for (int i = 0; i < 512; i++) {
|
||||
if (C[i] == A[i] / B[i]) {
|
||||
passed = 1;
|
||||
}
|
||||
}
|
||||
|
||||
delete[] A;
|
||||
delete[] B;
|
||||
delete[] C;
|
||||
hipFree(Ad);
|
||||
hipFree(Bd);
|
||||
hipFree(Cd);
|
||||
|
||||
if (passed == 1) {
|
||||
return true;
|
||||
}
|
||||
assert(passed == 1);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool run_llrintf() {
|
||||
float *A, *Ad;
|
||||
long long int *B, *Bd;
|
||||
A = new float[N];
|
||||
B = new long long int[N];
|
||||
for (int i = 0; i < N; i++) {
|
||||
A[i] = 1.345f;
|
||||
}
|
||||
hipMalloc((void**)&Ad, SIZE);
|
||||
hipMalloc((void**)&Bd, N * sizeof(long long int));
|
||||
hipMemcpy(Ad, A, SIZE, hipMemcpyHostToDevice);
|
||||
hipLaunchKernelGGL(test_llrintf, dim3(1), dim3(N), 0, 0, Ad, Bd);
|
||||
hipMemcpy(B, Bd, N * sizeof(long long int), hipMemcpyDeviceToHost);
|
||||
int passed = 0;
|
||||
for (int i = 0; i < 512; i++) {
|
||||
int x = roundf(A[i]);
|
||||
if (B[i] == x) {
|
||||
passed = 1;
|
||||
}
|
||||
}
|
||||
|
||||
delete[] A;
|
||||
delete[] B;
|
||||
hipFree(Ad);
|
||||
hipFree(Bd);
|
||||
|
||||
if (passed == 1) {
|
||||
return true;
|
||||
}
|
||||
assert(passed == 1);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool run_lrintf() {
|
||||
float *A, *Ad;
|
||||
long int *B, *Bd;
|
||||
A = new float[N];
|
||||
B = new long int[N];
|
||||
for (int i = 0; i < N; i++) {
|
||||
A[i] = 1.345f;
|
||||
}
|
||||
hipMalloc((void**)&Ad, SIZE);
|
||||
hipMalloc((void**)&Bd, N * sizeof(long int));
|
||||
hipMemcpy(Ad, A, SIZE, hipMemcpyHostToDevice);
|
||||
hipLaunchKernelGGL(test_lrintf, dim3(1), dim3(N), 0, 0, Ad, Bd);
|
||||
hipMemcpy(B, Bd, N * sizeof(long int), hipMemcpyDeviceToHost);
|
||||
int passed = 0;
|
||||
for (int i = 0; i < 512; i++) {
|
||||
int x = roundf(A[i]);
|
||||
if (B[i] == x) {
|
||||
passed = 1;
|
||||
}
|
||||
}
|
||||
|
||||
delete[] A;
|
||||
delete[] B;
|
||||
hipFree(Ad);
|
||||
hipFree(Bd);
|
||||
|
||||
if (passed == 1) {
|
||||
return true;
|
||||
}
|
||||
assert(passed == 1);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool run_rintf() {
|
||||
float *A, *Ad;
|
||||
float *B, *Bd;
|
||||
A = new float[N];
|
||||
B = new float[N];
|
||||
for (int i = 0; i < N; i++) {
|
||||
A[i] = 1.345f;
|
||||
}
|
||||
hipMalloc((void**)&Ad, SIZE);
|
||||
hipMalloc((void**)&Bd, SIZE);
|
||||
hipMemcpy(Ad, A, SIZE, hipMemcpyHostToDevice);
|
||||
hipLaunchKernelGGL(test_rintf, dim3(1), dim3(N), 0, 0, Ad, Bd);
|
||||
hipMemcpy(B, Bd, SIZE, hipMemcpyDeviceToHost);
|
||||
int passed = 0;
|
||||
for (int i = 0; i < 512; i++) {
|
||||
float x = roundf(A[i]);
|
||||
if (B[i] == x) {
|
||||
passed = 1;
|
||||
}
|
||||
}
|
||||
|
||||
delete[] A;
|
||||
delete[] B;
|
||||
hipFree(Ad);
|
||||
hipFree(Bd);
|
||||
|
||||
if (passed == 1) {
|
||||
return true;
|
||||
}
|
||||
assert(passed == 1);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool run_llroundf() {
|
||||
float *A, *Ad;
|
||||
long long int *B, *Bd;
|
||||
A = new float[N];
|
||||
B = new long long int[N];
|
||||
for (int i = 0; i < N; i++) {
|
||||
A[i] = 1.345f;
|
||||
}
|
||||
hipMalloc((void**)&Ad, SIZE);
|
||||
hipMalloc((void**)&Bd, N * sizeof(long long int));
|
||||
hipMemcpy(Ad, A, SIZE, hipMemcpyHostToDevice);
|
||||
hipLaunchKernelGGL(test_llroundf, dim3(1), dim3(N), 0, 0, Ad, Bd);
|
||||
hipMemcpy(B, Bd, N * sizeof(long long int), hipMemcpyDeviceToHost);
|
||||
int passed = 0;
|
||||
for (int i = 0; i < 512; i++) {
|
||||
int x = roundf(A[i]);
|
||||
if (B[i] == x) {
|
||||
passed = 1;
|
||||
}
|
||||
}
|
||||
|
||||
delete[] A;
|
||||
delete[] B;
|
||||
hipFree(Ad);
|
||||
hipFree(Bd);
|
||||
|
||||
if (passed == 1) {
|
||||
return true;
|
||||
}
|
||||
assert(passed == 1);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool run_lroundf() {
|
||||
float *A, *Ad;
|
||||
long int *B, *Bd;
|
||||
A = new float[N];
|
||||
B = new long int[N];
|
||||
for (int i = 0; i < N; i++) {
|
||||
A[i] = 1.345f;
|
||||
}
|
||||
hipMalloc((void**)&Ad, SIZE);
|
||||
hipMalloc((void**)&Bd, N * sizeof(long int));
|
||||
hipMemcpy(Ad, A, SIZE, hipMemcpyHostToDevice);
|
||||
hipLaunchKernelGGL(test_lroundf, dim3(1), dim3(N), 0, 0, Ad, Bd);
|
||||
hipMemcpy(B, Bd, N * sizeof(long int), hipMemcpyDeviceToHost);
|
||||
int passed = 0;
|
||||
for (int i = 0; i < 512; i++) {
|
||||
int x = roundf(A[i]);
|
||||
if (B[i] == x) {
|
||||
passed = 1;
|
||||
}
|
||||
}
|
||||
|
||||
delete[] A;
|
||||
delete[] B;
|
||||
hipFree(Ad);
|
||||
hipFree(Bd);
|
||||
|
||||
if (passed == 1) {
|
||||
return true;
|
||||
}
|
||||
assert(passed == 1);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool run_norm3df() {
|
||||
float *A, *Ad, *B, *Bd, *C, *Cd, *D, *Dd;
|
||||
A = new float[N];
|
||||
B = new float[N];
|
||||
C = new float[N];
|
||||
D = new float[N];
|
||||
float val = 0.0f;
|
||||
for (int i = 0; i < N; i++) {
|
||||
A[i] = 1.0f;
|
||||
B[i] = 2.0f;
|
||||
C[i] = 3.0f;
|
||||
}
|
||||
val = sqrtf(1.0f + 4.0f + 9.0f);
|
||||
hipMalloc((void**)&Ad, SIZE);
|
||||
hipMalloc((void**)&Bd, SIZE);
|
||||
hipMalloc((void**)&Cd, SIZE);
|
||||
hipMalloc((void**)&Dd, SIZE);
|
||||
hipMemcpy(Ad, A, SIZE, hipMemcpyHostToDevice);
|
||||
hipMemcpy(Bd, B, SIZE, hipMemcpyHostToDevice);
|
||||
hipMemcpy(Cd, C, SIZE, hipMemcpyHostToDevice);
|
||||
hipLaunchKernelGGL(test_norm3df, dim3(1), dim3(N), 0, 0, Ad, Bd, Cd, Dd);
|
||||
hipMemcpy(D, Dd, SIZE, hipMemcpyDeviceToHost);
|
||||
int passed = 0;
|
||||
for (int i = 0; i < 512; i++) {
|
||||
if (D[i] - val < 0.000001) {
|
||||
passed = 1;
|
||||
}
|
||||
}
|
||||
|
||||
delete[] A;
|
||||
delete[] B;
|
||||
delete[] C;
|
||||
delete[] D;
|
||||
hipFree(Ad);
|
||||
hipFree(Bd);
|
||||
hipFree(Cd);
|
||||
hipFree(Dd);
|
||||
|
||||
if (passed == 1) {
|
||||
return true;
|
||||
}
|
||||
assert(passed == 1);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool run_norm4df() {
|
||||
float *A, *Ad, *B, *Bd, *C, *Cd, *D, *Dd, *E, *Ed;
|
||||
A = new float[N];
|
||||
B = new float[N];
|
||||
C = new float[N];
|
||||
D = new float[N];
|
||||
E = new float[N];
|
||||
float val = 0.0f;
|
||||
for (int i = 0; i < N; i++) {
|
||||
A[i] = 1.0f;
|
||||
B[i] = 2.0f;
|
||||
C[i] = 3.0f;
|
||||
D[i] = 4.0f;
|
||||
}
|
||||
val = sqrtf(1.0f + 4.0f + 9.0f + 16.0f);
|
||||
hipMalloc((void**)&Ad, SIZE);
|
||||
hipMalloc((void**)&Bd, SIZE);
|
||||
hipMalloc((void**)&Cd, SIZE);
|
||||
hipMalloc((void**)&Dd, SIZE);
|
||||
hipMalloc((void**)&Ed, SIZE);
|
||||
hipMemcpy(Ad, A, SIZE, hipMemcpyHostToDevice);
|
||||
hipMemcpy(Bd, B, SIZE, hipMemcpyHostToDevice);
|
||||
hipMemcpy(Cd, C, SIZE, hipMemcpyHostToDevice);
|
||||
hipMemcpy(Dd, D, SIZE, hipMemcpyHostToDevice);
|
||||
hipLaunchKernelGGL(test_norm4df, dim3(1), dim3(N), 0, 0, Ad, Bd, Cd, Dd, Ed);
|
||||
hipMemcpy(E, Ed, SIZE, hipMemcpyDeviceToHost);
|
||||
int passed = 0;
|
||||
for (int i = 0; i < 512; i++) {
|
||||
if (E[i] - val < 0.000001) {
|
||||
passed = 1;
|
||||
}
|
||||
}
|
||||
|
||||
delete[] A;
|
||||
delete[] B;
|
||||
delete[] C;
|
||||
delete[] D;
|
||||
delete[] E;
|
||||
hipFree(Ad);
|
||||
hipFree(Bd);
|
||||
hipFree(Cd);
|
||||
hipFree(Dd);
|
||||
hipFree(Ed);
|
||||
|
||||
if (passed == 1) {
|
||||
return true;
|
||||
}
|
||||
assert(passed == 1);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool run_normf() {
|
||||
float *A, *Ad, *B, *Bd;
|
||||
A = new float[N];
|
||||
B = new float[N];
|
||||
float val = 0.0f;
|
||||
for (int i = 0; i < N; i++) {
|
||||
A[i] = 1.0f;
|
||||
B[i] = 0.0f;
|
||||
val += 1.0f;
|
||||
}
|
||||
val = sqrtf(val);
|
||||
hipMalloc((void**)&Ad, SIZE);
|
||||
hipMalloc((void**)&Bd, SIZE);
|
||||
hipMemcpy(Ad, A, SIZE, hipMemcpyHostToDevice);
|
||||
hipLaunchKernelGGL(test_normf, dim3(1), dim3(N), 0, 0, Ad, Bd);
|
||||
hipMemcpy(B, Bd, SIZE, hipMemcpyDeviceToHost);
|
||||
int passed = 0;
|
||||
for (int i = 0; i < 512; i++) {
|
||||
if (B[0] - val < 0.000001) {
|
||||
passed = 1;
|
||||
}
|
||||
}
|
||||
|
||||
delete[] A;
|
||||
delete[] B;
|
||||
hipFree(Ad);
|
||||
hipFree(Bd);
|
||||
|
||||
if (passed == 1) {
|
||||
return true;
|
||||
}
|
||||
assert(passed == 1);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool run_rhypotf() {
|
||||
float *A, *Ad, *B, *Bd, *C, *Cd;
|
||||
A = new float[N];
|
||||
B = new float[N];
|
||||
C = new float[N];
|
||||
float val = 0.0f;
|
||||
for (int i = 0; i < N; i++) {
|
||||
A[i] = 1.0f;
|
||||
B[i] = 2.0f;
|
||||
}
|
||||
val = 1 / sqrtf(1.0f + 4.0f);
|
||||
hipMalloc((void**)&Ad, SIZE);
|
||||
hipMalloc((void**)&Bd, SIZE);
|
||||
hipMalloc((void**)&Cd, SIZE);
|
||||
hipMemcpy(Ad, A, SIZE, hipMemcpyHostToDevice);
|
||||
hipMemcpy(Bd, B, SIZE, hipMemcpyHostToDevice);
|
||||
hipLaunchKernelGGL(test_rhypotf, dim3(1), dim3(N), 0, 0, Ad, Bd, Cd);
|
||||
hipMemcpy(C, Cd, SIZE, hipMemcpyDeviceToHost);
|
||||
int passed = 0;
|
||||
for (int i = 0; i < 512; i++) {
|
||||
if (C[i] - val < 0.000001) {
|
||||
passed = 1;
|
||||
}
|
||||
}
|
||||
|
||||
delete[] A;
|
||||
delete[] B;
|
||||
delete[] C;
|
||||
hipFree(Ad);
|
||||
hipFree(Bd);
|
||||
hipFree(Cd);
|
||||
|
||||
if (passed == 1) {
|
||||
return true;
|
||||
}
|
||||
assert(passed == 1);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool run_rnorm3df() {
|
||||
float *A, *Ad, *B, *Bd, *C, *Cd, *D, *Dd;
|
||||
A = new float[N];
|
||||
B = new float[N];
|
||||
C = new float[N];
|
||||
D = new float[N];
|
||||
float val = 0.0f;
|
||||
for (int i = 0; i < N; i++) {
|
||||
A[i] = 1.0f;
|
||||
B[i] = 2.0f;
|
||||
C[i] = 3.0f;
|
||||
}
|
||||
val = 1 / sqrtf(1.0f + 4.0f + 9.0f);
|
||||
hipMalloc((void**)&Ad, SIZE);
|
||||
hipMalloc((void**)&Bd, SIZE);
|
||||
hipMalloc((void**)&Cd, SIZE);
|
||||
hipMalloc((void**)&Dd, SIZE);
|
||||
hipMemcpy(Ad, A, SIZE, hipMemcpyHostToDevice);
|
||||
hipMemcpy(Bd, B, SIZE, hipMemcpyHostToDevice);
|
||||
hipMemcpy(Cd, C, SIZE, hipMemcpyHostToDevice);
|
||||
hipLaunchKernelGGL(test_rnorm3df, dim3(1), dim3(N), 0, 0, Ad, Bd, Cd, Dd);
|
||||
hipMemcpy(D, Dd, SIZE, hipMemcpyDeviceToHost);
|
||||
int passed = 0;
|
||||
for (int i = 0; i < 512; i++) {
|
||||
if (D[i] - val < 0.000001) {
|
||||
passed = 1;
|
||||
}
|
||||
}
|
||||
|
||||
delete[] A;
|
||||
delete[] B;
|
||||
delete[] C;
|
||||
delete[] D;
|
||||
hipFree(Ad);
|
||||
hipFree(Bd);
|
||||
hipFree(Cd);
|
||||
hipFree(Dd);
|
||||
|
||||
if (passed == 1) {
|
||||
return true;
|
||||
}
|
||||
assert(passed == 1);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool run_rnorm4df() {
|
||||
float *A, *Ad, *B, *Bd, *C, *Cd, *D, *Dd, *E, *Ed;
|
||||
A = new float[N];
|
||||
B = new float[N];
|
||||
C = new float[N];
|
||||
D = new float[N];
|
||||
E = new float[N];
|
||||
float val = 0.0f;
|
||||
for (int i = 0; i < N; i++) {
|
||||
A[i] = 1.0f;
|
||||
B[i] = 2.0f;
|
||||
C[i] = 3.0f;
|
||||
D[i] = 4.0f;
|
||||
}
|
||||
val = 1 / sqrtf(1.0f + 4.0f + 9.0f + 16.0f);
|
||||
hipMalloc((void**)&Ad, SIZE);
|
||||
hipMalloc((void**)&Bd, SIZE);
|
||||
hipMalloc((void**)&Cd, SIZE);
|
||||
hipMalloc((void**)&Dd, SIZE);
|
||||
hipMalloc((void**)&Ed, SIZE);
|
||||
hipMemcpy(Ad, A, SIZE, hipMemcpyHostToDevice);
|
||||
hipMemcpy(Bd, B, SIZE, hipMemcpyHostToDevice);
|
||||
hipMemcpy(Cd, C, SIZE, hipMemcpyHostToDevice);
|
||||
hipMemcpy(Dd, D, SIZE, hipMemcpyHostToDevice);
|
||||
hipLaunchKernelGGL(test_rnorm4df, dim3(1), dim3(N), 0, 0, Ad, Bd, Cd, Dd, Ed);
|
||||
hipMemcpy(E, Ed, SIZE, hipMemcpyDeviceToHost);
|
||||
int passed = 0;
|
||||
for (int i = 0; i < 512; i++) {
|
||||
if (E[i] - val < 0.000001) {
|
||||
passed = 1;
|
||||
}
|
||||
}
|
||||
|
||||
delete[] A;
|
||||
delete[] B;
|
||||
delete[] C;
|
||||
delete[] D;
|
||||
delete[] E;
|
||||
hipFree(Ad);
|
||||
hipFree(Bd);
|
||||
hipFree(Cd);
|
||||
hipFree(Dd);
|
||||
hipFree(Ed);
|
||||
|
||||
if (passed == 1) {
|
||||
return true;
|
||||
}
|
||||
assert(passed == 1);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool run_rnormf() {
|
||||
float *A, *Ad, *B, *Bd;
|
||||
A = new float[N];
|
||||
B = new float[N];
|
||||
float val = 0.0f;
|
||||
for (int i = 0; i < N; i++) {
|
||||
A[i] = 1.0f;
|
||||
B[i] = 0.0f;
|
||||
val += 1.0f;
|
||||
}
|
||||
val = 1 / sqrtf(val);
|
||||
hipMalloc((void**)&Ad, SIZE);
|
||||
hipMalloc((void**)&Bd, SIZE);
|
||||
hipMemcpy(Ad, A, SIZE, hipMemcpyHostToDevice);
|
||||
hipLaunchKernelGGL(test_rnormf, dim3(1), dim3(N), 0, 0, Ad, Bd);
|
||||
hipMemcpy(B, Bd, SIZE, hipMemcpyDeviceToHost);
|
||||
int passed = 0;
|
||||
for (int i = 0; i < 512; i++) {
|
||||
if (B[0] - val < 0.000001) {
|
||||
passed = 1;
|
||||
}
|
||||
}
|
||||
|
||||
delete[] A;
|
||||
delete[] B;
|
||||
hipFree(Ad);
|
||||
hipFree(Bd);
|
||||
|
||||
if (passed == 1) {
|
||||
return true;
|
||||
}
|
||||
assert(passed == 1);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool run_erfinvf() {
|
||||
float *A, *Ad, *B, *Bd;
|
||||
A = new float[N];
|
||||
B = new float[N];
|
||||
for (int i = 0; i < N; i++) {
|
||||
A[i] = -0.6f;
|
||||
B[i] = 0.0f;
|
||||
}
|
||||
hipMalloc((void**)&Ad, SIZE);
|
||||
hipMalloc((void**)&Bd, SIZE);
|
||||
hipMemcpy(Ad, A, SIZE, hipMemcpyHostToDevice);
|
||||
hipLaunchKernelGGL(test_erfinvf, dim3(1), dim3(N), 0, 0, Ad, Bd);
|
||||
hipMemcpy(B, Bd, SIZE, hipMemcpyDeviceToHost);
|
||||
int passed = 0;
|
||||
for (int i = 0; i < 512; i++) {
|
||||
if (B[i] - A[i] < 0.000001) {
|
||||
passed = 1;
|
||||
}
|
||||
}
|
||||
|
||||
delete[] A;
|
||||
delete[] B;
|
||||
hipFree(Ad);
|
||||
hipFree(Bd);
|
||||
|
||||
if (passed == 1) {
|
||||
return true;
|
||||
}
|
||||
assert(passed == 1);
|
||||
return false;
|
||||
}
|
||||
|
||||
int main() {
|
||||
if (run_sincosf() && run_sincospif() && run_fdividef() && run_llrintf() && run_norm3df() &&
|
||||
run_norm4df() && run_normf() && run_rnorm3df() && run_rnorm4df() && run_rnormf() &&
|
||||
run_lroundf() && run_llroundf() && run_rintf() && run_rhypotf() && run_erfinvf()) {
|
||||
passed();
|
||||
}
|
||||
}
|
||||
@@ -1,664 +0,0 @@
|
||||
/*
|
||||
Copyright (c) 2015 - 2021 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:
|
||||
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.
|
||||
*/
|
||||
|
||||
/* HIT_START
|
||||
* XXBUILD: %t %s ../test_common.cpp
|
||||
* XXTEST: %t
|
||||
* HIT_END
|
||||
*/
|
||||
|
||||
#include "test_common.h"
|
||||
#include <hip/hip_runtime.h>
|
||||
#include <hip/hip_runtime_api.h>
|
||||
#include <hip/math_functions.h>
|
||||
|
||||
#define N 512
|
||||
#define SIZE N * sizeof(double)
|
||||
|
||||
__global__ void test_sincos(double* a, double* b, double* c) {
|
||||
int tid = threadIdx.x;
|
||||
sincos(a[tid], b + tid, c + tid);
|
||||
}
|
||||
|
||||
__global__ void test_sincospi(double* a, double* b, double* c) {
|
||||
int tid = threadIdx.x;
|
||||
sincospi(a[tid], b + tid, c + tid);
|
||||
}
|
||||
|
||||
__global__ void test_llrint(double* a, long long int* b) {
|
||||
int tid = threadIdx.x;
|
||||
b[tid] = llrint(a[tid]);
|
||||
}
|
||||
|
||||
__global__ void test_lrint(double* a, long int* b) {
|
||||
int tid = threadIdx.x;
|
||||
b[tid] = lrint(a[tid]);
|
||||
}
|
||||
|
||||
__global__ void test_rint(double* a, double* b) {
|
||||
int tid = threadIdx.x;
|
||||
b[tid] = rint(a[tid]);
|
||||
}
|
||||
|
||||
__global__ void test_llround(double* a, long long int* b) {
|
||||
int tid = threadIdx.x;
|
||||
b[tid] = llround(a[tid]);
|
||||
}
|
||||
|
||||
__global__ void test_lround(double* a, long int* b) {
|
||||
int tid = threadIdx.x;
|
||||
b[tid] = lround(a[tid]);
|
||||
}
|
||||
|
||||
__global__ void test_rhypot(double* a, double* b, double* c) {
|
||||
int tid = threadIdx.x;
|
||||
c[tid] = rhypot(a[tid], b[tid]);
|
||||
}
|
||||
|
||||
__global__ void test_norm3d(double* a, double* b, double* c, double* d) {
|
||||
int tid = threadIdx.x;
|
||||
d[tid] = norm3d(a[tid], b[tid], c[tid]);
|
||||
}
|
||||
|
||||
__global__ void test_norm4d(double* a, double* b, double* c, double* d,
|
||||
double* e) {
|
||||
int tid = threadIdx.x;
|
||||
e[tid] = norm4d(a[tid], b[tid], c[tid], d[tid]);
|
||||
}
|
||||
|
||||
__global__ void test_rnorm3d(double* a, double* b, double* c, double* d) {
|
||||
int tid = threadIdx.x;
|
||||
d[tid] = rnorm3d(a[tid], b[tid], c[tid]);
|
||||
}
|
||||
|
||||
__global__ void test_rnorm4d(double* a, double* b, double* c, double* d,
|
||||
double* e) {
|
||||
int tid = threadIdx.x;
|
||||
e[tid] = rnorm4d(a[tid], b[tid], c[tid], d[tid]);
|
||||
}
|
||||
|
||||
__global__ void test_rnorm(double* a, double* b) {
|
||||
int tid = threadIdx.x;
|
||||
b[tid] = rnorm(N, a);
|
||||
}
|
||||
|
||||
__global__ void test_erfinv(double* a, double* b) {
|
||||
int tid = threadIdx.x;
|
||||
b[tid] = erf(erfinv(a[tid]));
|
||||
}
|
||||
|
||||
bool run_sincos() {
|
||||
double *A, *Ad, *B, *C, *Bd, *Cd;
|
||||
A = new double[N];
|
||||
B = new double[N];
|
||||
C = new double[N];
|
||||
for (int i = 0; i < N; i++) {
|
||||
A[i] = 1.0;
|
||||
}
|
||||
hipMalloc((void**)&Ad, SIZE);
|
||||
hipMalloc((void**)&Bd, SIZE);
|
||||
hipMalloc((void**)&Cd, SIZE);
|
||||
hipMemcpy(Ad, A, SIZE, hipMemcpyHostToDevice);
|
||||
hipLaunchKernelGGL(test_sincos, dim3(1), dim3(N), 0, 0, Ad, Bd, Cd);
|
||||
hipMemcpy(B, Bd, SIZE, hipMemcpyDeviceToHost);
|
||||
hipMemcpy(C, Cd, SIZE, hipMemcpyDeviceToHost);
|
||||
int passed = 0;
|
||||
for (int i = 0; i < 512; i++) {
|
||||
if (B[i] == sin(1.0)) {
|
||||
passed = 1;
|
||||
}
|
||||
}
|
||||
passed = 0;
|
||||
for (int i = 0; i < 512; i++) {
|
||||
if (C[i] == cos(1.0)) {
|
||||
passed = 1;
|
||||
}
|
||||
}
|
||||
|
||||
delete[] A;
|
||||
delete[] B;
|
||||
delete[] C;
|
||||
hipFree(Ad);
|
||||
hipFree(Bd);
|
||||
hipFree(Cd);
|
||||
|
||||
if (passed == 1) {
|
||||
return true;
|
||||
}
|
||||
assert(passed == 1);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool run_sincospi() {
|
||||
double *A, *Ad, *B, *C, *Bd, *Cd;
|
||||
A = new double[N];
|
||||
B = new double[N];
|
||||
C = new double[N];
|
||||
for (int i = 0; i < N; i++) {
|
||||
A[i] = 1.0;
|
||||
}
|
||||
hipMalloc((void**)&Ad, SIZE);
|
||||
hipMalloc((void**)&Bd, SIZE);
|
||||
hipMalloc((void**)&Cd, SIZE);
|
||||
hipMemcpy(Ad, A, SIZE, hipMemcpyHostToDevice);
|
||||
hipLaunchKernelGGL(test_sincospi, dim3(1), dim3(N), 0, 0, Ad, Bd, Cd);
|
||||
hipMemcpy(B, Bd, SIZE, hipMemcpyDeviceToHost);
|
||||
hipMemcpy(C, Cd, SIZE, hipMemcpyDeviceToHost);
|
||||
int passed = 0;
|
||||
for (int i = 0; i < 512; i++) {
|
||||
if (B[i] - sin(3.14 * 1.0) < 0.1) {
|
||||
passed = 1;
|
||||
}
|
||||
}
|
||||
passed = 0;
|
||||
for (int i = 0; i < 512; i++) {
|
||||
if (C[i] - cos(3.14 * 1.0) < 0.1) {
|
||||
passed = 1;
|
||||
}
|
||||
}
|
||||
|
||||
delete[] A;
|
||||
delete[] B;
|
||||
delete[] C;
|
||||
hipFree(Ad);
|
||||
hipFree(Bd);
|
||||
hipFree(Cd);
|
||||
|
||||
if (passed == 1) {
|
||||
return true;
|
||||
}
|
||||
assert(passed == 1);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool run_llrint() {
|
||||
double *A, *Ad;
|
||||
long long int *B, *Bd;
|
||||
A = new double[N];
|
||||
B = new long long int[N];
|
||||
for (int i = 0; i < N; i++) {
|
||||
A[i] = 1.345;
|
||||
}
|
||||
hipMalloc((void**)&Ad, SIZE);
|
||||
hipMalloc((void**)&Bd, N * sizeof(long long int));
|
||||
hipMemcpy(Ad, A, SIZE, hipMemcpyHostToDevice);
|
||||
hipLaunchKernelGGL(test_llrint, dim3(1), dim3(N), 0, 0, Ad, Bd);
|
||||
hipMemcpy(B, Bd, N * sizeof(long long int), hipMemcpyDeviceToHost);
|
||||
int passed = 0;
|
||||
for (int i = 0; i < 512; i++) {
|
||||
int x = round(A[i]);
|
||||
long long int y = x;
|
||||
if (B[i] == x) {
|
||||
passed = 1;
|
||||
}
|
||||
}
|
||||
|
||||
delete[] A;
|
||||
delete[] B;
|
||||
hipFree(Ad);
|
||||
hipFree(Bd);
|
||||
|
||||
if (passed == 1) {
|
||||
return true;
|
||||
}
|
||||
assert(passed == 1);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool run_lrint() {
|
||||
double *A, *Ad;
|
||||
long int *B, *Bd;
|
||||
A = new double[N];
|
||||
B = new long int[N];
|
||||
for (int i = 0; i < N; i++) {
|
||||
A[i] = 1.345;
|
||||
}
|
||||
hipMalloc((void**)&Ad, SIZE);
|
||||
hipMalloc((void**)&Bd, N * sizeof(long int));
|
||||
hipMemcpy(Ad, A, SIZE, hipMemcpyHostToDevice);
|
||||
hipLaunchKernelGGL(test_lrint, dim3(1), dim3(N), 0, 0, Ad, Bd);
|
||||
hipMemcpy(B, Bd, N * sizeof(long int), hipMemcpyDeviceToHost);
|
||||
int passed = 0;
|
||||
for (int i = 0; i < 512; i++) {
|
||||
long int x = round(A[i]);
|
||||
if (B[i] == x) {
|
||||
passed = 1;
|
||||
}
|
||||
}
|
||||
|
||||
delete[] A;
|
||||
delete[] B;
|
||||
hipFree(Ad);
|
||||
hipFree(Bd);
|
||||
|
||||
if (passed == 1) {
|
||||
return true;
|
||||
}
|
||||
assert(passed == 1);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool run_rint() {
|
||||
double *A, *Ad;
|
||||
double *B, *Bd;
|
||||
A = new double[N];
|
||||
B = new double[N];
|
||||
for (int i = 0; i < N; i++) {
|
||||
A[i] = 1.345;
|
||||
}
|
||||
hipMalloc((void**)&Ad, SIZE);
|
||||
hipMalloc((void**)&Bd, SIZE);
|
||||
hipMemcpy(Ad, A, SIZE, hipMemcpyHostToDevice);
|
||||
hipLaunchKernelGGL(test_rint, dim3(1), dim3(N), 0, 0, Ad, Bd);
|
||||
hipMemcpy(B, Bd, SIZE, hipMemcpyDeviceToHost);
|
||||
int passed = 0;
|
||||
for (int i = 0; i < 512; i++) {
|
||||
double x = round(A[i]);
|
||||
if (B[i] == x) {
|
||||
passed = 1;
|
||||
}
|
||||
}
|
||||
|
||||
delete[] A;
|
||||
delete[] B;
|
||||
hipFree(Ad);
|
||||
hipFree(Bd);
|
||||
|
||||
if (passed == 1) {
|
||||
return true;
|
||||
}
|
||||
assert(passed == 1);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool run_llround() {
|
||||
double *A, *Ad;
|
||||
long long int *B, *Bd;
|
||||
A = new double[N];
|
||||
B = new long long int[N];
|
||||
for (int i = 0; i < N; i++) {
|
||||
A[i] = 1.345;
|
||||
}
|
||||
hipMalloc((void**)&Ad, SIZE);
|
||||
hipMalloc((void**)&Bd, N * sizeof(long long int));
|
||||
hipMemcpy(Ad, A, SIZE, hipMemcpyHostToDevice);
|
||||
hipLaunchKernelGGL(test_llround, dim3(1), dim3(N), 0, 0, Ad, Bd);
|
||||
hipMemcpy(B, Bd, N * sizeof(long long int), hipMemcpyDeviceToHost);
|
||||
int passed = 0;
|
||||
for (int i = 0; i < 512; i++) {
|
||||
long long int x = round(A[i]);
|
||||
if (B[i] == x) {
|
||||
passed = 1;
|
||||
}
|
||||
}
|
||||
|
||||
delete[] A;
|
||||
delete[] B;
|
||||
hipFree(Ad);
|
||||
hipFree(Bd);
|
||||
|
||||
if (passed == 1) {
|
||||
return true;
|
||||
}
|
||||
assert(passed == 1);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool run_lround() {
|
||||
double *A, *Ad;
|
||||
long int *B, *Bd;
|
||||
A = new double[N];
|
||||
B = new long int[N];
|
||||
for (int i = 0; i < N; i++) {
|
||||
A[i] = 1.345;
|
||||
}
|
||||
hipMalloc((void**)&Ad, SIZE);
|
||||
hipMalloc((void**)&Bd, N * sizeof(long int));
|
||||
hipMemcpy(Ad, A, SIZE, hipMemcpyHostToDevice);
|
||||
hipLaunchKernelGGL(test_lround, dim3(1), dim3(N), 0, 0, Ad, Bd);
|
||||
hipMemcpy(B, Bd, N * sizeof(long int), hipMemcpyDeviceToHost);
|
||||
int passed = 0;
|
||||
for (int i = 0; i < 512; i++) {
|
||||
long int x = round(A[i]);
|
||||
if (B[i] == x) {
|
||||
passed = 1;
|
||||
}
|
||||
}
|
||||
|
||||
delete[] A;
|
||||
delete[] B;
|
||||
hipFree(Ad);
|
||||
hipFree(Bd);
|
||||
|
||||
if (passed == 1) {
|
||||
return true;
|
||||
}
|
||||
assert(passed == 1);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool run_norm3d() {
|
||||
double *A, *Ad, *B, *Bd, *C, *Cd, *D, *Dd;
|
||||
A = new double[N];
|
||||
B = new double[N];
|
||||
C = new double[N];
|
||||
D = new double[N];
|
||||
double val = 0.0;
|
||||
for (int i = 0; i < N; i++) {
|
||||
A[i] = 1.0;
|
||||
B[i] = 2.0;
|
||||
C[i] = 3.0;
|
||||
}
|
||||
val = sqrt(1.0 + 4.0 + 9.0);
|
||||
hipMalloc((void**)&Ad, SIZE);
|
||||
hipMalloc((void**)&Bd, SIZE);
|
||||
hipMalloc((void**)&Cd, SIZE);
|
||||
hipMalloc((void**)&Dd, SIZE);
|
||||
hipMemcpy(Ad, A, SIZE, hipMemcpyHostToDevice);
|
||||
hipMemcpy(Bd, B, SIZE, hipMemcpyHostToDevice);
|
||||
hipMemcpy(Cd, C, SIZE, hipMemcpyHostToDevice);
|
||||
hipLaunchKernelGGL(test_norm3d, dim3(1), dim3(N), 0, 0, Ad, Bd, Cd, Dd);
|
||||
hipMemcpy(D, Dd, SIZE, hipMemcpyDeviceToHost);
|
||||
int passed = 0;
|
||||
for (int i = 0; i < 512; i++) {
|
||||
if (D[i] - val < 0.000001) {
|
||||
passed = 1;
|
||||
}
|
||||
}
|
||||
|
||||
delete[] A;
|
||||
delete[] B;
|
||||
delete[] C;
|
||||
delete[] D;
|
||||
hipFree(Ad);
|
||||
hipFree(Bd);
|
||||
hipFree(Cd);
|
||||
hipFree(Dd);
|
||||
|
||||
if (passed == 1) {
|
||||
return true;
|
||||
}
|
||||
assert(passed == 1);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool run_norm4d() {
|
||||
double *A, *Ad, *B, *Bd, *C, *Cd, *D, *Dd, *E, *Ed;
|
||||
A = new double[N];
|
||||
B = new double[N];
|
||||
C = new double[N];
|
||||
D = new double[N];
|
||||
E = new double[N];
|
||||
double val = 0.0;
|
||||
for (int i = 0; i < N; i++) {
|
||||
A[i] = 1.0;
|
||||
B[i] = 2.0;
|
||||
C[i] = 3.0;
|
||||
D[i] = 4.0;
|
||||
}
|
||||
val = sqrt(1.0 + 4.0 + 9.0 + 16.0);
|
||||
hipMalloc((void**)&Ad, SIZE);
|
||||
hipMalloc((void**)&Bd, SIZE);
|
||||
hipMalloc((void**)&Cd, SIZE);
|
||||
hipMalloc((void**)&Dd, SIZE);
|
||||
hipMalloc((void**)&Ed, SIZE);
|
||||
hipMemcpy(Ad, A, SIZE, hipMemcpyHostToDevice);
|
||||
hipMemcpy(Bd, B, SIZE, hipMemcpyHostToDevice);
|
||||
hipMemcpy(Cd, C, SIZE, hipMemcpyHostToDevice);
|
||||
hipMemcpy(Dd, D, SIZE, hipMemcpyHostToDevice);
|
||||
hipLaunchKernelGGL(test_norm4d, dim3(1), dim3(N), 0, 0, Ad, Bd, Cd, Dd, Ed);
|
||||
hipMemcpy(E, Ed, SIZE, hipMemcpyDeviceToHost);
|
||||
int passed = 0;
|
||||
for (int i = 0; i < 512; i++) {
|
||||
if (E[i] - val < 0.000001) {
|
||||
passed = 1;
|
||||
}
|
||||
}
|
||||
|
||||
delete[] A;
|
||||
delete[] B;
|
||||
delete[] C;
|
||||
delete[] D;
|
||||
delete[] E;
|
||||
hipFree(Ad);
|
||||
hipFree(Bd);
|
||||
hipFree(Cd);
|
||||
hipFree(Dd);
|
||||
hipFree(Ed);
|
||||
|
||||
if (passed == 1) {
|
||||
return true;
|
||||
}
|
||||
assert(passed == 1);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool run_rhypot() {
|
||||
double *A, *Ad, *B, *Bd, *C, *Cd;
|
||||
A = new double[N];
|
||||
B = new double[N];
|
||||
C = new double[N];
|
||||
double val = 0.0;
|
||||
for (int i = 0; i < N; i++) {
|
||||
A[i] = 1.0;
|
||||
B[i] = 2.0;
|
||||
}
|
||||
val = 1 / sqrt(1.0 + 4.0);
|
||||
hipMalloc((void**)&Ad, SIZE);
|
||||
hipMalloc((void**)&Bd, SIZE);
|
||||
hipMalloc((void**)&Cd, SIZE);
|
||||
hipMemcpy(Ad, A, SIZE, hipMemcpyHostToDevice);
|
||||
hipMemcpy(Bd, B, SIZE, hipMemcpyHostToDevice);
|
||||
hipLaunchKernelGGL(test_rhypot, dim3(1), dim3(N), 0, 0, Ad, Bd, Cd);
|
||||
hipMemcpy(C, Cd, SIZE, hipMemcpyDeviceToHost);
|
||||
int passed = 0;
|
||||
for (int i = 0; i < 512; i++) {
|
||||
if (C[i] - val < 0.000001) {
|
||||
passed = 1;
|
||||
}
|
||||
}
|
||||
|
||||
delete[] A;
|
||||
delete[] B;
|
||||
delete[] C;
|
||||
hipFree(Ad);
|
||||
hipFree(Bd);
|
||||
hipFree(Cd);
|
||||
|
||||
if (passed == 1) {
|
||||
return true;
|
||||
}
|
||||
assert(passed == 1);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool run_rnorm3d() {
|
||||
double *A, *Ad, *B, *Bd, *C, *Cd, *D, *Dd;
|
||||
A = new double[N];
|
||||
B = new double[N];
|
||||
C = new double[N];
|
||||
D = new double[N];
|
||||
double val = 0.0;
|
||||
for (int i = 0; i < N; i++) {
|
||||
A[i] = 1.0;
|
||||
B[i] = 2.0;
|
||||
C[i] = 3.0;
|
||||
}
|
||||
val = 1 / sqrt(1.0 + 4.0 + 9.0);
|
||||
hipMalloc((void**)&Ad, SIZE);
|
||||
hipMalloc((void**)&Bd, SIZE);
|
||||
hipMalloc((void**)&Cd, SIZE);
|
||||
hipMalloc((void**)&Dd, SIZE);
|
||||
hipMemcpy(Ad, A, SIZE, hipMemcpyHostToDevice);
|
||||
hipMemcpy(Bd, B, SIZE, hipMemcpyHostToDevice);
|
||||
hipMemcpy(Cd, C, SIZE, hipMemcpyHostToDevice);
|
||||
hipLaunchKernelGGL(test_rnorm3d, dim3(1), dim3(N), 0, 0, Ad, Bd, Cd, Dd);
|
||||
hipMemcpy(D, Dd, SIZE, hipMemcpyDeviceToHost);
|
||||
int passed = 0;
|
||||
for (int i = 0; i < 512; i++) {
|
||||
if (D[i] - val < 0.000001) {
|
||||
passed = 1;
|
||||
}
|
||||
}
|
||||
|
||||
delete[] A;
|
||||
delete[] B;
|
||||
delete[] C;
|
||||
delete[] D;
|
||||
hipFree(Ad);
|
||||
hipFree(Bd);
|
||||
hipFree(Cd);
|
||||
hipFree(Dd);
|
||||
|
||||
if (passed == 1) {
|
||||
return true;
|
||||
}
|
||||
assert(passed == 1);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool run_rnorm4d() {
|
||||
double *A, *Ad, *B, *Bd, *C, *Cd, *D, *Dd, *E, *Ed;
|
||||
A = new double[N];
|
||||
B = new double[N];
|
||||
C = new double[N];
|
||||
D = new double[N];
|
||||
E = new double[N];
|
||||
double val = 0.0;
|
||||
for (int i = 0; i < N; i++) {
|
||||
A[i] = 1.0;
|
||||
B[i] = 2.0;
|
||||
C[i] = 3.0;
|
||||
D[i] = 4.0;
|
||||
}
|
||||
val = 1 / sqrt(1.0 + 4.0 + 9.0 + 16.0);
|
||||
hipMalloc((void**)&Ad, SIZE);
|
||||
hipMalloc((void**)&Bd, SIZE);
|
||||
hipMalloc((void**)&Cd, SIZE);
|
||||
hipMalloc((void**)&Dd, SIZE);
|
||||
hipMalloc((void**)&Ed, SIZE);
|
||||
hipMemcpy(Ad, A, SIZE, hipMemcpyHostToDevice);
|
||||
hipMemcpy(Bd, B, SIZE, hipMemcpyHostToDevice);
|
||||
hipMemcpy(Cd, C, SIZE, hipMemcpyHostToDevice);
|
||||
hipMemcpy(Dd, D, SIZE, hipMemcpyHostToDevice);
|
||||
hipLaunchKernelGGL(test_rnorm4d, dim3(1), dim3(N), 0, 0, Ad, Bd, Cd, Dd, Ed);
|
||||
hipMemcpy(E, Ed, SIZE, hipMemcpyDeviceToHost);
|
||||
int passed = 0;
|
||||
for (int i = 0; i < 512; i++) {
|
||||
if (E[i] - val < 0.000001) {
|
||||
passed = 1;
|
||||
}
|
||||
}
|
||||
|
||||
delete[] A;
|
||||
delete[] B;
|
||||
delete[] C;
|
||||
delete[] D;
|
||||
delete[] E;
|
||||
hipFree(Ad);
|
||||
hipFree(Bd);
|
||||
hipFree(Cd);
|
||||
hipFree(Dd);
|
||||
hipFree(Ed);
|
||||
|
||||
if (passed == 1) {
|
||||
return true;
|
||||
}
|
||||
assert(passed == 1);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool run_rnorm() {
|
||||
double *A, *Ad, *B, *Bd;
|
||||
A = new double[N];
|
||||
B = new double[N];
|
||||
double val = 0.0;
|
||||
for (int i = 0; i < N; i++) {
|
||||
A[i] = 1.0;
|
||||
B[i] = 0.0;
|
||||
val += 1.0;
|
||||
}
|
||||
val = 1 / sqrt(val);
|
||||
hipMalloc((void**)&Ad, SIZE);
|
||||
hipMalloc((void**)&Bd, SIZE);
|
||||
hipMemcpy(Ad, A, SIZE, hipMemcpyHostToDevice);
|
||||
hipLaunchKernelGGL(test_rnorm, dim3(1), dim3(N), 0, 0, Ad, Bd);
|
||||
hipMemcpy(B, Bd, SIZE, hipMemcpyDeviceToHost);
|
||||
int passed = 0;
|
||||
for (int i = 0; i < 512; i++) {
|
||||
if (B[0] - val < 0.000001) {
|
||||
passed = 1;
|
||||
}
|
||||
}
|
||||
|
||||
delete[] A;
|
||||
delete[] B;
|
||||
hipFree(Ad);
|
||||
hipFree(Bd);
|
||||
|
||||
if (passed == 1) {
|
||||
return true;
|
||||
}
|
||||
assert(passed == 1);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool run_erfinv() {
|
||||
double *A, *Ad, *B, *Bd;
|
||||
A = new double[N];
|
||||
B = new double[N];
|
||||
for (int i = 0; i < N; i++) {
|
||||
A[i] = -0.6;
|
||||
B[i] = 0.0;
|
||||
}
|
||||
hipMalloc((void**)&Ad, SIZE);
|
||||
hipMalloc((void**)&Bd, SIZE);
|
||||
hipMemcpy(Ad, A, SIZE, hipMemcpyHostToDevice);
|
||||
hipLaunchKernelGGL(test_erfinv, dim3(1), dim3(N), 0, 0, Ad, Bd);
|
||||
hipMemcpy(B, Bd, SIZE, hipMemcpyDeviceToHost);
|
||||
int passed = 0;
|
||||
for (int i = 0; i < 512; i++) {
|
||||
if (B[i] - A[i] < 0.000001) {
|
||||
passed = 1;
|
||||
}
|
||||
}
|
||||
|
||||
delete[] A;
|
||||
delete[] B;
|
||||
hipFree(Ad);
|
||||
hipFree(Bd);
|
||||
|
||||
if (passed == 1) {
|
||||
return true;
|
||||
}
|
||||
assert(passed == 1);
|
||||
return false;
|
||||
}
|
||||
|
||||
int main() {
|
||||
if (run_sincos() && run_sincospi() && run_llrint() && run_norm3d() && run_norm4d() &&
|
||||
run_rnorm3d() && run_rnorm4d() && run_rnorm() && run_lround() && run_llround() &&
|
||||
run_rint() && run_rhypot() && run_erfinv()) {
|
||||
passed();
|
||||
}
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
/*
|
||||
Copyright (c) 2015 - 2021 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:
|
||||
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.
|
||||
*/
|
||||
|
||||
#include <hip/hip_runtime_api.h>
|
||||
#include <iostream>
|
||||
#include <assert.h>
|
||||
|
||||
int main() {
|
||||
size_t heap;
|
||||
assert(hipSuccess == hipDeviceGetLimit(&heap, hipLimitMallocHeapSize));
|
||||
assert(heap == 4194304);
|
||||
}
|
||||
@@ -1,131 +0,0 @@
|
||||
/*
|
||||
Copyright (c) 2015 - 2021 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:
|
||||
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.
|
||||
*/
|
||||
|
||||
/* HIT_START
|
||||
* BUILD: %t %s
|
||||
* TEST: %t
|
||||
* HIT_END
|
||||
*/
|
||||
|
||||
#include <hip/hip_runtime.h>
|
||||
#include <hip/hip_runtime_api.h>
|
||||
#include "test_common.h"
|
||||
#include <iostream>
|
||||
|
||||
#define NUM 1024
|
||||
#define SIZE 1024 * 4
|
||||
|
||||
__device__ int globalIn[NUM];
|
||||
__device__ int globalOut[NUM];
|
||||
|
||||
__global__ void Assign(int* Out) {
|
||||
int tid = threadIdx.x + blockIdx.x * blockDim.x;
|
||||
Out[tid] = globalIn[tid];
|
||||
globalOut[tid] = globalIn[tid];
|
||||
}
|
||||
|
||||
__device__ __constant__ int globalConst[NUM];
|
||||
|
||||
__global__ void checkAddress(int* addr, bool* out) {
|
||||
*out = (globalConst == addr);
|
||||
}
|
||||
|
||||
int main() {
|
||||
int *A, *Am, *B, *Ad, *C, *Cm;
|
||||
A = new int[NUM];
|
||||
B = new int[NUM];
|
||||
C = new int[NUM];
|
||||
for (int i = 0; i < NUM; i++) {
|
||||
A[i] = -1 * i;
|
||||
B[i] = 0;
|
||||
C[i] = 0;
|
||||
}
|
||||
|
||||
hipMalloc((void**)&Ad, SIZE);
|
||||
hipHostMalloc((void**)&Am, SIZE);
|
||||
hipHostMalloc((void**)&Cm, SIZE);
|
||||
for (int i = 0; i < NUM; i++) {
|
||||
Am[i] = -1 * i;
|
||||
Cm[i] = 0;
|
||||
}
|
||||
|
||||
hipStream_t stream;
|
||||
hipStreamCreate(&stream);
|
||||
hipMemcpyToSymbolAsync(HIP_SYMBOL(globalIn), Am, SIZE, 0, hipMemcpyHostToDevice, stream);
|
||||
hipStreamSynchronize(stream);
|
||||
hipLaunchKernelGGL(Assign, dim3(1, 1, 1), dim3(NUM, 1, 1), 0, 0, Ad);
|
||||
hipMemcpy(B, Ad, SIZE, hipMemcpyDeviceToHost);
|
||||
hipMemcpyFromSymbolAsync(Cm, HIP_SYMBOL(globalOut), SIZE, 0, hipMemcpyDeviceToHost, stream);
|
||||
hipStreamSynchronize(stream);
|
||||
for (int i = 0; i < NUM; i++) {
|
||||
assert(Am[i] == B[i]);
|
||||
assert(Am[i] == Cm[i]);
|
||||
}
|
||||
|
||||
for (int i = 0; i < NUM; i++) {
|
||||
A[i] = -2 * i;
|
||||
B[i] = 0;
|
||||
}
|
||||
|
||||
hipMemcpyToSymbol(HIP_SYMBOL(globalIn), A, SIZE, 0, hipMemcpyHostToDevice);
|
||||
hipLaunchKernelGGL(Assign, dim3(1, 1, 1), dim3(NUM, 1, 1), 0, 0, Ad);
|
||||
hipMemcpy(B, Ad, SIZE, hipMemcpyDeviceToHost);
|
||||
hipMemcpyFromSymbol(C, HIP_SYMBOL(globalOut), SIZE, 0, hipMemcpyDeviceToHost);
|
||||
for (int i = 0; i < NUM; i++) {
|
||||
assert(A[i] == B[i]);
|
||||
assert(A[i] == C[i]);
|
||||
}
|
||||
|
||||
for (int i = 0; i < NUM; i++) {
|
||||
A[i] = -3 * i;
|
||||
B[i] = 0;
|
||||
}
|
||||
|
||||
hipMemcpyToSymbolAsync(HIP_SYMBOL(globalIn), A, SIZE, 0, hipMemcpyHostToDevice, stream);
|
||||
hipStreamSynchronize(stream);
|
||||
hipLaunchKernelGGL(Assign, dim3(1, 1, 1), dim3(NUM, 1, 1), 0, 0, Ad);
|
||||
hipMemcpy(B, Ad, SIZE, hipMemcpyDeviceToHost);
|
||||
hipMemcpyFromSymbolAsync(C, HIP_SYMBOL(globalOut), SIZE, 0, hipMemcpyDeviceToHost, stream);
|
||||
hipStreamSynchronize(stream);
|
||||
for (int i = 0; i < NUM; i++) {
|
||||
assert(A[i] == B[i]);
|
||||
assert(A[i] == C[i]);
|
||||
}
|
||||
|
||||
bool *checkOkD;
|
||||
bool checkOk = false;
|
||||
size_t symbolSize = 0;
|
||||
int *symbolAddress;
|
||||
hipGetSymbolSize(&symbolSize, HIP_SYMBOL(globalConst));
|
||||
hipGetSymbolAddress((void**) &symbolAddress, HIP_SYMBOL(globalConst));
|
||||
hipMalloc((void**)&checkOkD, sizeof(bool));
|
||||
hipLaunchKernelGGL(checkAddress, dim3(1, 1, 1), dim3(1, 1, 1), 0, 0, symbolAddress, checkOkD);
|
||||
hipMemcpy(&checkOk, checkOkD, sizeof(bool), hipMemcpyDeviceToHost);
|
||||
hipFree(checkOkD);
|
||||
assert(checkOk);
|
||||
assert(symbolSize == SIZE);
|
||||
|
||||
hipHostFree(Am);
|
||||
hipHostFree(Cm);
|
||||
hipFree(Ad);
|
||||
delete[] A;
|
||||
delete[] B;
|
||||
delete[] C;
|
||||
passed();
|
||||
}
|
||||
@@ -1,69 +0,0 @@
|
||||
/*
|
||||
Copyright (c) 2015 - 2021 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:
|
||||
|
||||
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.
|
||||
*/
|
||||
|
||||
/* HIT_START
|
||||
* BUILD: %t %s ../test_common.cpp NVCC_OPTIONS -std=c++11
|
||||
* TEST: %t
|
||||
* HIT_END
|
||||
*/
|
||||
|
||||
#include <hip/hip_runtime.h>
|
||||
#include <hip/math_functions.h>
|
||||
#include "test_common.h"
|
||||
|
||||
|
||||
__global__ void DotFunctions(bool* result) {
|
||||
#if __HIP_CLANG_ONLY__
|
||||
// Dot Functions
|
||||
short2 sa{1}, sb{1};
|
||||
result[0] = amd_mixed_dot(sa, sb, 1, result[0]) && result[0];
|
||||
|
||||
ushort2 usa{1}, usb{1};
|
||||
result[0] = amd_mixed_dot(usa, usb, (uint) 1, result[0]) && result[0];
|
||||
|
||||
char4 ca{1}, cb{1};
|
||||
result[0] = amd_mixed_dot(ca, cb, 1, result[0]) && result[0];
|
||||
|
||||
uchar4 uca{1}, ucb{1};
|
||||
result[0] = amd_mixed_dot(uca, ucb, (uint) 1, result[0]) && result[0];
|
||||
|
||||
int ia{1}, ib{1};
|
||||
result[0] = amd_mixed_dot(ia, ib, 1, result[0]) && result[0];
|
||||
|
||||
uint ua{1}, ub{1};
|
||||
result[0] = amd_mixed_dot(ua, ub, (uint) 1, result[0]) && result[0];
|
||||
#endif
|
||||
}
|
||||
|
||||
int main() {
|
||||
bool* result{nullptr};
|
||||
hipHostMalloc(&result, 1);
|
||||
result[0] = true;
|
||||
|
||||
hipLaunchKernelGGL(DotFunctions, dim3(1, 1, 1), dim3(1, 1, 1), 0, 0, result);
|
||||
hipDeviceSynchronize();
|
||||
if (!result[0]) { failed("Failed dot tests."); }
|
||||
|
||||
hipHostFree(result);
|
||||
|
||||
passed();
|
||||
}
|
||||
@@ -1,187 +0,0 @@
|
||||
/*
|
||||
Copyright (c) 2015 - 2021 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:
|
||||
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.
|
||||
*/
|
||||
|
||||
/* HIT_START
|
||||
* BUILD: %t %s ../test_common.cpp EXCLUDE_HIP_PLATFORM nvidia
|
||||
* TEST: %t
|
||||
* HIT_END
|
||||
*/
|
||||
|
||||
#include "test_common.h"
|
||||
#include <hip/hip_runtime.h>
|
||||
#include <hip/hip_runtime_api.h>
|
||||
#include <iostream>
|
||||
|
||||
#define HIP_ASSERT(status) assert(status == hipSuccess)
|
||||
|
||||
#define LEN 50
|
||||
#define SIZE (LEN * sizeof(bool))
|
||||
|
||||
__global__ void kernelTestFMA(bool *Ad) {
|
||||
float f = 1.0f / 3.0f;
|
||||
double d = f;
|
||||
int i = 0;
|
||||
auto Check = [&](bool Cond) { Ad[i++] = Cond; };
|
||||
// f * f + 3.0f will be different if promoted to double.
|
||||
float floatResult = fma(f, f, 3.0f);
|
||||
double doubleResult = fma(d, d, 3.0);
|
||||
Check(floatResult != doubleResult);
|
||||
|
||||
if(sizeof(decltype(fma(f, f, 3))) == 8) {
|
||||
// To align with libcxx, if any argument has integral type,
|
||||
// it is cast to double.
|
||||
// Check type promotes to double.
|
||||
Check(fma(f, f, 3) == doubleResult);
|
||||
Check(fma(f, f, (char)3) == doubleResult);
|
||||
Check(fma(f, f, (unsigned char)3) == doubleResult);
|
||||
Check(fma(f, f, (short)3) == doubleResult);
|
||||
Check(fma(f, f, (unsigned short)3) == doubleResult);
|
||||
Check(fma(f, f, (int)3) == doubleResult);
|
||||
Check(fma(f, f, (unsigned int)3) == doubleResult);
|
||||
Check(fma(f, f, (long)3) == doubleResult);
|
||||
Check(fma(f, f, (unsigned long)3) == doubleResult);
|
||||
Check(fma(f, f, true) == fma((double)f, (double)f, 1.0));
|
||||
} else if(sizeof(decltype(fma(f, f, 3))) == 4) {
|
||||
// Previous HIP headers returns float type.
|
||||
// Delete this to support backwards compatibility.
|
||||
// check promote to float.
|
||||
Check(fma(f, f, 3) == floatResult);
|
||||
Check(fma(f, f, (char)3) == floatResult);
|
||||
Check(fma(f, f, (unsigned char)3) == floatResult);
|
||||
Check(fma(f, f, (short)3) == floatResult);
|
||||
Check(fma(f, f, (unsigned short)3) == floatResult);
|
||||
Check(fma(f, f, (int)3) == floatResult);
|
||||
Check(fma(f, f, (unsigned int)3) == floatResult);
|
||||
Check(fma(f, f, (long)3) == floatResult);
|
||||
Check(fma(f, f, (unsigned long)3) == floatResult);
|
||||
Check(fma(f, f, true) == fma(f, f, 1.0f));
|
||||
} else {
|
||||
assert(0 && "Invalid fma return type.");
|
||||
}
|
||||
|
||||
Check(fma(d, (double)f, 3) == doubleResult);
|
||||
Check(fma(d, (double)f, (char)3) == doubleResult);
|
||||
Check(fma(d, (double)f, (unsigned char)3) == doubleResult);
|
||||
Check(fma(d, (double)f, (short)3) == doubleResult);
|
||||
Check(fma(d, (double)f, (unsigned short)3) == doubleResult);
|
||||
Check(fma(d, (double)f, (int)3) == doubleResult);
|
||||
Check(fma(d, (double)f, (unsigned int)3) == doubleResult);
|
||||
Check(fma(d, (double)f, (long)3) == doubleResult);
|
||||
Check(fma(d, (double)f, (unsigned long)3) == doubleResult);
|
||||
Check(fma(d, (double)f, true) == fma((double)f, (double)f, 1.0));
|
||||
|
||||
while (i < LEN)
|
||||
Check(true);
|
||||
}
|
||||
|
||||
void runTestFMA() {
|
||||
bool *Ad;
|
||||
bool A[LEN];
|
||||
for (unsigned i = 0; i < LEN; i++) {
|
||||
A[i] = 0;
|
||||
}
|
||||
|
||||
HIP_ASSERT(hipMalloc((void **)&Ad, SIZE));
|
||||
hipLaunchKernelGGL(kernelTestFMA, dim3(1, 1, 1), dim3(1, 1, 1), 0, 0, Ad);
|
||||
HIP_ASSERT(hipMemcpy(A, Ad, SIZE, hipMemcpyDeviceToHost));
|
||||
|
||||
for (unsigned i = 0; i < LEN; i++) {
|
||||
assert(A[i]);
|
||||
}
|
||||
}
|
||||
|
||||
__global__ void kernelTestHalfFMA(bool *Ad) {
|
||||
_Float16 h = (_Float16)(1.0f/3.0f);
|
||||
float f = h;
|
||||
double d = f;
|
||||
int i = 0;
|
||||
auto Check = [&](bool Cond) { Ad[i++] = Cond; };
|
||||
// h * h + 3 will be different if promoted to float.
|
||||
_Float16 halfResult = fma(h, h, (_Float16)3);
|
||||
float floatResult = fma(f, f, 3.0f);
|
||||
double doubleResult = fma(d, d, 3.0);
|
||||
Check(halfResult != floatResult);
|
||||
Check(halfResult != doubleResult);
|
||||
|
||||
// check promote to half.
|
||||
// fma(_Float16, _Float16, int) should resolve to
|
||||
// fma(double, double, double). This is similar to
|
||||
// fma(float, float, int) resolving to fma(double, double, double)
|
||||
// as required Standard C++ header <cmath>.
|
||||
if (sizeof(decltype(fma(h, h, 3))) == 8) {
|
||||
Check(fma(h, h, 3) == doubleResult);
|
||||
Check(fma(h, h, (char)3) == doubleResult);
|
||||
Check(fma(h, h, (unsigned char)3) == doubleResult);
|
||||
Check(fma(h, h, (short)3) == doubleResult);
|
||||
Check(fma(h, h, (unsigned short)3) == doubleResult);
|
||||
Check(fma(h, h, (int)3) == doubleResult);
|
||||
Check(fma(h, h, (unsigned int)3) == doubleResult);
|
||||
Check(fma(h, h, (long)3) == doubleResult);
|
||||
Check(fma(h, h, (unsigned long)3) == doubleResult);
|
||||
Check(fma(h, h, true) == fma((double)h, (double) h, 1.0));
|
||||
} else if (sizeof(decltype(fma(h, h, 3))) == 2) {
|
||||
// ToDo: Currently there is a bug in clang header
|
||||
// __clang_hip_cmath.h due to using
|
||||
// std::numeric_limits<T>::is_specified to define
|
||||
// overloaded math functions. Since numeric_limits is
|
||||
// not specicialized for _Float16, overloaded template
|
||||
// functions with argument promotion are not defined
|
||||
// for _Float16. As a result, fma(_Float16, _Float16, int)
|
||||
// is resolved to fma(_Float16, _Float16, _Float16).
|
||||
// This part should be removed after __clang_hip_cmath.h
|
||||
// is fixed.
|
||||
Check(fma(h, h, 3) == halfResult);
|
||||
Check(fma(h, h, (char)3) == halfResult);
|
||||
Check(fma(h, h, (unsigned char)3) == halfResult);
|
||||
Check(fma(h, h, (short)3) == halfResult);
|
||||
Check(fma(h, h, (unsigned short)3) == halfResult);
|
||||
Check(fma(h, h, (int)3) == halfResult);
|
||||
Check(fma(h, h, (unsigned int)3) == halfResult);
|
||||
Check(fma(h, h, (long)3) == halfResult);
|
||||
Check(fma(h, h, (unsigned long)3) == halfResult);
|
||||
Check(fma(h, h, true) == fma(h, h, (_Float16)1));
|
||||
} else {
|
||||
assert(0 && "Invalid fma return type.");
|
||||
}
|
||||
|
||||
while (i < LEN)
|
||||
Check(true);
|
||||
}
|
||||
|
||||
void runTestHalfFMA() {
|
||||
bool *Ad;
|
||||
bool A[LEN];
|
||||
for (unsigned i = 0; i < LEN; i++) {
|
||||
A[i] = 0;
|
||||
}
|
||||
|
||||
HIP_ASSERT(hipMalloc((void **)&Ad, SIZE));
|
||||
hipLaunchKernelGGL(kernelTestHalfFMA, dim3(1, 1, 1), dim3(1, 1, 1), 0, 0, Ad);
|
||||
HIP_ASSERT(hipMemcpy(A, Ad, SIZE, hipMemcpyDeviceToHost));
|
||||
|
||||
for (unsigned i = 0; i < LEN; i++) {
|
||||
assert(A[i]);
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
runTestFMA();
|
||||
runTestHalfFMA();
|
||||
passed();
|
||||
}
|
||||
@@ -1,294 +0,0 @@
|
||||
/*
|
||||
Copyright (c) 2015 - 2021 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:
|
||||
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.
|
||||
*/
|
||||
|
||||
/* HIT_START
|
||||
* BUILD: %t %s ../test_common.cpp EXCLUDE_HIP_PLATFORM nvidia
|
||||
* TEST: %t
|
||||
* HIT_END
|
||||
*/
|
||||
|
||||
#include <hip/hip_fp16.h>
|
||||
#include "hip/hip_runtime.h"
|
||||
|
||||
#include "test_common.h"
|
||||
|
||||
__device__ void test_convert() {
|
||||
__half x;
|
||||
float y = (float)x;
|
||||
}
|
||||
|
||||
__global__
|
||||
void __halfMath(bool* result, __half a) {
|
||||
result[0] = __heq(__hadd(a, __half{1}), __half{2});
|
||||
result[0] = __heq(__hadd_sat(a, __half{1}), __half{1}) && result[0];
|
||||
result[0] = __heq(__hfma(a, __half{2}, __half{3}), __half{5}) && result[0];
|
||||
result[0] =
|
||||
__heq(__hfma_sat(a, __half{2}, __half{3}), __half{1}) && result[0];
|
||||
result[0] = __heq(__hsub(a, __half{1}), __half{0}) && result[0];
|
||||
result[0] = __heq(__hsub_sat(a, __half{2}), __half{0}) && result[0];
|
||||
result[0] = __heq(__hmul(a, __half{2}), __half{2}) && result[0];
|
||||
result[0] = __heq(__hmul_sat(a, __half{2}), __half{1}) && result[0];
|
||||
result[0] = __heq(__hdiv(a, __half{2}), __half{0.5}) && result[0];
|
||||
}
|
||||
|
||||
__device__
|
||||
bool to_bool(const __half2& x)
|
||||
{
|
||||
auto r = static_cast<const __half2_raw&>(x);
|
||||
|
||||
return r.data.x != 0 && r.data.y != 0;
|
||||
}
|
||||
|
||||
__global__
|
||||
void __half2Math(bool* result, __half2 a) {
|
||||
result[0] =
|
||||
to_bool(__heq2(__hadd2(a, __half2{1, 1}), __half2{2, 2}));
|
||||
result[0] = to_bool(__heq2(__hadd2_sat(a, __half2{1, 1}), __half2{1, 1})) &&
|
||||
result[0];
|
||||
result[0] = to_bool(__heq2(
|
||||
__hfma2(a, __half2{2, 2}, __half2{3, 3}), __half2{5, 5})) && result[0];
|
||||
result[0] = to_bool(__heq2(
|
||||
__hfma2_sat(a, __half2{2, 2}, __half2{3, 3}), __half2{1, 1})) && result[0];
|
||||
result[0] = to_bool(__heq2(__hsub2(a, __half2{1, 1}), __half2{0, 0})) &&
|
||||
result[0];
|
||||
result[0] = to_bool(__heq2(__hsub2_sat(a, __half2{2, 2}), __half2{0, 0})) &&
|
||||
result[0];
|
||||
result[0] = to_bool(__heq2(__hmul2(a, __half2{2, 2}), __half2{2, 2})) &&
|
||||
result[0];
|
||||
result[0] = to_bool(__heq2(__hmul2_sat(a, __half2{2, 2}), __half2{1, 1})) &&
|
||||
result[0];
|
||||
result[0] = to_bool(__heq2(__h2div(a, __half2{2, 2}), __half2{0.5, 0.5})) &&
|
||||
result[0];
|
||||
}
|
||||
|
||||
__global__
|
||||
void kernel_hisnan(__half* input, int* output) {
|
||||
int tx = threadIdx.x;
|
||||
output[tx] = __hisnan(input[tx]);
|
||||
}
|
||||
|
||||
__global__
|
||||
void kernel_hisinf(__half* input, int* output) {
|
||||
int tx = threadIdx.x;
|
||||
output[tx] = __hisinf(input[tx]);
|
||||
}
|
||||
|
||||
__global__ void testHalfAbs(float* p) {
|
||||
auto a = __float2half(*p);
|
||||
a = __habs(a);
|
||||
*p = __half2float(a);
|
||||
}
|
||||
|
||||
__global__ void testHalf2Abs(float2* p) {
|
||||
auto a = __float22half2_rn(*p);
|
||||
a = __habs2(a);
|
||||
*p = __half22float2(a);
|
||||
}
|
||||
|
||||
|
||||
__half host_ushort_as_half(unsigned short s) {
|
||||
union {__half h; unsigned short s; } converter;
|
||||
converter.s = s;
|
||||
return converter.h;
|
||||
}
|
||||
|
||||
|
||||
void check_hisnan(int NUM_INPUTS, __half* inputCPU, __half* inputGPU) {
|
||||
|
||||
// allocate memory
|
||||
auto memsize = NUM_INPUTS * sizeof(int);
|
||||
int* outputGPU = nullptr;
|
||||
hipMalloc((void**)&outputGPU, memsize);
|
||||
|
||||
// launch the kernel
|
||||
hipLaunchKernelGGL(
|
||||
kernel_hisnan, dim3(1), dim3(NUM_INPUTS), 0, 0, inputGPU, outputGPU);
|
||||
|
||||
// copy output from device
|
||||
int* outputCPU = (int*) malloc(memsize);
|
||||
hipMemcpy(outputCPU, outputGPU, memsize, hipMemcpyDeviceToHost);
|
||||
|
||||
// check output
|
||||
for (int i=0; i<NUM_INPUTS; i++) {
|
||||
if ((2 <= i) && (i <= 5)) { // inputs are nan, output should be true
|
||||
if (outputCPU[i] == 0) {
|
||||
failed(
|
||||
"__hisnan() returned false for %f (input idx = %d)\n",
|
||||
static_cast<float>(inputCPU[i]),
|
||||
i);
|
||||
}
|
||||
}
|
||||
else { // inputs are NOT nan, output should be false
|
||||
if (outputCPU[i] != 0) {
|
||||
failed(
|
||||
"__hisnan() returned true for %f (input idx = %d)\n",
|
||||
static_cast<float>(inputCPU[i]),
|
||||
i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// free memory
|
||||
free(outputCPU);
|
||||
hipFree(outputGPU);
|
||||
|
||||
// done
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
void check_hisinf(int NUM_INPUTS, __half* inputCPU, __half* inputGPU) {
|
||||
// allocate memory
|
||||
auto memsize = NUM_INPUTS * sizeof(int);
|
||||
int* outputGPU = nullptr;
|
||||
hipMalloc((void**)&outputGPU, memsize);
|
||||
|
||||
// launch the kernel
|
||||
hipLaunchKernelGGL(
|
||||
kernel_hisinf, dim3(1), dim3(NUM_INPUTS), 0, 0, inputGPU, outputGPU);
|
||||
|
||||
// copy output from device
|
||||
int* outputCPU = (int*) malloc(memsize);
|
||||
hipMemcpy(outputCPU, outputGPU, memsize, hipMemcpyDeviceToHost);
|
||||
|
||||
// check output
|
||||
for (int i=0; i<NUM_INPUTS; i++) {
|
||||
if ((0 <= i) && (i <= 1)) { // inputs are inf, output should be true
|
||||
if (outputCPU[i] == 0) {
|
||||
failed(
|
||||
"__hisinf() returned false for %f (input idx = %d)\n",
|
||||
static_cast<float>(inputCPU[i]),
|
||||
i);
|
||||
}
|
||||
}
|
||||
else { // inputs are NOT inf, output should be false
|
||||
if (outputCPU[i] != 0) {
|
||||
failed(
|
||||
"__hisinf() returned true for %f (input idx = %d)\n",
|
||||
static_cast<float>(inputCPU[i]),
|
||||
i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// free memory
|
||||
free(outputCPU);
|
||||
hipFree(outputGPU);
|
||||
|
||||
// done
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
void checkFunctional() {
|
||||
|
||||
// allocate memory
|
||||
const int NUM_INPUTS = 16;
|
||||
auto memsize = NUM_INPUTS * sizeof(__half);
|
||||
__half* inputCPU = (__half*) malloc(memsize);
|
||||
|
||||
// populate inputs
|
||||
inputCPU[0] = host_ushort_as_half(0x7c00); // inf
|
||||
inputCPU[1] = host_ushort_as_half(0xfc00); // -inf
|
||||
inputCPU[2] = host_ushort_as_half(0x7c01); // nan
|
||||
inputCPU[3] = host_ushort_as_half(0x7e00); // nan
|
||||
inputCPU[4] = host_ushort_as_half(0xfc01); // nan
|
||||
inputCPU[5] = host_ushort_as_half(0xfe00); // nan
|
||||
inputCPU[6] = host_ushort_as_half(0x0000); // 0
|
||||
inputCPU[7] = host_ushort_as_half(0x8000); // -0
|
||||
inputCPU[8] = host_ushort_as_half(0x7bff); // max +ve normal
|
||||
inputCPU[9] = host_ushort_as_half(0xfbff); // max -ve normal
|
||||
inputCPU[10] = host_ushort_as_half(0x0400); // min +ve normal
|
||||
inputCPU[11] = host_ushort_as_half(0x8400); // min -ve normal
|
||||
inputCPU[12] = host_ushort_as_half(0x03ff); // max +ve sub-normal
|
||||
inputCPU[13] = host_ushort_as_half(0x83ff); // max -ve sub-normal
|
||||
inputCPU[14] = host_ushort_as_half(0x0001); // min +ve sub-normal
|
||||
inputCPU[15] = host_ushort_as_half(0x8001); // min -ve sub-normal
|
||||
|
||||
// copy inputs to the GPU
|
||||
__half* inputGPU = nullptr;
|
||||
hipMalloc((void**)&inputGPU, memsize);
|
||||
hipMemcpy(inputGPU, inputCPU, memsize, hipMemcpyHostToDevice);
|
||||
|
||||
// run checks
|
||||
|
||||
check_hisnan(NUM_INPUTS, inputCPU, inputGPU);
|
||||
|
||||
check_hisinf(NUM_INPUTS, inputCPU, inputGPU);
|
||||
|
||||
// free memory
|
||||
hipFree(inputGPU);
|
||||
free(inputCPU);
|
||||
|
||||
// all done
|
||||
return;
|
||||
}
|
||||
|
||||
void checkHalfAbs() {
|
||||
{
|
||||
float *p;
|
||||
hipMalloc(&p, sizeof(float));
|
||||
float pp = -2.1f;
|
||||
hipMemcpy(p, &pp, sizeof(float), hipMemcpyDefault);
|
||||
hipLaunchKernelGGL(testHalfAbs, 1, 1, 0, 0, p);
|
||||
hipMemcpy(&pp, p, sizeof(float), hipMemcpyDefault);
|
||||
hipFree(p);
|
||||
if(pp < 0.0f) { failed("Half Abs failed"); }
|
||||
}
|
||||
{
|
||||
float2 *p;
|
||||
hipMalloc(&p, sizeof(float2));
|
||||
float2 pp;
|
||||
pp.x = -2.1f;
|
||||
pp.y = -1.1f;
|
||||
hipMemcpy(p, &pp, sizeof(float2), hipMemcpyDefault);
|
||||
hipLaunchKernelGGL(testHalf2Abs, 1, 1, 0, 0, p);
|
||||
hipMemcpy(&pp, p, sizeof(float2), hipMemcpyDefault);
|
||||
hipFree(p);
|
||||
if(pp.x < 0.0f || pp.y < 0.0f) { failed("Half2 Abs Test Failed"); }
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
bool* result{nullptr};
|
||||
hipMemAllocHost((void**)&result, sizeof(result));
|
||||
|
||||
result[0] = false;
|
||||
hipLaunchKernelGGL(
|
||||
__halfMath, dim3(1, 1, 1), dim3(1, 1, 1), 0, 0, result, __half{1});
|
||||
hipDeviceSynchronize();
|
||||
|
||||
if (!result[0]) { failed("Failed __half tests."); }
|
||||
|
||||
result[0] = false;
|
||||
hipLaunchKernelGGL(
|
||||
__half2Math, dim3(1, 1, 1), dim3(1, 1, 1), 0, 0, result, __half2{1, 1});
|
||||
hipDeviceSynchronize();
|
||||
|
||||
if (!result[0]) { failed("Failed __half2 tests."); }
|
||||
|
||||
hipHostFree(result);
|
||||
|
||||
// run some functional checks
|
||||
checkFunctional();
|
||||
|
||||
checkHalfAbs();
|
||||
|
||||
passed();
|
||||
}
|
||||
@@ -1,384 +0,0 @@
|
||||
/*
|
||||
Copyright (c) 2015 - 2021 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:
|
||||
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.
|
||||
*/
|
||||
#include "test_common.h"
|
||||
#include <iostream>
|
||||
#include "hip/hip_runtime.h"
|
||||
#include "hip/hip_runtime_api.h"
|
||||
|
||||
#define N 512
|
||||
|
||||
bool check_erfcinvf() {
|
||||
uint32_t len = 4;
|
||||
float Val[] = {0.1, 1.2, 1, 0.9};
|
||||
float Out[] = {1.16309, -0.179144, 0, 0.0889};
|
||||
for (int i = 0; i < len; i++) {
|
||||
if (Out[i] - erfcinvf(Val[i]) > 0.0001) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool check_erfcxf() {
|
||||
uint32_t len = 4;
|
||||
float Val[] = {-0.5, 15, 3.2, 1};
|
||||
float Out[] = {1.9524, 0.0375, 0.1687, 0.4276};
|
||||
for (int i = 0; i < len; i++) {
|
||||
if (Out[i] - erfcxf(Val[i]) > 0.0001) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool check_erfinvf() {
|
||||
uint32_t len = 4;
|
||||
float Val[] = {0, -0.5, 0.9, -0.2};
|
||||
float Out[] = {0, -0.4769, 1.1631, -0.1791};
|
||||
for (int i = 0; i < len; i++) {
|
||||
if (Out[i] - erfinvf(Val[i]) > 0.0001) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool check_fdividef() {
|
||||
uint32_t len = 4;
|
||||
float Val[] = {0, -0.5, 0.9, -0.2};
|
||||
float Out[] = {1, -0.4769, 1.1631, -0.1791};
|
||||
for (int i = 0; i < len; i++) {
|
||||
if (Val[i] / Out[i] - fdividef(Val[i], Out[i]) > 0.0001) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool check_erfcinv() {
|
||||
uint32_t len = 4;
|
||||
double Val[] = {0.1, 1.2, 1, 0.9};
|
||||
double Out[] = {1.16309, -0.179144, 0, 0.0889};
|
||||
for (int i = 0; i < len; i++) {
|
||||
if (Out[i] - erfcinv(Val[i]) > 0.0001) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool check_erfcx() {
|
||||
uint32_t len = 4;
|
||||
double Val[] = {-0.5, 15, 3.2, 1};
|
||||
double Out[] = {1.9524, 0.0375, 0.1687, 0.4276};
|
||||
for (int i = 0; i < len; i++) {
|
||||
if (Out[i] - erfcx(Val[i]) > 0.0001) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool check_erfinv() {
|
||||
uint32_t len = 4;
|
||||
double Val[] = {0, -0.5, 0.9, -0.2};
|
||||
double Out[] = {0, -0.4769, 1.1631, -0.1791};
|
||||
for (int i = 0; i < len; i++) {
|
||||
if (Out[i] - erfinv(Val[i]) > 0.0001) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool check_fdivide() {
|
||||
uint32_t len = 4;
|
||||
double Val[] = {0, -0.5, 0.9, -0.2};
|
||||
double Out[] = {1, -0.4769, 1.1631, -0.1791};
|
||||
for (int i = 0; i < len; i++) {
|
||||
if (Val[i] / Out[i] - fdivide(Val[i], Out[i]) > 0.0001) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool check_modff() {
|
||||
uint32_t len = 4;
|
||||
float Val[] = {0, -0.5, 0.9, -0.2};
|
||||
float iPtr[] = {0, 0, 0, 0};
|
||||
float frac[] = {0, -0.5, 0.9, -0.2};
|
||||
float Out[] = {1, 1, 1, 1};
|
||||
for (int i = 0; i < len; i++) {
|
||||
if (frac[i] - modff(Val[i], Out + i) > 0.0001 && iPtr[i] == Out[i]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool check_modf() {
|
||||
uint32_t len = 4;
|
||||
double Val[] = {0, -0.5, 0.9, -0.2};
|
||||
double iPtr[] = {0, 0, 0, 0};
|
||||
double frac[] = {0, -0.5, 0.9, -0.2};
|
||||
double Out[] = {1, 1, 1, 1};
|
||||
for (int i = 0; i < len; i++) {
|
||||
if (frac[i] - modf(Val[i], Out + i) > 0.0001 && iPtr[i] == Out[i]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool check_nextafterf() {
|
||||
uint32_t len = 4;
|
||||
float Val[] = {0, -0.5, 0.9, -0.2};
|
||||
float iPtr[] = {0, 0, 0, 0};
|
||||
float frac[] = {0, -0.5, 0.9, -0.2};
|
||||
float Out[] = {1, 1, 1, 1};
|
||||
for (int i = 0; i < len; i++) {
|
||||
if (nextafterf(Val[i], 1) - Val[i] > 0.0001) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool check_nextafter() {
|
||||
uint32_t len = 4;
|
||||
double Val[] = {0, -0.5, 0.9, -0.2};
|
||||
double iPtr[] = {0, 0, 0, 0};
|
||||
double frac[] = {0, -0.5, 0.9, -0.2};
|
||||
double Out[] = {1, 1, 1, 1};
|
||||
for (int i = 0; i < len; i++) {
|
||||
if (nextafter(Val[i], 1) - Val[i] > 0.0001) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool check_norm3df(float* A) {
|
||||
float f = norm3df(A[0], A[1], A[2]);
|
||||
float out = sqrt(A[0] * A[0] + A[1] * A[1] + A[2] * A[2]);
|
||||
if (f - out > 0.0001) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool check_norm3d(double* A) {
|
||||
double f = norm3d(A[0], A[1], A[2]);
|
||||
double out = sqrt(A[0] * A[0] + A[1] * A[1] + A[2] * A[2]);
|
||||
if (f - out > 0.0001) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool check_norm4df(float* A) {
|
||||
float f = norm4df(A[0], A[1], A[2], A[3]);
|
||||
float out = sqrt(A[0] * A[0] + A[1] * A[1] + A[2] * A[2] + A[3] * A[3]);
|
||||
if (f - out > 0.0001) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool check_norm4d(double* A) {
|
||||
double f = norm4d(A[0], A[1], A[2], A[3]);
|
||||
double out = sqrt(A[0] * A[0] + A[1] * A[1] + A[2] * A[2] + A[3] * A[3]);
|
||||
if (f - out > 0.0001) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool check_normcdff() {
|
||||
uint32_t len = 2;
|
||||
float Val[] = {0, 1};
|
||||
float Out[] = {0.5, 0.8413};
|
||||
for (int i = 0; i < len; i++) {
|
||||
if (Out[i] - normcdff(Val[i]) > 0.0001) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool check_normcdf() {
|
||||
uint32_t len = 2;
|
||||
float Val[] = {0, 1};
|
||||
float Out[] = {0.5, 0.8413};
|
||||
for (int i = 0; i < len; i++) {
|
||||
if (Out[i] - normcdf(Val[i]) > 0.0001) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool check_normcdfinvf() {
|
||||
uint32_t len = 2;
|
||||
double Val[] = {0.5, 0.8413};
|
||||
for (int i = 0; i < len; i++) {
|
||||
if (Val[i] - normcdfinvf(normcdff(Val[i])) > 0.0001) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool check_normcdfinv() {
|
||||
uint32_t len = 2;
|
||||
double Val[] = {0.5, 0.8413};
|
||||
for (int i = 0; i < len; i++) {
|
||||
if (Val[i] - normcdfinv(normcdf(Val[i])) > 0.0001) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool check_rcbrtf() {
|
||||
float f = 1.0f;
|
||||
if (rcbrtf(f) != 1.0f) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool check_rcbrt() {
|
||||
double f = 1.0;
|
||||
if (rcbrt(f) != 1.0) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool check_rhypotf() {
|
||||
float f = 1.0f;
|
||||
float g = 2.0f;
|
||||
float val = rhypotf(f, g);
|
||||
float sq = f * f + g * g;
|
||||
if (1 / (val * val) - sq > 0.0001) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool check_rhypot() {
|
||||
double f = 1.0f;
|
||||
double g = 2.0f;
|
||||
double val = rhypot(f, g);
|
||||
double sq = f * f + g * g;
|
||||
if (1 / (val * val) - sq > 0.0001) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool check_rnorm3df(float* A) {
|
||||
float f = rnorm3df(A[0], A[1], A[2]);
|
||||
float out = sqrt(A[0] * A[0] + A[1] * A[1] + A[2] * A[2]);
|
||||
if (f - 1 / out > 0.0001) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool check_rnorm3d(double* A) {
|
||||
double f = rnorm3d(A[0], A[1], A[2]);
|
||||
double out = sqrt(A[0] * A[0] + A[1] * A[1] + A[2] * A[2]);
|
||||
if (f - 1 / out > 0.0001) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool check_rnorm4df(float* A) {
|
||||
float f = rnorm4df(A[0], A[1], A[2], A[3]);
|
||||
float out = sqrt(A[0] * A[0] + A[1] * A[1] + A[2] * A[2] + A[3] * A[3]);
|
||||
if (f - 1 / out > 0.0001) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool check_rnorm4d(double* A) {
|
||||
double f = rnorm4d(A[0], A[1], A[2], A[3]);
|
||||
double out = sqrt(A[0] * A[0] + A[1] * A[1] + A[2] * A[2] + A[3] * A[3]);
|
||||
if (f - 1 / out > 0.0001) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool check_rnormf(float* A) {
|
||||
return (rnorm3df(A[0], A[1], A[2]) - rnormf(3, A) < 0.0001) &&
|
||||
(rnorm4df(A[0], A[1], A[2], A[3]) - rnormf(4, A) < 0.0001);
|
||||
}
|
||||
|
||||
bool check_rnorm(double* A) {
|
||||
return (rnorm3d(A[0], A[1], A[2]) - rnorm(3, A) < 0.0001) &&
|
||||
(rnorm4d(A[0], A[1], A[2], A[3]) - rnorm(4, A) < 0.0001);
|
||||
}
|
||||
|
||||
bool check_sincospif() {
|
||||
float s1, c1, s2, c2;
|
||||
float in1 = 1, in2 = 0.5;
|
||||
sincospif(in1, &s1, &c1);
|
||||
sincospif(in2, &s2, &c2);
|
||||
if ((s1 - 0 < 0.00001) && (s2 - 1 < 0.00001) && (c1 + 1 < 0.00001) && (c2 - 0 < 0.00001)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool check_sincospi() {
|
||||
double s1, c1, s2, c2;
|
||||
double in1 = 1, in2 = 0.5;
|
||||
sincospi(in1, &s1, &c1);
|
||||
sincospi(in2, &s2, &c2);
|
||||
if ((s1 - 0 < 0.00001) && (s2 - 1 < 0.00001) && (c1 + 1 < 0.00001) && (c2 - 0 < 0.00001)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
int main() {
|
||||
float* Af = new float[N];
|
||||
double* A = new double[N];
|
||||
for (int i = 0; i < N; i++) {
|
||||
Af[i] = i * 1.0f;
|
||||
A[i] = i * 1.0;
|
||||
}
|
||||
if (check_erfcinvf() && check_erfcxf() && check_erfcinvf() && check_erfcinv() &&
|
||||
check_erfcx() && check_erfcinv() && check_fdividef() && check_fdivide() && check_modff() &&
|
||||
check_modf() && check_nextafterf() && check_norm3df(Af) && check_norm3d(A) &&
|
||||
check_norm4df(Af) && check_norm4d(A) && check_normcdff() && check_normcdf() &&
|
||||
check_normcdfinvf() && check_normcdfinv() && check_rcbrtf() && check_rcbrt() &&
|
||||
check_rhypotf() && check_rhypot() && check_rnorm3df(Af) && check_rnorm3d(A) &&
|
||||
check_rnorm4df(Af) && check_rnorm4d(A) && check_rnormf(Af) && check_rnorm(A) &&
|
||||
check_sincospif() && check_sincospi()) {
|
||||
passed();
|
||||
}
|
||||
}
|
||||
@@ -1,151 +0,0 @@
|
||||
/*
|
||||
Copyright (c) 2015 - 2021 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:
|
||||
|
||||
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.
|
||||
*/
|
||||
|
||||
/* HIT_START
|
||||
* BUILD: %t %s ../test_common.cpp
|
||||
* TEST: %t
|
||||
* HIT_END
|
||||
*/
|
||||
|
||||
// Test include math_functions.h then hip_runtime.h.
|
||||
// Incorrect implementation causes compilation failure due to conflict
|
||||
// declartions.
|
||||
|
||||
#include <new>
|
||||
#include <hip/math_functions.h>
|
||||
|
||||
// Test __HIP_DEVICE_COMPILE__ is defined after math_functions.h
|
||||
// is included.
|
||||
//
|
||||
__device__ __host__ inline void throw_std_bad_alloc()
|
||||
{
|
||||
#ifndef __HIP_DEVICE_COMPILE__
|
||||
throw std::bad_alloc();
|
||||
#else
|
||||
std::size_t huge = static_cast<std::size_t>(-1);
|
||||
new int[huge];
|
||||
#endif
|
||||
}
|
||||
|
||||
#include <hip/hip_runtime.h>
|
||||
#include "test_common.h"
|
||||
|
||||
__global__ void FloatMathPrecise() {
|
||||
int iX;
|
||||
float fX, fY;
|
||||
|
||||
acosf(1.0f);
|
||||
acoshf(1.0f);
|
||||
asinf(0.0f);
|
||||
asinhf(0.0f);
|
||||
atan2f(0.0f, 1.0f);
|
||||
atanf(0.0f);
|
||||
atanhf(0.0f);
|
||||
cbrtf(0.0f);
|
||||
fX = ceilf(0.0f);
|
||||
fX = copysignf(1.0f, -2.0f);
|
||||
cosf(0.0f);
|
||||
coshf(0.0f);
|
||||
cospif(0.0f);
|
||||
cyl_bessel_i0f(0.0f);
|
||||
cyl_bessel_i1f(0.0f);
|
||||
erfcf(0.0f);
|
||||
erfcinvf(2.0f);
|
||||
erfcxf(0.0f);
|
||||
erff(0.0f);
|
||||
erfinvf(1.0f);
|
||||
exp10f(0.0f);
|
||||
exp2f(0.0f);
|
||||
expf(0.0f);
|
||||
expm1f(0.0f);
|
||||
fX = fabsf(1.0f);
|
||||
fdimf(1.0f, 0.0f);
|
||||
fdividef(0.0f, 1.0f);
|
||||
fX = floorf(0.0f);
|
||||
fmaf(1.0f, 2.0f, 3.0f);
|
||||
fX = fmaxf(0.0f, 0.0f);
|
||||
fX = fminf(0.0f, 0.0f);
|
||||
fmodf(0.0f, 1.0f);
|
||||
frexpf(0.0f, &iX);
|
||||
hypotf(1.0f, 0.0f);
|
||||
ilogbf(1.0f);
|
||||
isfinite(0.0f);
|
||||
fX = isinf(0.0f);
|
||||
fX = isnan(0.0f);
|
||||
j0f(0.0f);
|
||||
j1f(0.0f);
|
||||
jnf(-1.0f, 1.0f);
|
||||
ldexpf(0.0f, 0);
|
||||
lgammaf(1.0f);
|
||||
llrintf(0.0f);
|
||||
llroundf(0.0f);
|
||||
log10f(1.0f);
|
||||
log1pf(-1.0f);
|
||||
log2f(1.0f);
|
||||
logbf(1.0f);
|
||||
logf(1.0f);
|
||||
lrintf(0.0f);
|
||||
lroundf(0.0f);
|
||||
modff(0.0f, &fX);
|
||||
fX = nanf("1");
|
||||
fX = nearbyintf(0.0f);
|
||||
nextafterf(0.0f, 0.0f);
|
||||
norm3df(1.0f, 0.0f, 0.0f);
|
||||
norm4df(1.0f, 0.0f, 0.0f, 0.0f);
|
||||
normcdff(0.0f);
|
||||
normcdfinvf(1.0f);
|
||||
fX = 1.0f;
|
||||
normf(1, &fX);
|
||||
powf(1.0f, 0.0f);
|
||||
rcbrtf(1.0f);
|
||||
remainderf(2.0f, 1.0f);
|
||||
remquof(1.0f, 2.0f, &iX);
|
||||
rhypotf(0.0f, 1.0f);
|
||||
fY = rintf(1.0f);
|
||||
rnorm3df(0.0f, 0.0f, 1.0f);
|
||||
rnorm4df(0.0f, 0.0f, 0.0f, 1.0f);
|
||||
fX = 1.0f;
|
||||
rnormf(1, &fX);
|
||||
fY = roundf(0.0f);
|
||||
rsqrtf(1.0f);
|
||||
scalblnf(0.0f, 1);
|
||||
scalbnf(0.0f, 1);
|
||||
signbit(1.0f);
|
||||
sincosf(0.0f, &fX, &fY);
|
||||
sincospif(0.0f, &fX, &fY);
|
||||
sinf(0.0f);
|
||||
sinhf(0.0f);
|
||||
sinpif(0.0f);
|
||||
sqrtf(0.0f);
|
||||
tanf(0.0f);
|
||||
tanhf(0.0f);
|
||||
tgammaf(2.0f);
|
||||
fY = truncf(0.0f);
|
||||
y0f(1.0f);
|
||||
y1f(1.0f);
|
||||
ynf(1, 1.0f);
|
||||
}
|
||||
|
||||
int main() {
|
||||
hipLaunchKernelGGL(FloatMathPrecise, dim3(1, 1, 1), dim3(1, 1, 1), 0, 0);
|
||||
passed();
|
||||
}
|
||||
@@ -1,188 +0,0 @@
|
||||
/*
|
||||
Copyright (c) 2015 - 2021 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:
|
||||
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.
|
||||
*/
|
||||
|
||||
/* HIT_START
|
||||
* BUILD: %t %s ../test_common.cpp EXCLUDE_HIP_PLATFORM nvidia
|
||||
* TEST: %t
|
||||
* HIT_END
|
||||
*/
|
||||
|
||||
#include <hip/hip_fp16.h>
|
||||
#include "hip/hip_runtime.h"
|
||||
|
||||
#include "test_common.h"
|
||||
|
||||
#include <type_traits>
|
||||
|
||||
using namespace std;
|
||||
|
||||
__global__
|
||||
void __halfTest(bool* result, __half a) {
|
||||
// Construction
|
||||
static_assert(is_default_constructible<__half>{}, "");
|
||||
static_assert(is_copy_constructible<__half>{}, "");
|
||||
static_assert(is_move_constructible<__half>{}, "");
|
||||
static_assert(is_constructible<__half, float>{}, "");
|
||||
static_assert(is_constructible<__half, double>{}, "");
|
||||
static_assert(is_constructible<__half, unsigned short>{}, "");
|
||||
static_assert(is_constructible<__half, short>{}, "");
|
||||
static_assert(is_constructible<__half, unsigned int>{}, "");
|
||||
static_assert(is_constructible<__half, int>{}, "");
|
||||
static_assert(is_constructible<__half, unsigned long>{}, "");
|
||||
static_assert(is_constructible<__half, long>{}, "");
|
||||
static_assert(is_constructible<__half, long long>{}, "");
|
||||
static_assert(is_constructible<__half, unsigned long long>{}, "");
|
||||
static_assert(is_constructible<__half, __half_raw>{}, "");
|
||||
|
||||
// Assignment
|
||||
static_assert(is_copy_assignable<__half>{}, "");
|
||||
static_assert(is_move_assignable<__half>{}, "");
|
||||
static_assert(is_assignable<__half, float>{}, "");
|
||||
static_assert(is_assignable<__half, double>{}, "");
|
||||
static_assert(is_assignable<__half, unsigned short>{}, "");
|
||||
static_assert(is_assignable<__half, short>{}, "");
|
||||
static_assert(is_assignable<__half, unsigned int>{}, "");
|
||||
static_assert(is_assignable<__half, int>{}, "");
|
||||
static_assert(is_assignable<__half, unsigned long>{}, "");
|
||||
static_assert(is_assignable<__half, long>{}, "");
|
||||
static_assert(is_assignable<__half, long long>{}, "");
|
||||
static_assert(is_assignable<__half, unsigned long long>{}, "");
|
||||
static_assert(is_assignable<__half, __half_raw>{}, "");
|
||||
static_assert(is_assignable<__half, volatile __half_raw&>{}, "");
|
||||
static_assert(is_assignable<__half, volatile __half_raw&&>{}, "");
|
||||
|
||||
// Conversion
|
||||
static_assert(is_convertible<__half, float>{}, "");
|
||||
static_assert(is_convertible<__half, unsigned short>{}, "");
|
||||
static_assert(is_convertible<__half, short>{}, "");
|
||||
static_assert(is_convertible<__half, unsigned int>{}, "");
|
||||
static_assert(is_convertible<__half, int>{}, "");
|
||||
static_assert(is_convertible<__half, unsigned long>{}, "");
|
||||
static_assert(is_convertible<__half, long>{}, "");
|
||||
static_assert(is_convertible<__half, long long>{}, "");
|
||||
static_assert(is_convertible<__half, bool>{}, "");
|
||||
static_assert(is_convertible<__half, unsigned long long>{}, "");
|
||||
static_assert(is_convertible<__half, __half_raw>{}, "");
|
||||
static_assert(is_convertible<__half, volatile __half_raw>{}, "");
|
||||
|
||||
// Nullary
|
||||
result[0] = __heq(a, +a) && result[0];
|
||||
result[0] = __heq(__hneg(a), -a) && result[0];
|
||||
|
||||
// Unary arithmetic
|
||||
result[0] = __heq(a += 0, a) && result[0];
|
||||
result[0] = __heq(a -= 0, a) && result[0];
|
||||
result[0] = __heq(a *= 1, a) && result[0];
|
||||
result[0] = __heq(a /= 1, a) && result[0];
|
||||
|
||||
// Binary arithmetic
|
||||
result[0] = __heq((a + a), __hadd(a, a)) && result[0];
|
||||
result[0] = __heq((a - a), __hsub(a, a)) && result[0];
|
||||
result[0] = __heq((a * a), __hmul(a, a)) && result[0];
|
||||
result[0] = __heq((a / a), __hdiv(a, a)) && result[0];
|
||||
|
||||
// Relations
|
||||
result[0] = (a == a) && result[0];
|
||||
result[0] = !(a != a) && result[0];
|
||||
result[0] = (a <= a) && result[0];
|
||||
result[0] = (a >= a) && result[0];
|
||||
result[0] = !(a < a) && result[0];
|
||||
result[0] = !(a > a) && result[0];
|
||||
}
|
||||
|
||||
__device__
|
||||
bool to_bool(const __half2& x)
|
||||
{
|
||||
auto r = static_cast<const __half2_raw&>(x);
|
||||
|
||||
return r.data.x != 0 && r.data.y != 0;
|
||||
}
|
||||
|
||||
__global__
|
||||
void __half2Test(bool* result, __half2 a) {
|
||||
// Construction
|
||||
static_assert(is_default_constructible<__half2>{}, "");
|
||||
static_assert(is_copy_constructible<__half2>{}, "");
|
||||
static_assert(is_move_constructible<__half2>{}, "");
|
||||
static_assert(is_constructible<__half2, __half, __half>{}, "");
|
||||
static_assert(is_constructible<__half2, __half2_raw>{}, "");
|
||||
|
||||
// Assignment
|
||||
static_assert(is_copy_assignable<__half2>{}, "");
|
||||
static_assert(is_move_assignable<__half2>{}, "");
|
||||
static_assert(is_assignable<__half2, __half2_raw>{}, "");
|
||||
|
||||
// Conversion
|
||||
static_assert(is_convertible<__half2, __half2_raw>{}, "");
|
||||
|
||||
// Nullary
|
||||
result[0] = to_bool(__heq2(a, +a)) && result[0];
|
||||
result[0] = to_bool(__heq2(__hneg2(a), -a)) && result[0];
|
||||
|
||||
// Unary arithmetic
|
||||
result[0] = to_bool(__heq2(a += 0, a)) && result[0];
|
||||
result[0] = to_bool(__heq2(a -= 0, a)) && result[0];
|
||||
result[0] = to_bool(__heq2(a *= 1, a)) && result[0];
|
||||
result[0] = to_bool(__heq2(a /= 1, a)) && result[0];
|
||||
|
||||
// Binary arithmetic
|
||||
result[0] = to_bool(__heq2((a + a), __hadd2(a, a))) && result[0];
|
||||
result[0] = to_bool(__heq2((a - a), __hsub2(a, a))) && result[0];
|
||||
result[0] = to_bool(__heq2((a * a), __hmul2(a, a))) && result[0];
|
||||
result[0] = to_bool(__heq2((a / a), __h2div(a, a))) && result[0];
|
||||
|
||||
// Relations
|
||||
result[0] = (a == a) && result[0];
|
||||
result[0] = !(a != a) && result[0];
|
||||
result[0] = (a <= a) && result[0];
|
||||
result[0] = (a >= a) && result[0];
|
||||
result[0] = !(a < a) && result[0];
|
||||
result[0] = !(a > a) && result[0];
|
||||
|
||||
#if __HIP_CLANG_ONLY__
|
||||
// Dot Functions
|
||||
result[0] = amd_mixed_dot(a, a, 1, 1) && result[0];
|
||||
#endif
|
||||
|
||||
half X = a.x;
|
||||
half Y = a.y;
|
||||
}
|
||||
|
||||
int main() {
|
||||
bool* result{nullptr};
|
||||
hipHostMalloc(&result, 1);
|
||||
|
||||
result[0] = true;
|
||||
hipLaunchKernelGGL(
|
||||
__halfTest, dim3(1, 1, 1), dim3(1, 1, 1), 0, 0, result, __half{1});
|
||||
hipDeviceSynchronize();
|
||||
|
||||
if (!result[0]) { failed("Failed __half tests."); }
|
||||
|
||||
result[0] = true;
|
||||
hipLaunchKernelGGL(
|
||||
__half2Test, dim3(1, 1, 1), dim3(1, 1, 1), 0, 0, result, __half2{1, 1});
|
||||
hipDeviceSynchronize();
|
||||
|
||||
if (!result[0]) { failed("Failed __half2 tests."); }
|
||||
|
||||
hipHostFree(result);
|
||||
|
||||
passed();
|
||||
}
|
||||
@@ -1,69 +0,0 @@
|
||||
/*
|
||||
Copyright (c) 2015 - 2021 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:
|
||||
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.
|
||||
*/
|
||||
|
||||
/* HIT_START
|
||||
* BUILD: %t %s ../test_common.cpp
|
||||
* TEST: %t
|
||||
* HIT_END
|
||||
*/
|
||||
|
||||
#include <hip/hip_runtime.h>
|
||||
#include <hip/hip_runtime_api.h>
|
||||
#include <iostream>
|
||||
#include "test_common.h"
|
||||
|
||||
#define HIP_ASSERT(status) assert(status == hipSuccess)
|
||||
|
||||
#define LEN 512
|
||||
#define SIZE 2048
|
||||
|
||||
class A {
|
||||
public:
|
||||
__device__ A() {
|
||||
a = threadIdx.x + blockIdx.x * blockDim.x;
|
||||
}
|
||||
private:
|
||||
int a;
|
||||
};
|
||||
|
||||
static __global__ void kernel(int* Ad) {
|
||||
int tid = threadIdx.x + blockIdx.x * blockDim.x;
|
||||
new(Ad+tid) A();
|
||||
}
|
||||
|
||||
void run() {
|
||||
int *A, *Ad;
|
||||
A = new int[LEN];
|
||||
for (unsigned i = 0; i < LEN; i++) {
|
||||
A[i] = 0;
|
||||
}
|
||||
|
||||
HIP_ASSERT(hipMalloc((void**)&Ad, SIZE));
|
||||
hipLaunchKernelGGL(kernel, dim3(1, 1, 1), dim3(LEN, 1, 1), 0, 0, Ad);
|
||||
HIP_ASSERT(hipMemcpy(A, Ad, SIZE, hipMemcpyDeviceToHost));
|
||||
|
||||
for (unsigned i = 0; i < LEN; i++) {
|
||||
assert(i == A[i]);
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
run();
|
||||
passed();
|
||||
}
|
||||
@@ -1,73 +0,0 @@
|
||||
/*
|
||||
Copyright (c) 2015 - 2021 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:
|
||||
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.
|
||||
*/
|
||||
|
||||
/* HIT_START
|
||||
* BUILD: %t %s ../test_common.cpp
|
||||
* TEST: %t
|
||||
* HIT_END
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
#include <hip/hip_runtime_api.h>
|
||||
#include <hip/hip_runtime.h>
|
||||
#include "test_common.h"
|
||||
|
||||
#define NUM 1024
|
||||
#define SIZE NUM * sizeof(float)
|
||||
|
||||
__global__ void vAdd(float* In1, float* In2, float* In3, float* In4, float* Out) {
|
||||
int tid = threadIdx.x + blockIdx.x * blockDim.x;
|
||||
In4[tid] = In1[tid] + In2[tid];
|
||||
__threadfence();
|
||||
In3[tid] = In3[tid] + In4[tid];
|
||||
__threadfence_block();
|
||||
Out[tid] = In4[tid] + In3[tid];
|
||||
}
|
||||
|
||||
int main() {
|
||||
float* In1 = new float[1024];
|
||||
float* In2 = new float[1024];
|
||||
float* In3 = new float[1024];
|
||||
float* In4 = new float[1024];
|
||||
float* Out = new float[1024];
|
||||
|
||||
for (uint32_t i = 0; i < 1024; i++) {
|
||||
In1[i] = 1.0f;
|
||||
In2[i] = 1.0f;
|
||||
In3[i] = 1.0f;
|
||||
In4[i] = 1.0f;
|
||||
}
|
||||
|
||||
float *In1d, *In2d, *In3d, *In4d, *Outd;
|
||||
hipMalloc((void**)&In1d, SIZE);
|
||||
hipMalloc((void**)&In2d, SIZE);
|
||||
hipMalloc((void**)&In3d, SIZE);
|
||||
hipMalloc((void**)&In4d, SIZE);
|
||||
hipMalloc((void**)&Outd, SIZE);
|
||||
|
||||
hipMemcpy(In1d, In1, SIZE, hipMemcpyHostToDevice);
|
||||
hipMemcpy(In2d, In2, SIZE, hipMemcpyHostToDevice);
|
||||
hipMemcpy(In3d, In3, SIZE, hipMemcpyHostToDevice);
|
||||
hipMemcpy(In4d, In4, SIZE, hipMemcpyHostToDevice);
|
||||
|
||||
hipLaunchKernelGGL(vAdd, dim3(32, 1, 1), dim3(32, 1, 1), 0, 0, In1d, In2d, In3d, In4d, Outd);
|
||||
hipMemcpy(Out, Outd, SIZE, hipMemcpyDeviceToHost);
|
||||
assert(Out[10] == 2 * In1[10] + 2 * In2[10] + In3[10]);
|
||||
passed();
|
||||
}
|
||||
@@ -1,227 +0,0 @@
|
||||
/*
|
||||
Copyright (c) 2015 - 2021 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:
|
||||
|
||||
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.
|
||||
*/
|
||||
|
||||
/* HIT_START
|
||||
* BUILD: %t %s ../test_common.cpp EXCLUDE_HIP_PLATFORM nvidia amd
|
||||
* TEST: %t
|
||||
* HIT_END
|
||||
*/
|
||||
|
||||
#include <hip/hip_vector_types.h>
|
||||
|
||||
#include "vector_test_common.h"
|
||||
#include "test_common.h"
|
||||
|
||||
#include <assert.h>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include <type_traits>
|
||||
|
||||
using namespace std;
|
||||
|
||||
template<
|
||||
typename V,
|
||||
Enable_if_t<!is_integral<decltype(declval<V>().x)>{}>* = nullptr>
|
||||
bool integer_unary_tests(V&, V&) {
|
||||
return true;
|
||||
}
|
||||
|
||||
template<
|
||||
typename V,
|
||||
Enable_if_t<!is_integral<decltype(declval<V>().x)>{}>* = nullptr>
|
||||
bool integer_binary_tests(V&, V&, V&...) {
|
||||
return true;
|
||||
}
|
||||
|
||||
template<
|
||||
typename V,
|
||||
Enable_if_t<is_integral<decltype(declval<V>().x)>{}>* = nullptr>
|
||||
bool integer_unary_tests(V& f1, V& f2) {
|
||||
f1 %= f2;
|
||||
if (f1 != V{0}) return false;
|
||||
f1 &= f2;
|
||||
if (f1 != V{0}) return false;
|
||||
f1 |= f2;
|
||||
if (f1 != V{1}) return false;
|
||||
f1 ^= f2;
|
||||
if (f1 != V{0}) return false;
|
||||
f1 = V{1};
|
||||
f1 <<= f2;
|
||||
if (f1 != V{2}) return false;
|
||||
f1 >>= f2;
|
||||
if (f1 != V{1}) return false;
|
||||
f2 = ~f1;
|
||||
return f2 == V{~1};
|
||||
}
|
||||
|
||||
template<
|
||||
typename V,
|
||||
Enable_if_t<is_integral<decltype(declval<V>().x)>{}>* = nullptr>
|
||||
bool integer_binary_tests(V& f1, V& f2, V& f3) {
|
||||
f3 = f1 % f2;
|
||||
if (f3 != V{0}) return false;
|
||||
f1 = f3 & f2;
|
||||
if (f1 != V{0}) return false;
|
||||
f2 = f1 ^ f3;
|
||||
if (f2 != V{0}) return false;
|
||||
f1 = V{1};
|
||||
f2 = V{2};
|
||||
f3 = f1 << f2;
|
||||
if (f3 != V{4}) return false;
|
||||
f2 = f3 >> f1;
|
||||
return f2 == V{2};
|
||||
}
|
||||
|
||||
template<typename V>
|
||||
bool constructor_tests() {
|
||||
static_assert(is_constructible<V, unsigned char>{}, "");
|
||||
static_assert(is_constructible<V, signed char>{}, "");
|
||||
static_assert(is_constructible<V, unsigned short>{}, "");
|
||||
static_assert(is_constructible<V, signed short>{}, "");
|
||||
static_assert(is_constructible<V, unsigned int>{}, "");
|
||||
static_assert(is_constructible<V, signed int>{}, "");
|
||||
static_assert(is_constructible<V, unsigned long>{}, "");
|
||||
static_assert(is_constructible<V, signed long>{}, "");
|
||||
static_assert(is_constructible<V, unsigned long long>{}, "");
|
||||
static_assert(is_constructible<V, signed long long>{}, "");
|
||||
static_assert(is_constructible<V, float>{}, "");
|
||||
static_assert(is_constructible<V, double>{}, "");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
template<typename V>
|
||||
bool TestVectorType() {
|
||||
constexpr V v1{1};
|
||||
constexpr V v2{2};
|
||||
constexpr V v3{3};
|
||||
constexpr V v4{4};
|
||||
|
||||
V f1{1};
|
||||
V f2{1};
|
||||
V f3 = f1 + f2;
|
||||
if (f3 != v2) return false;
|
||||
f2 = f3 - f1;
|
||||
if (f2 != v1) return false;
|
||||
f1 = f2 * f3;
|
||||
if (f1 != v2) return false;
|
||||
f2 = f1 / f3;
|
||||
if (f2 != v1) return false;
|
||||
if (!integer_binary_tests(f1, f2, f3)) return false;
|
||||
|
||||
f1 = V{2};
|
||||
f2 = V{1};
|
||||
f1 += f2;
|
||||
if (f1 != v3) return false;
|
||||
f1 -= f2;
|
||||
if (f1 != v2) return false;
|
||||
f1 *= f2;
|
||||
if (f1 != v2) return false;
|
||||
f1 /= f2;
|
||||
if (f1 != v2) return false;
|
||||
if (!integer_unary_tests(f1, f2)) return false;
|
||||
|
||||
f1 = v2;
|
||||
f2 = f1++;
|
||||
if (f1 != v3) return false;
|
||||
if (f2 != v2) return false;
|
||||
f2 = f1--;
|
||||
if (f2 != v3) return false;
|
||||
if (f1 != v2) return false;
|
||||
f2 = ++f1;
|
||||
if (f1 != v3) return false;
|
||||
if (f2 != v3) return false;
|
||||
f2 = --f1;
|
||||
if (f1 != v2) return false;
|
||||
if (f2 != v2) return false;
|
||||
|
||||
if (!constructor_tests<V>()) return false;
|
||||
|
||||
f1 = v3;
|
||||
f2 = v4;
|
||||
f3 = v3;
|
||||
if (f1 == f2) return false;
|
||||
if (!(f1 != f2)) return false;
|
||||
|
||||
using T = typename V::value_type;
|
||||
|
||||
const T& x = f1.x;
|
||||
T& y = f2.x;
|
||||
const volatile T& z = f3.x;
|
||||
volatile T& w = f2.x;
|
||||
|
||||
if (x != T{3}) return false;
|
||||
if (y != T{4}) return false;
|
||||
if (z != T{3}) return false;
|
||||
if (w != T{4}) return false;
|
||||
|
||||
stringstream str;
|
||||
str << f1.x;
|
||||
str >> f2.x;
|
||||
|
||||
if (f1.x != f2.x) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
template<typename... Ts, Enable_if_t<sizeof...(Ts) == 0>* = nullptr>
|
||||
bool TestVectorTypes() {
|
||||
return true;
|
||||
}
|
||||
|
||||
template<typename T, typename... Ts>
|
||||
bool TestVectorTypes() {
|
||||
if (!TestVectorType<T>()) return false;
|
||||
return TestVectorTypes<Ts...>();
|
||||
}
|
||||
|
||||
bool CheckVectorTypes() {
|
||||
return TestVectorTypes<
|
||||
char1, char2, char3, char4,
|
||||
uchar1, uchar2, uchar3, uchar4,
|
||||
short1, short2, short3, short4,
|
||||
ushort1, ushort2, ushort3, ushort4,
|
||||
int1, int2, int3, int4,
|
||||
uint1, uint2, uint3, uint4,
|
||||
long1, long2, long3, long4,
|
||||
ulong1, ulong2, ulong3, ulong4,
|
||||
longlong1, longlong2, longlong3, longlong4,
|
||||
ulonglong1, ulonglong2, ulonglong3, ulonglong4,
|
||||
float1, float2, float3, float4,
|
||||
double1, double2, double3, double4>();
|
||||
}
|
||||
|
||||
int main() {
|
||||
static_assert(sizeof(float1) == 4, "");
|
||||
static_assert(sizeof(float2) >= 8, "");
|
||||
static_assert(sizeof(float3) == 12, "");
|
||||
static_assert(sizeof(float4) >= 16, "");
|
||||
|
||||
if (CheckVectorTypes()) {
|
||||
float1 f1 = make_float1(1.0f);
|
||||
passed();
|
||||
}
|
||||
else {
|
||||
failed("Failed some vector test on the host side.");
|
||||
}
|
||||
}
|
||||
@@ -1,319 +0,0 @@
|
||||
/*
|
||||
Copyright (c) 2015 - 2021 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:
|
||||
|
||||
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.
|
||||
*/
|
||||
|
||||
/* HIT_START
|
||||
* BUILD: %t %s ../test_common.cpp EXCLUDE_HIP_PLATFORM nvidia amd
|
||||
* TEST: %t
|
||||
* HIT_END
|
||||
*/
|
||||
|
||||
#include <hip/hip_vector_types.h>
|
||||
|
||||
#include "test_common.h"
|
||||
|
||||
#include <memory>
|
||||
#include <type_traits>
|
||||
#include <utility>
|
||||
|
||||
using namespace std;
|
||||
|
||||
template <class T> __device__
|
||||
typename std::add_rvalue_reference<T>::type _declval() noexcept;
|
||||
|
||||
template<
|
||||
typename V,
|
||||
Enable_if_t<!is_integral<decltype(_declval<V>().x)>{}>* = nullptr>
|
||||
__device__
|
||||
constexpr
|
||||
bool integer_unary_tests(const V&, const V&) {
|
||||
return true;
|
||||
}
|
||||
|
||||
template<
|
||||
typename V,
|
||||
Enable_if_t<is_integral<decltype(_declval<V>().x)>{}>* = nullptr>
|
||||
__device__
|
||||
bool integer_unary_tests(V& f1, V& f2) {
|
||||
f1 %= f2;
|
||||
if (f1 != V{0}) return false;
|
||||
|
||||
f1 &= f2;
|
||||
if (f1 != V{0}) return false;
|
||||
f1 |= f2;
|
||||
if (f1 != V{1}) return false;
|
||||
f1 ^= f2;
|
||||
if (f1 != V{0}) return false;
|
||||
f1 = V{1};
|
||||
f1 <<= f2;
|
||||
if (f1 != V{2}) return false;
|
||||
f1 >>= f2;
|
||||
if (f1 != V{1}) return false;
|
||||
f2 = ~f1;
|
||||
return f2 == V{~1};
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
template<
|
||||
typename V,
|
||||
Enable_if_t<!is_integral<decltype(_declval<V>().x)>{}>* = nullptr>
|
||||
__device__
|
||||
constexpr
|
||||
bool integer_binary_tests(const V&, const V&, const V&) {
|
||||
return true;
|
||||
}
|
||||
|
||||
template<
|
||||
typename V,
|
||||
Enable_if_t<is_integral<decltype(_declval<V>().x)>{}>* = nullptr>
|
||||
__device__
|
||||
bool integer_binary_tests(V& f1, V& f2, V& f3) {
|
||||
f3 = f1 % f2;
|
||||
if (f3 != V{0}) return false;
|
||||
f1 = f3 & f2;
|
||||
if (f1 != V{0}) return false;
|
||||
f2 = f1 ^ f3;
|
||||
if (f2 != V{0}) return false;
|
||||
f1 = V{1};
|
||||
f2 = V{2};
|
||||
f3 = f1 << f2;
|
||||
if (f3 != V{4}) return false;
|
||||
f2 = f3 >> f1;
|
||||
return f2 == V{2};
|
||||
}
|
||||
|
||||
template<typename V>
|
||||
__device__
|
||||
bool TestVectorType() {
|
||||
constexpr V v1{1};
|
||||
constexpr V v2{2};
|
||||
constexpr V v3{3};
|
||||
constexpr V v4{4};
|
||||
|
||||
V f1{1};
|
||||
V f2{1};
|
||||
V f3 = f1 + f2;
|
||||
if (f3 != V{2}) return false;
|
||||
f2 = f3 - f1;
|
||||
if (f2 != V{1}) return false;
|
||||
f1 = f2 * f3;
|
||||
if (f1 != V{2}) return false;
|
||||
f2 = f1 / f3;
|
||||
if (f2 != V{1}) return false;
|
||||
if (!integer_binary_tests(f1, f2, f3)) return false;
|
||||
|
||||
f1 = v2;
|
||||
f2 = v1;
|
||||
f1 += f2;
|
||||
if (f1 != v3) return false;
|
||||
f1 -= f2;
|
||||
if (f1 != v2) return false;
|
||||
f1 *= f2;
|
||||
if (f1 != v2) return false;
|
||||
f1 /= f2;
|
||||
if (f1 != v2) return false;
|
||||
if (!integer_unary_tests(f1, f2)) return false;
|
||||
|
||||
f1 = v2;
|
||||
f2 = f1++;
|
||||
if (f1 != v3) return false;
|
||||
if (f2 != v2) return false;
|
||||
f2 = f1--;
|
||||
if (f2 != v3) return false;
|
||||
if (f1 != v2) return false;
|
||||
f2 = ++f1;
|
||||
if (f1 != v3) return false;
|
||||
if (f2 != v3) return false;
|
||||
f2 = --f1;
|
||||
if (f1 != v2) return false;
|
||||
if (f2 != v2) return false;
|
||||
|
||||
f1 = v3;
|
||||
f2 = v4;
|
||||
f3 = v3;
|
||||
if (f1 == f2) return false;
|
||||
if (!(f1 != f2)) return false;
|
||||
|
||||
#if 0 // TODO: investigate on GFX8
|
||||
using T = typename V::value_type;
|
||||
|
||||
const T& x = f1.x;
|
||||
T& y = f2.x;
|
||||
const volatile T& z = f3.x;
|
||||
volatile T& w = f2.x;
|
||||
|
||||
if (x != T{3}) return false;
|
||||
if (y != T{4}) return false;
|
||||
if (z != T{3}) return false;
|
||||
if (w != T{4}) return false;
|
||||
#endif
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
template<typename... Ts, Enable_if_t<sizeof...(Ts) == 0>* = nullptr>
|
||||
__device__
|
||||
bool TestVectorTypes() {
|
||||
return true;
|
||||
}
|
||||
|
||||
template<typename T, typename... Ts>
|
||||
__device__
|
||||
bool TestVectorTypes() {
|
||||
if (!TestVectorType<T>()) return false;
|
||||
return TestVectorTypes<Ts...>();
|
||||
}
|
||||
|
||||
__global__
|
||||
void CheckVectorTypes(bool* ptr) {
|
||||
ptr[0] = TestVectorTypes<
|
||||
char1, char2, char3, char4,
|
||||
uchar1, uchar2, uchar3, uchar4,
|
||||
short1, short2, short3, short4,
|
||||
ushort1, ushort2, ushort3, ushort4,
|
||||
int1, int2, int3, int4,
|
||||
uint1, uint2, uint3, uint4,
|
||||
long1, long2, long3, long4,
|
||||
ulong1, ulong2, ulong3, ulong4,
|
||||
longlong1, longlong2, longlong3, longlong4,
|
||||
ulonglong1, ulonglong2, ulonglong3, ulonglong4,
|
||||
float1, float2, float3, float4,
|
||||
double1, double2, double3, double4>();
|
||||
}
|
||||
|
||||
|
||||
template<typename V>
|
||||
__global__
|
||||
void CheckSharedVectorType(bool* ptr) {
|
||||
constexpr V v1{1};
|
||||
constexpr V v2{2};
|
||||
constexpr V v3{3};
|
||||
constexpr V v4{4};
|
||||
__shared__ V f1, f2, f3;
|
||||
|
||||
*ptr = true;
|
||||
f1 = V{1};
|
||||
f2 = V{1};
|
||||
f3 = f1 + f2;
|
||||
*ptr = *ptr && f3 == V{2};
|
||||
f2 = f3 - f1;
|
||||
*ptr = *ptr && f2 == V{1};
|
||||
f1 = f2 * f3;
|
||||
*ptr = *ptr && f1 == V{2};
|
||||
f2 = f1 / f3;
|
||||
*ptr = *ptr && f2 == V{1};
|
||||
*ptr = *ptr && integer_binary_tests(f1, f2, f3);
|
||||
|
||||
f1 = v2;
|
||||
f2 = v1;
|
||||
f1 += f2;
|
||||
*ptr = *ptr && f1 == v3;
|
||||
f1 -= f2;
|
||||
*ptr = *ptr && f1 == v2;
|
||||
f1 *= f2;
|
||||
*ptr = *ptr && f1 == v2;
|
||||
f1 /= f2;
|
||||
*ptr = *ptr && f1 == v2;
|
||||
*ptr = *ptr && integer_unary_tests(f1, f2);
|
||||
|
||||
f1 = v2;
|
||||
f2 = f1++;
|
||||
*ptr = *ptr && f1 == v3;
|
||||
*ptr = *ptr && f2 == v2;
|
||||
f2 = f1--;
|
||||
*ptr = *ptr && f2 == v3;
|
||||
*ptr = *ptr && f1 == v2;
|
||||
f2 = ++f1;
|
||||
*ptr = *ptr && f1 == v3;
|
||||
*ptr = *ptr && f2 == v3;
|
||||
f2 = --f1;
|
||||
*ptr = *ptr && f1 == v2;
|
||||
*ptr = *ptr && f2 == v2;
|
||||
|
||||
f1 = v3;
|
||||
f2 = v4;
|
||||
f3 = v3;
|
||||
*ptr = *ptr && f1 != f2;
|
||||
}
|
||||
|
||||
template <typename V>
|
||||
bool run_CheckSharedVectorType() {
|
||||
bool* ptr = nullptr;
|
||||
if (hipMalloc(&ptr, sizeof(bool)) != HIP_SUCCESS) return false;
|
||||
unique_ptr<bool, decltype(hipFree)*> correct{ptr, hipFree};
|
||||
hipLaunchKernelGGL(
|
||||
(CheckSharedVectorType<V>), dim3(1, 1, 1), dim3(1, 1, 1), 0, 0, correct.get());
|
||||
bool passed = true;
|
||||
if (hipMemcpyDtoH(&passed, correct.get(), sizeof(bool)) != HIP_SUCCESS) {
|
||||
return false;
|
||||
}
|
||||
return passed;
|
||||
}
|
||||
|
||||
template<typename... Ts, Enable_if_t<sizeof...(Ts) == 0>* = nullptr>
|
||||
bool run_CheckSharedVectorTypes() {
|
||||
return true;
|
||||
}
|
||||
|
||||
template <typename V, typename... Vs>
|
||||
bool run_CheckSharedVectorTypes() {
|
||||
return run_CheckSharedVectorType<V>() &&
|
||||
run_CheckSharedVectorTypes<Vs...>();
|
||||
}
|
||||
|
||||
int main() {
|
||||
static_assert(sizeof(float1) == 4, "");
|
||||
static_assert(sizeof(float2) >= 8, "");
|
||||
static_assert(sizeof(float3) >= 12, "");
|
||||
static_assert(sizeof(float4) >= 16, "");
|
||||
|
||||
bool* ptr = nullptr;
|
||||
if (hipMalloc(&ptr, sizeof(bool)) != HIP_SUCCESS) return EXIT_FAILURE;
|
||||
unique_ptr<bool, decltype(hipFree)*> correct{ptr, hipFree};
|
||||
hipLaunchKernelGGL(
|
||||
CheckVectorTypes, dim3(1, 1, 1), dim3(1, 1, 1), 0, 0, correct.get());
|
||||
bool passed = true;
|
||||
if (hipMemcpyDtoH(&passed, correct.get(), sizeof(bool)) != HIP_SUCCESS) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
passed = passed && run_CheckSharedVectorTypes<
|
||||
char1, char2, char3, char4,
|
||||
uchar1, uchar2, uchar3, uchar4,
|
||||
short1, short2, short3, short4,
|
||||
ushort1, ushort2, ushort3, ushort4,
|
||||
int1, int2, int3, int4,
|
||||
uint1, uint2, uint3, uint4,
|
||||
long1, long2, long3, long4,
|
||||
ulong1, ulong2, ulong3, ulong4,
|
||||
longlong1, longlong2, longlong3, longlong4,
|
||||
ulonglong1, ulonglong2, ulonglong3, ulonglong4,
|
||||
float1, float2, float3, float4,
|
||||
double1, double2, double3, double4>();
|
||||
|
||||
if (passed == true) {
|
||||
passed();
|
||||
}
|
||||
else {
|
||||
failed("Failed some vector test.");
|
||||
}
|
||||
}
|
||||
@@ -1,42 +0,0 @@
|
||||
/*
|
||||
Copyright (c) 2015 - 2021 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:
|
||||
|
||||
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.
|
||||
*/
|
||||
|
||||
/* HIT_START
|
||||
* BUILD: %t %s ../test_common.cpp
|
||||
* TEST: %t
|
||||
* HIT_END
|
||||
*/
|
||||
|
||||
#include "test_common.h"
|
||||
|
||||
/*
|
||||
* Note : Compile time test hence always returns success while run.
|
||||
* Intension is to make sure apilcation can access hip version.
|
||||
*/
|
||||
int main()
|
||||
{
|
||||
std::cout<<"Hip major version : "<<HIP_VERSION_MAJOR<<std::endl;
|
||||
std::cout<<"Hip minor version : "<<HIP_VERSION_MINOR<<std::endl;
|
||||
std::cout<<"Hip patch version : "<<HIP_VERSION_PATCH<<std::endl;
|
||||
std::cout<<"Hip patch version : "<<HIP_VERSION<<std::endl;
|
||||
passed();
|
||||
}
|
||||
@@ -1,100 +0,0 @@
|
||||
/*
|
||||
Copyright (c) 2015 - 2021 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:
|
||||
|
||||
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.
|
||||
*/
|
||||
|
||||
/* HIT_START
|
||||
* BUILD: %t %s ../test_common.cpp NVCC_OPTIONS --Wno-deprecated-declarations
|
||||
* TEST: %t
|
||||
* HIT_END
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <iostream>
|
||||
|
||||
#include <hip/hip_runtime.h>
|
||||
#include <hip/device_functions.h>
|
||||
#define HIP_ASSERT(x) (assert((x) == hipSuccess))
|
||||
|
||||
__global__ void warpvote(int* device_any, int* device_all,
|
||||
int Num_Warps_per_Block, int pshift) {
|
||||
int tid = threadIdx.x + blockIdx.x * blockDim.x;
|
||||
device_any[threadIdx.x >> pshift] = __any(tid - 77);
|
||||
device_all[threadIdx.x >> pshift] = __all(tid - 77);
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
int warpSize, pshift;
|
||||
hipDeviceProp_t devProp;
|
||||
hipGetDeviceProperties(&devProp, 0);
|
||||
warpSize = devProp.warpSize;
|
||||
|
||||
int w = warpSize;
|
||||
pshift = 0;
|
||||
while (w >>= 1) ++pshift;
|
||||
|
||||
printf("warpSize=%d pshift=%d\n", warpSize, pshift);
|
||||
|
||||
|
||||
int anycount = 0;
|
||||
int allcount = 0;
|
||||
int Num_Threads_per_Block = 1024;
|
||||
int Num_Blocks_per_Grid = 1;
|
||||
int Num_Warps_per_Block = Num_Threads_per_Block / warpSize;
|
||||
int Num_Warps_per_Grid = (Num_Threads_per_Block * Num_Blocks_per_Grid) / warpSize;
|
||||
|
||||
int* host_any = (int*)malloc(Num_Warps_per_Grid * sizeof(int));
|
||||
int* host_all = (int*)malloc(Num_Warps_per_Grid * sizeof(int));
|
||||
int* device_any;
|
||||
int* device_all;
|
||||
HIP_ASSERT(hipMalloc((void**)&device_any, Num_Warps_per_Grid * sizeof(int)));
|
||||
HIP_ASSERT(hipMalloc((void**)&device_all, Num_Warps_per_Grid * sizeof(int)));
|
||||
for (int i = 0; i < Num_Warps_per_Grid; i++) {
|
||||
host_any[i] = 0;
|
||||
host_all[i] = 0;
|
||||
}
|
||||
HIP_ASSERT(hipMemcpy(device_any, host_any, sizeof(int), hipMemcpyHostToDevice));
|
||||
HIP_ASSERT(hipMemcpy(device_all, host_all, sizeof(int), hipMemcpyHostToDevice));
|
||||
|
||||
hipLaunchKernelGGL(warpvote, dim3(Num_Blocks_per_Grid), dim3(Num_Threads_per_Block), 0, 0,
|
||||
device_any, device_all, Num_Warps_per_Block, pshift);
|
||||
|
||||
|
||||
HIP_ASSERT(
|
||||
hipMemcpy(host_any, device_any, Num_Warps_per_Grid * sizeof(int), hipMemcpyDeviceToHost));
|
||||
HIP_ASSERT(
|
||||
hipMemcpy(host_all, device_all, Num_Warps_per_Grid * sizeof(int), hipMemcpyDeviceToHost));
|
||||
for (int i = 0; i < Num_Warps_per_Grid; i++) {
|
||||
printf("warp no. %d __any = %d \n", i, host_any[i]);
|
||||
printf("warp no. %d __all = %d \n", i, host_all[i]);
|
||||
|
||||
if (host_all[i] != 1) ++allcount;
|
||||
if (host_any[i] != 1) ++anycount;
|
||||
}
|
||||
|
||||
if (anycount == 0 && allcount == 1)
|
||||
printf("PASSED\n");
|
||||
else {
|
||||
printf("FAILED\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
@@ -1,97 +0,0 @@
|
||||
/*
|
||||
Copyright (c) 2015 - 2021 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:
|
||||
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.
|
||||
*/
|
||||
|
||||
/* HIT_START
|
||||
* BUILD: %t %s ../test_common.cpp NVCC_OPTIONS --Wno-deprecated-declarations
|
||||
* TEST: %t
|
||||
* HIT_END
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include <hip/hip_runtime.h>
|
||||
#include <hip/device_functions.h>
|
||||
|
||||
#define HIP_ASSERT(x) (assert((x) == hipSuccess))
|
||||
|
||||
__global__ void gpu_ballot(unsigned int* device_ballot, int Num_Warps_per_Block,
|
||||
int pshift) {
|
||||
int tid = threadIdx.x + blockIdx.x * blockDim.x;
|
||||
const unsigned int warp_num = threadIdx.x >> pshift;
|
||||
#ifdef __HIP_PLATFORM_AMD__
|
||||
atomicAdd(&device_ballot[warp_num + blockIdx.x * Num_Warps_per_Block],
|
||||
__popcll(__ballot(tid - 245)));
|
||||
#else
|
||||
atomicAdd(&device_ballot[warp_num + blockIdx.x * Num_Warps_per_Block],
|
||||
__popc(__ballot(tid - 245)));
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
int warpSize, pshift;
|
||||
hipDeviceProp_t devProp;
|
||||
hipGetDeviceProperties(&devProp, 0);
|
||||
|
||||
warpSize = devProp.warpSize;
|
||||
|
||||
int w = warpSize;
|
||||
pshift = 0;
|
||||
while (w >>= 1) ++pshift;
|
||||
|
||||
unsigned int Num_Threads_per_Block = 512;
|
||||
unsigned int Num_Blocks_per_Grid = 1;
|
||||
unsigned int Num_Warps_per_Block = Num_Threads_per_Block / warpSize;
|
||||
unsigned int Num_Warps_per_Grid = (Num_Threads_per_Block * Num_Blocks_per_Grid) / warpSize;
|
||||
unsigned int* host_ballot = (unsigned int*)malloc(Num_Warps_per_Grid * sizeof(unsigned int));
|
||||
unsigned int* device_ballot;
|
||||
HIP_ASSERT(hipMalloc((void**)&device_ballot, Num_Warps_per_Grid * sizeof(unsigned int)));
|
||||
int divergent_count = 0;
|
||||
for (int i = 0; i < Num_Warps_per_Grid; i++) host_ballot[i] = 0;
|
||||
|
||||
|
||||
HIP_ASSERT(hipMemcpy(device_ballot, host_ballot, Num_Warps_per_Grid * sizeof(unsigned int),
|
||||
hipMemcpyHostToDevice));
|
||||
|
||||
hipLaunchKernelGGL(gpu_ballot, dim3(Num_Blocks_per_Grid), dim3(Num_Threads_per_Block), 0, 0,
|
||||
device_ballot, Num_Warps_per_Block, pshift);
|
||||
|
||||
|
||||
HIP_ASSERT(hipMemcpy(host_ballot, device_ballot, Num_Warps_per_Grid * sizeof(unsigned int),
|
||||
hipMemcpyDeviceToHost));
|
||||
for (int i = 0; i < Num_Warps_per_Grid; i++) {
|
||||
if ((host_ballot[i] == 0) || (host_ballot[i] / warpSize == warpSize))
|
||||
std::cout << "Warp " << i << " IS convergent- Predicate true for "
|
||||
<< host_ballot[i] / warpSize << " threads\n";
|
||||
|
||||
else {
|
||||
std::cout << " Warp " << i << " IS divergent - Predicate true for "
|
||||
<< host_ballot[i] / warpSize << " threads\n";
|
||||
divergent_count++;
|
||||
}
|
||||
}
|
||||
|
||||
if (divergent_count == 1)
|
||||
printf("PASSED\n");
|
||||
else {
|
||||
printf("FAILED\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
@@ -1,221 +0,0 @@
|
||||
/*
|
||||
Copyright (c) 2015 - 2021 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:
|
||||
|
||||
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.
|
||||
*/
|
||||
|
||||
/* HIT_START
|
||||
* BUILD: %t %s ../test_common.cpp EXCLUDE_HIP_PLATFORM nvidia
|
||||
* TEST: %t
|
||||
* HIT_END
|
||||
*/
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
#include <algorithm>
|
||||
#include <stdlib.h>
|
||||
#include <iostream>
|
||||
#include <random>
|
||||
#include "hip/hip_runtime.h"
|
||||
#include <hip/device_functions.h>
|
||||
|
||||
#define HIP_ASSERT(x) (assert((x) == hipSuccess))
|
||||
|
||||
#define TEST_DEBUG (0)
|
||||
|
||||
|
||||
// CPU implementation of bitextract
|
||||
template <typename T>
|
||||
T bit_extract(T src0, unsigned int src1, unsigned int src2) {
|
||||
unsigned int bits = sizeof(T) * 8;
|
||||
T offset = src1 & (bits - 1);
|
||||
T width = src2 & (bits - 1);
|
||||
if (width == 0) {
|
||||
return 0;
|
||||
} else {
|
||||
return (src0 << (bits - width - offset)) >> (bits - width);
|
||||
}
|
||||
}
|
||||
|
||||
__global__ void HIP_kernel(unsigned int* out32, unsigned int* in32_0,
|
||||
unsigned int* in32_1, unsigned int* in32_2,
|
||||
unsigned long long int* out64, unsigned long long int* in64_0,
|
||||
unsigned int* in64_1, unsigned int* in64_2) {
|
||||
int x = blockDim.x * blockIdx.x + threadIdx.x;
|
||||
|
||||
out32[x] = __bitextract_u32(in32_0[x], in32_1[x], in32_2[x]);
|
||||
out64[x] = __bitextract_u64(in64_0[x], in64_1[x], in64_2[x]);
|
||||
}
|
||||
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main() {
|
||||
unsigned int* hostOut32;
|
||||
unsigned int* hostSrc032;
|
||||
unsigned int* hostSrc132;
|
||||
unsigned int* hostSrc232;
|
||||
unsigned long long int* hostOut64;
|
||||
unsigned long long int* hostSrc064;
|
||||
unsigned int* hostSrc164;
|
||||
unsigned int* hostSrc264;
|
||||
|
||||
unsigned int* deviceOut32;
|
||||
unsigned int* deviceSrc032;
|
||||
unsigned int* deviceSrc132;
|
||||
unsigned int* deviceSrc232;
|
||||
unsigned long long int* deviceOut64;
|
||||
unsigned long long int* deviceSrc064;
|
||||
unsigned int* deviceSrc164;
|
||||
unsigned int* deviceSrc264;
|
||||
|
||||
hipDeviceProp_t devProp;
|
||||
hipGetDeviceProperties(&devProp, 0);
|
||||
cout << " System minor " << devProp.minor << endl;
|
||||
cout << " System major " << devProp.major << endl;
|
||||
cout << " agent prop name " << devProp.name << endl;
|
||||
|
||||
cout << "hip Device prop succeeded " << endl;
|
||||
|
||||
unsigned int wave_size = devProp.warpSize;
|
||||
unsigned int num_waves_per_block = 2;
|
||||
unsigned int num_threads_per_block = wave_size * num_waves_per_block;
|
||||
unsigned int num_blocks = 2;
|
||||
unsigned int NUM = num_threads_per_block * num_blocks;
|
||||
|
||||
int i;
|
||||
int errors;
|
||||
|
||||
hostOut32 = (unsigned int*)malloc(NUM * sizeof(unsigned int));
|
||||
hostSrc032 = (unsigned int*)malloc(NUM * sizeof(unsigned int));
|
||||
hostSrc132 = (unsigned int*)malloc(NUM * sizeof(unsigned int));
|
||||
hostSrc232 = (unsigned int*)malloc(NUM * sizeof(unsigned int));
|
||||
|
||||
hostOut64 = (unsigned long long int*)malloc(NUM * sizeof(unsigned long long int));
|
||||
hostSrc064 = (unsigned long long int*)malloc(NUM * sizeof(unsigned long long int));
|
||||
hostSrc164 = (unsigned int*)malloc(NUM * sizeof(unsigned int));
|
||||
hostSrc264 = (unsigned int*)malloc(NUM * sizeof(unsigned int));
|
||||
|
||||
// initialize the input data
|
||||
std::random_device rd;
|
||||
std::uniform_int_distribution<uint32_t> uint32_src0_dist;
|
||||
std::uniform_int_distribution<uint32_t> uint32_src12_dist(0,31);
|
||||
std::uniform_int_distribution<uint64_t> uint64_src0_dist;
|
||||
std::uniform_int_distribution<uint32_t> uint64_src12_dist(0,63);
|
||||
for (i = 0; i < NUM; i++) {
|
||||
hostOut32[i] = 0;
|
||||
hostSrc032[i] = uint32_src0_dist(rd);
|
||||
hostSrc132[i] = uint32_src12_dist(rd);
|
||||
hostSrc232[i] = uint32_src12_dist(rd);
|
||||
if (hostSrc132[i] + hostSrc232[i] > 32)
|
||||
hostSrc232[i] = 32 - hostSrc132[i];
|
||||
hostOut64[i] = 0;
|
||||
hostSrc064[i] = uint64_src0_dist(rd);
|
||||
hostSrc164[i] = uint64_src12_dist(rd);
|
||||
hostSrc264[i] = uint64_src12_dist(rd);
|
||||
}
|
||||
|
||||
HIP_ASSERT(hipMalloc((void**)&deviceOut32, NUM * sizeof(unsigned int)));
|
||||
HIP_ASSERT(hipMalloc((void**)&deviceSrc032, NUM * sizeof(unsigned int)));
|
||||
HIP_ASSERT(hipMalloc((void**)&deviceSrc132, NUM * sizeof(unsigned int)));
|
||||
HIP_ASSERT(hipMalloc((void**)&deviceSrc232, NUM * sizeof(unsigned int)));
|
||||
|
||||
HIP_ASSERT(hipMalloc((void**)&deviceOut64, NUM * sizeof(unsigned long long int)));
|
||||
HIP_ASSERT(hipMalloc((void**)&deviceSrc064, NUM * sizeof(unsigned long long int)));
|
||||
HIP_ASSERT(hipMalloc((void**)&deviceSrc164, NUM * sizeof(unsigned int)));
|
||||
HIP_ASSERT(hipMalloc((void**)&deviceSrc264, NUM * sizeof(unsigned int)));
|
||||
|
||||
HIP_ASSERT(hipMemcpy(deviceSrc032, hostSrc032, NUM * sizeof(unsigned int), hipMemcpyHostToDevice));
|
||||
HIP_ASSERT(hipMemcpy(deviceSrc132, hostSrc132, NUM * sizeof(unsigned int), hipMemcpyHostToDevice));
|
||||
HIP_ASSERT(hipMemcpy(deviceSrc232, hostSrc232, NUM * sizeof(unsigned int), hipMemcpyHostToDevice));
|
||||
|
||||
HIP_ASSERT(hipMemcpy(deviceSrc064, hostSrc064, NUM * sizeof(unsigned long long int),
|
||||
hipMemcpyHostToDevice));
|
||||
HIP_ASSERT(hipMemcpy(deviceSrc164, hostSrc164, NUM * sizeof(unsigned int), hipMemcpyHostToDevice));
|
||||
HIP_ASSERT(hipMemcpy(deviceSrc264, hostSrc264, NUM * sizeof(unsigned int), hipMemcpyHostToDevice));
|
||||
|
||||
|
||||
hipLaunchKernelGGL(HIP_kernel, dim3(num_blocks), dim3(num_threads_per_block),
|
||||
0, 0,
|
||||
deviceOut32, deviceSrc032, deviceSrc132, deviceSrc232,
|
||||
deviceOut64, deviceSrc064, deviceSrc164, deviceSrc264);
|
||||
|
||||
|
||||
HIP_ASSERT(hipMemcpy(hostOut32, deviceOut32, NUM * sizeof(unsigned int), hipMemcpyDeviceToHost));
|
||||
HIP_ASSERT(hipMemcpy(hostOut64, deviceOut64,
|
||||
NUM * sizeof(unsigned long long int), hipMemcpyDeviceToHost));
|
||||
|
||||
// verify the results
|
||||
errors = 0;
|
||||
for (i = 0; i < NUM; i++) {
|
||||
if (hostOut32[i] != bit_extract<uint32_t>(hostSrc032[i], hostSrc132[i], hostSrc232[i])) {
|
||||
errors++;
|
||||
#if TEST_DEBUG
|
||||
cout << "device: " << hostOut32[i] << " host: "
|
||||
<< bit_extract<uint32_t>(hostSrc032[i], hostSrc132[i], hostSrc232[i])
|
||||
<< " " << hostSrc032[i] << " " << hostSrc132[i] << " " << hostSrc232[i] << "\n";
|
||||
#endif
|
||||
}
|
||||
}
|
||||
if (errors != 0) {
|
||||
cout << "__bitextract_u32() FAILED\n" << endl;
|
||||
return -1;
|
||||
} else {
|
||||
cout << "__bitextract_u32() checked!" << endl;
|
||||
}
|
||||
errors = 0;
|
||||
for (i = 0; i < NUM; i++) {
|
||||
if (hostOut64[i] != bit_extract<uint64_t>(hostSrc064[i], hostSrc164[i], hostSrc264[i])) {
|
||||
errors++;
|
||||
#if TEST_DEBUG
|
||||
cout << "device: " << hostOut64[i] << " host: "
|
||||
<< bit_extract<uint64_t>(hostSrc064[i], hostSrc164[i], hostSrc264[i])
|
||||
<< " " << hostSrc064[i] << " " << hostSrc164[i] << " " << hostSrc264[i] << "\n";
|
||||
#endif
|
||||
}
|
||||
}
|
||||
if (errors != 0) {
|
||||
cout << "__bitextract_u64() FAILED" << endl;
|
||||
return -1;
|
||||
} else {
|
||||
cout << "__bitextract_u64() checked!" << endl;
|
||||
}
|
||||
|
||||
cout << "__bitextract_u32() and __bitextract_u64() PASSED!" << endl;
|
||||
|
||||
HIP_ASSERT(hipFree(deviceOut32));
|
||||
HIP_ASSERT(hipFree(deviceSrc032));
|
||||
HIP_ASSERT(hipFree(deviceSrc132));
|
||||
HIP_ASSERT(hipFree(deviceSrc232));
|
||||
HIP_ASSERT(hipFree(deviceOut64));
|
||||
HIP_ASSERT(hipFree(deviceSrc064));
|
||||
HIP_ASSERT(hipFree(deviceSrc164));
|
||||
HIP_ASSERT(hipFree(deviceSrc264));
|
||||
|
||||
free(hostOut32);
|
||||
free(hostSrc032);
|
||||
free(hostSrc132);
|
||||
free(hostSrc232);
|
||||
free(hostOut64);
|
||||
free(hostSrc064);
|
||||
free(hostSrc164);
|
||||
free(hostSrc264);
|
||||
|
||||
return errors;
|
||||
}
|
||||
@@ -1,239 +0,0 @@
|
||||
/*
|
||||
Copyright (c) 2015 - 2021 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:
|
||||
|
||||
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.
|
||||
*/
|
||||
|
||||
/* HIT_START
|
||||
* BUILD: %t %s ../test_common.cpp EXCLUDE_HIP_PLATFORM nvidia
|
||||
* TEST: %t
|
||||
* HIT_END
|
||||
*/
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
#include <algorithm>
|
||||
#include <stdlib.h>
|
||||
#include <iostream>
|
||||
#include <random>
|
||||
#include "hip/hip_runtime.h"
|
||||
#include <hip/device_functions.h>
|
||||
|
||||
#define HIP_ASSERT(x) (assert((x) == hipSuccess))
|
||||
|
||||
#define TEST_DEBUG (0)
|
||||
|
||||
|
||||
// CPU implementation of bitinsert
|
||||
template <typename T>
|
||||
T bit_insert(T src0, T src1, unsigned int src2, unsigned int src3) {
|
||||
unsigned int bits = sizeof(T) * 8;
|
||||
T offset = src2 & (bits - 1);
|
||||
T width = src3 & (bits - 1);
|
||||
T mask = (((T)1) << width) - 1;
|
||||
return ((src0 & ~(mask << offset)) | ((src1 & mask) << offset));
|
||||
}
|
||||
|
||||
__global__ void HIP_kernel(unsigned int* out32,
|
||||
unsigned int* in32_0, unsigned int* in32_1,
|
||||
unsigned int* in32_2, unsigned int* in32_3,
|
||||
unsigned long long int* out64, unsigned long long int* in64_0,
|
||||
unsigned long long int* in64_1, unsigned int* in64_2,
|
||||
unsigned int* in64_3) {
|
||||
int x = blockDim.x * blockIdx.x + threadIdx.x;
|
||||
|
||||
out32[x] = __bitinsert_u32(in32_0[x], in32_1[x], in32_2[x], in32_3[x]);
|
||||
out64[x] = __bitinsert_u64(in64_0[x], in64_1[x], in64_2[x], in64_3[x]);
|
||||
}
|
||||
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main() {
|
||||
unsigned int* hostOut32;
|
||||
unsigned int* hostSrc032;
|
||||
unsigned int* hostSrc132;
|
||||
unsigned int* hostSrc232;
|
||||
unsigned int* hostSrc332;
|
||||
unsigned long long int* hostOut64;
|
||||
unsigned long long int* hostSrc064;
|
||||
unsigned long long int* hostSrc164;
|
||||
unsigned int* hostSrc264;
|
||||
unsigned int* hostSrc364;
|
||||
|
||||
unsigned int* deviceOut32;
|
||||
unsigned int* deviceSrc032;
|
||||
unsigned int* deviceSrc132;
|
||||
unsigned int* deviceSrc232;
|
||||
unsigned int* deviceSrc332;
|
||||
unsigned long long int* deviceOut64;
|
||||
unsigned long long int* deviceSrc064;
|
||||
unsigned long long int* deviceSrc164;
|
||||
unsigned int* deviceSrc264;
|
||||
unsigned int* deviceSrc364;
|
||||
|
||||
hipDeviceProp_t devProp;
|
||||
hipGetDeviceProperties(&devProp, 0);
|
||||
cout << " System minor " << devProp.minor << endl;
|
||||
cout << " System major " << devProp.major << endl;
|
||||
cout << " agent prop name " << devProp.name << endl;
|
||||
|
||||
cout << "hip Device prop succeeded " << endl;
|
||||
|
||||
unsigned int wave_size = devProp.warpSize;
|
||||
unsigned int num_waves_per_block = 2;
|
||||
unsigned int num_threads_per_block = wave_size * num_waves_per_block;
|
||||
unsigned int num_blocks = 2;
|
||||
unsigned int NUM = num_threads_per_block * num_blocks;
|
||||
|
||||
int i;
|
||||
int errors;
|
||||
|
||||
hostOut32 = (unsigned int*)malloc(NUM * sizeof(unsigned int));
|
||||
hostSrc032 = (unsigned int*)malloc(NUM * sizeof(unsigned int));
|
||||
hostSrc132 = (unsigned int*)malloc(NUM * sizeof(unsigned int));
|
||||
hostSrc232 = (unsigned int*)malloc(NUM * sizeof(unsigned int));
|
||||
hostSrc332 = (unsigned int*)malloc(NUM * sizeof(unsigned int));
|
||||
|
||||
hostOut64 = (unsigned long long int*)malloc(NUM * sizeof(unsigned long long int));
|
||||
hostSrc064 = (unsigned long long int*)malloc(NUM * sizeof(unsigned long long int));
|
||||
hostSrc164 = (unsigned long long int*)malloc(NUM * sizeof(unsigned long long int));
|
||||
hostSrc264 = (unsigned int*)malloc(NUM * sizeof(unsigned int));
|
||||
hostSrc364 = (unsigned int*)malloc(NUM * sizeof(unsigned int));
|
||||
|
||||
// initialize the input data
|
||||
std::random_device rd;
|
||||
std::uniform_int_distribution<uint32_t> uint32_src01_dist;
|
||||
std::uniform_int_distribution<uint32_t> uint32_src23_dist(0,31);
|
||||
std::uniform_int_distribution<uint64_t> uint64_src01_dist;
|
||||
std::uniform_int_distribution<uint32_t> uint64_src23_dist(0,63);
|
||||
for (i = 0; i < NUM; i++) {
|
||||
hostOut32[i] = 0;
|
||||
hostSrc032[i] = uint32_src01_dist(rd);
|
||||
hostSrc132[i] = uint32_src01_dist(rd);
|
||||
hostSrc232[i] = uint32_src23_dist(rd);
|
||||
hostSrc232[i] = uint32_src23_dist(rd);
|
||||
hostOut64[i] = 0;
|
||||
hostSrc064[i] = uint64_src01_dist(rd);
|
||||
hostSrc164[i] = uint64_src01_dist(rd);
|
||||
hostSrc264[i] = uint64_src23_dist(rd);
|
||||
hostSrc264[i] = uint64_src23_dist(rd);
|
||||
}
|
||||
|
||||
HIP_ASSERT(hipMalloc((void**)&deviceOut32, NUM * sizeof(unsigned int)));
|
||||
HIP_ASSERT(hipMalloc((void**)&deviceSrc032, NUM * sizeof(unsigned int)));
|
||||
HIP_ASSERT(hipMalloc((void**)&deviceSrc132, NUM * sizeof(unsigned int)));
|
||||
HIP_ASSERT(hipMalloc((void**)&deviceSrc232, NUM * sizeof(unsigned int)));
|
||||
HIP_ASSERT(hipMalloc((void**)&deviceSrc332, NUM * sizeof(unsigned int)));
|
||||
|
||||
HIP_ASSERT(hipMalloc((void**)&deviceOut64, NUM * sizeof(unsigned long long int)));
|
||||
HIP_ASSERT(hipMalloc((void**)&deviceSrc064, NUM * sizeof(unsigned long long int)));
|
||||
HIP_ASSERT(hipMalloc((void**)&deviceSrc164, NUM * sizeof(unsigned long long int)));
|
||||
HIP_ASSERT(hipMalloc((void**)&deviceSrc264, NUM * sizeof(unsigned int)));
|
||||
HIP_ASSERT(hipMalloc((void**)&deviceSrc364, NUM * sizeof(unsigned int)));
|
||||
|
||||
HIP_ASSERT(hipMemcpy(deviceSrc032, hostSrc032, NUM * sizeof(unsigned int), hipMemcpyHostToDevice));
|
||||
HIP_ASSERT(hipMemcpy(deviceSrc132, hostSrc132, NUM * sizeof(unsigned int), hipMemcpyHostToDevice));
|
||||
HIP_ASSERT(hipMemcpy(deviceSrc232, hostSrc232, NUM * sizeof(unsigned int), hipMemcpyHostToDevice));
|
||||
HIP_ASSERT(hipMemcpy(deviceSrc332, hostSrc332, NUM * sizeof(unsigned int), hipMemcpyHostToDevice));
|
||||
|
||||
HIP_ASSERT(hipMemcpy(deviceSrc064, hostSrc064, NUM * sizeof(unsigned long long int),
|
||||
hipMemcpyHostToDevice));
|
||||
HIP_ASSERT(hipMemcpy(deviceSrc164, hostSrc164, NUM * sizeof(unsigned long long int),
|
||||
hipMemcpyHostToDevice));
|
||||
HIP_ASSERT(hipMemcpy(deviceSrc264, hostSrc264, NUM * sizeof(unsigned int), hipMemcpyHostToDevice));
|
||||
HIP_ASSERT(hipMemcpy(deviceSrc364, hostSrc364, NUM * sizeof(unsigned int), hipMemcpyHostToDevice));
|
||||
|
||||
|
||||
hipLaunchKernelGGL(HIP_kernel, dim3(num_blocks), dim3(num_threads_per_block),
|
||||
0, 0,
|
||||
deviceOut32, deviceSrc032, deviceSrc132, deviceSrc232, deviceSrc332,
|
||||
deviceOut64, deviceSrc064, deviceSrc164, deviceSrc264, deviceSrc364);
|
||||
|
||||
|
||||
HIP_ASSERT(hipMemcpy(hostOut32, deviceOut32, NUM * sizeof(unsigned int), hipMemcpyDeviceToHost));
|
||||
HIP_ASSERT(hipMemcpy(hostOut64, deviceOut64,
|
||||
NUM * sizeof(unsigned long long int), hipMemcpyDeviceToHost));
|
||||
|
||||
// verify the results
|
||||
errors = 0;
|
||||
for (i = 0; i < NUM; i++) {
|
||||
if (hostOut32[i] != bit_insert<uint32_t>(hostSrc032[i], hostSrc132[i],
|
||||
hostSrc232[i], hostSrc332[i])) {
|
||||
errors++;
|
||||
#if TEST_DEBUG
|
||||
cout << "device: " << hostOut32[i] << " host: "
|
||||
<< bit_insert<uint32_t>(hostSrc032[i], hostSrc132[i], hostSrc232[i], hostSrc332[i])
|
||||
<< " " << hostSrc032[i] << " " << hostSrc132[i] << " " << hostSrc232[i]
|
||||
<< " " << hostSrc332[i] << "\n";
|
||||
#endif
|
||||
}
|
||||
}
|
||||
if (errors != 0) {
|
||||
cout << "__bitinsert_u32() FAILED\n" << endl;
|
||||
return -1;
|
||||
} else {
|
||||
cout << "__bitinsert_u32() checked!" << endl;
|
||||
}
|
||||
errors = 0;
|
||||
for (i = 0; i < NUM; i++) {
|
||||
if (hostOut64[i] != bit_insert<uint64_t>(hostSrc064[i], hostSrc164[i],
|
||||
hostSrc264[i], hostSrc364[i])) {
|
||||
errors++;
|
||||
#if TEST_DEBUG
|
||||
cout << "device: " << hostOut64[i] << " host: "
|
||||
<< bit_insert<uint64_t>(hostSrc064[i], hostSrc164[i], hostSrc264[i], hostSrc364[i])
|
||||
<< " " << hostSrc064[i] << " " << hostSrc164[i] << " " << hostSrc264[i]
|
||||
<< " " << hostSrc364[i] << "\n";
|
||||
#endif
|
||||
}
|
||||
}
|
||||
if (errors != 0) {
|
||||
cout << "__bitinsert_u64() FAILED" << endl;
|
||||
return -1;
|
||||
} else {
|
||||
cout << "__bitinsert_u64() checked!" << endl;
|
||||
}
|
||||
|
||||
cout << "__bitinsert_u32() and __bitinsert_u64() PASSED!" << endl;
|
||||
|
||||
HIP_ASSERT(hipFree(deviceOut32));
|
||||
HIP_ASSERT(hipFree(deviceSrc032));
|
||||
HIP_ASSERT(hipFree(deviceSrc132));
|
||||
HIP_ASSERT(hipFree(deviceSrc232));
|
||||
HIP_ASSERT(hipFree(deviceSrc332));
|
||||
HIP_ASSERT(hipFree(deviceOut64));
|
||||
HIP_ASSERT(hipFree(deviceSrc064));
|
||||
HIP_ASSERT(hipFree(deviceSrc164));
|
||||
HIP_ASSERT(hipFree(deviceSrc264));
|
||||
HIP_ASSERT(hipFree(deviceSrc364));
|
||||
|
||||
free(hostOut32);
|
||||
free(hostSrc032);
|
||||
free(hostSrc132);
|
||||
free(hostSrc232);
|
||||
free(hostSrc332);
|
||||
free(hostOut64);
|
||||
free(hostSrc064);
|
||||
free(hostSrc164);
|
||||
free(hostSrc264);
|
||||
free(hostSrc364);
|
||||
|
||||
return errors;
|
||||
}
|
||||
@@ -1,175 +0,0 @@
|
||||
/*
|
||||
Copyright (c) 2015 - 2021 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:
|
||||
|
||||
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.
|
||||
*/
|
||||
|
||||
/* HIT_START
|
||||
* BUILD: %t %s ../test_common.cpp
|
||||
* TEST: %t
|
||||
* HIT_END
|
||||
*/
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
#include <algorithm>
|
||||
#include <stdlib.h>
|
||||
#include <iostream>
|
||||
#include "hip/hip_runtime.h"
|
||||
#include <hip/device_functions.h>
|
||||
|
||||
#define HIP_ASSERT(x) (assert((x) == hipSuccess))
|
||||
|
||||
|
||||
#define WIDTH 32
|
||||
#define HEIGHT 32
|
||||
|
||||
#define NUM (WIDTH * HEIGHT)
|
||||
|
||||
#define THREADS_PER_BLOCK_X 8
|
||||
#define THREADS_PER_BLOCK_Y 8
|
||||
#define THREADS_PER_BLOCK_Z 1
|
||||
|
||||
|
||||
// CPU implementation of bitreverse
|
||||
template <typename T>
|
||||
T bitreverse(T num) {
|
||||
T count = sizeof(num) * 8 - 1;
|
||||
T reverse_num = num;
|
||||
|
||||
num >>= 1;
|
||||
while (num) {
|
||||
reverse_num <<= 1;
|
||||
reverse_num |= num & 1;
|
||||
num >>= 1;
|
||||
count--;
|
||||
}
|
||||
reverse_num <<= count;
|
||||
return reverse_num;
|
||||
}
|
||||
|
||||
__global__ void HIP_kernel(unsigned int* a, unsigned int* b,
|
||||
unsigned long long int* c, unsigned long long int* d, int width,
|
||||
int height) {
|
||||
int x = blockDim.x * blockIdx.x + threadIdx.x;
|
||||
int y = blockDim.y * blockIdx.y + threadIdx.y;
|
||||
|
||||
int i = y * width + x;
|
||||
if (i < (width * height)) {
|
||||
a[i] = __brev(b[i]);
|
||||
c[i] = __brevll(d[i]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main() {
|
||||
unsigned int* hostA;
|
||||
unsigned int* hostB;
|
||||
unsigned long long int* hostC;
|
||||
unsigned long long int* hostD;
|
||||
|
||||
unsigned int* deviceA;
|
||||
unsigned int* deviceB;
|
||||
unsigned long long int* deviceC;
|
||||
unsigned long long int* deviceD;
|
||||
|
||||
hipDeviceProp_t devProp;
|
||||
hipGetDeviceProperties(&devProp, 0);
|
||||
cout << " System minor " << devProp.minor << endl;
|
||||
cout << " System major " << devProp.major << endl;
|
||||
cout << " agent prop name " << devProp.name << endl;
|
||||
|
||||
cout << "hip Device prop succeeded " << endl;
|
||||
|
||||
|
||||
int i;
|
||||
int errors;
|
||||
|
||||
hostA = (unsigned int*)malloc(NUM * sizeof(unsigned int));
|
||||
hostB = (unsigned int*)malloc(NUM * sizeof(unsigned int));
|
||||
hostC = (unsigned long long int*)malloc(NUM * sizeof(unsigned long long int));
|
||||
hostD = (unsigned long long int*)malloc(NUM * sizeof(unsigned long long int));
|
||||
|
||||
// initialize the input data
|
||||
for (i = 0; i < NUM; i++) {
|
||||
hostB[i] = i;
|
||||
hostD[i] = i;
|
||||
}
|
||||
|
||||
HIP_ASSERT(hipMalloc((void**)&deviceA, NUM * sizeof(unsigned int)));
|
||||
HIP_ASSERT(hipMalloc((void**)&deviceB, NUM * sizeof(unsigned int)));
|
||||
HIP_ASSERT(hipMalloc((void**)&deviceC, NUM * sizeof(unsigned long long int)));
|
||||
HIP_ASSERT(hipMalloc((void**)&deviceD, NUM * sizeof(unsigned long long int)));
|
||||
|
||||
HIP_ASSERT(hipMemcpy(deviceB, hostB, NUM * sizeof(unsigned int), hipMemcpyHostToDevice));
|
||||
HIP_ASSERT(
|
||||
hipMemcpy(deviceD, hostD, NUM * sizeof(unsigned long long int), hipMemcpyHostToDevice));
|
||||
|
||||
|
||||
hipLaunchKernelGGL(HIP_kernel, dim3(WIDTH / THREADS_PER_BLOCK_X, HEIGHT / THREADS_PER_BLOCK_Y),
|
||||
dim3(THREADS_PER_BLOCK_X, THREADS_PER_BLOCK_Y), 0, 0, deviceA, deviceB, deviceC,
|
||||
deviceD, WIDTH, HEIGHT);
|
||||
|
||||
|
||||
HIP_ASSERT(hipMemcpy(hostA, deviceA, NUM * sizeof(unsigned int), hipMemcpyDeviceToHost));
|
||||
HIP_ASSERT(
|
||||
hipMemcpy(hostC, deviceC, NUM * sizeof(unsigned long long int), hipMemcpyDeviceToHost));
|
||||
|
||||
// verify the results
|
||||
errors = 0;
|
||||
for (i = 0; i < NUM; i++) {
|
||||
if (hostA[i] != bitreverse(hostB[i])) {
|
||||
errors++;
|
||||
}
|
||||
}
|
||||
if (errors != 0) {
|
||||
cout << "__brev() FAILED\n" << endl;
|
||||
return -1;
|
||||
} else {
|
||||
cout << "__brev() checked!" << endl;
|
||||
}
|
||||
errors = 0;
|
||||
for (i = 0; i < NUM; i++) {
|
||||
if (hostC[i] != bitreverse(hostD[i])) {
|
||||
errors++;
|
||||
}
|
||||
}
|
||||
if (errors != 0) {
|
||||
cout << "__brevll() FAILED" << endl;
|
||||
return -1;
|
||||
} else {
|
||||
cout << "__brevll() checked!" << endl;
|
||||
}
|
||||
|
||||
cout << "__brev() and __brevll() PASSED!" << endl;
|
||||
|
||||
HIP_ASSERT(hipFree(deviceA));
|
||||
HIP_ASSERT(hipFree(deviceB));
|
||||
HIP_ASSERT(hipFree(deviceC));
|
||||
HIP_ASSERT(hipFree(deviceD));
|
||||
|
||||
free(hostA);
|
||||
free(hostB);
|
||||
free(hostC);
|
||||
free(hostD);
|
||||
|
||||
return errors;
|
||||
}
|
||||
@@ -1,190 +0,0 @@
|
||||
/*
|
||||
Copyright (c) 2015 - 2021 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:
|
||||
|
||||
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.
|
||||
*/
|
||||
|
||||
/* HIT_START
|
||||
* BUILD: %t %s ../test_common.cpp
|
||||
* TEST: %t
|
||||
* HIT_END
|
||||
*/
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
#include <algorithm>
|
||||
#include <stdlib.h>
|
||||
#include <iostream>
|
||||
#include "hip/hip_runtime.h"
|
||||
#include <hip/device_functions.h>
|
||||
|
||||
#define HIP_ASSERT(x) (assert((x) == hipSuccess))
|
||||
#define WIDTH 8
|
||||
#define HEIGHT 8
|
||||
#define NUM (WIDTH * HEIGHT)
|
||||
|
||||
#define THREADS_PER_BLOCK_X 8
|
||||
#define THREADS_PER_BLOCK_Y 8
|
||||
#define THREADS_PER_BLOCK_Z 1
|
||||
|
||||
unsigned int firstbit_u32(unsigned int a) {
|
||||
if (a == 0) {
|
||||
return 32;
|
||||
}
|
||||
unsigned int pos = 0;
|
||||
while ((int)a > 0) {
|
||||
a <<= 1;
|
||||
pos++;
|
||||
}
|
||||
return pos;
|
||||
}
|
||||
|
||||
unsigned int firstbit_u64(unsigned long long int a) {
|
||||
if (a == 0) {
|
||||
return 64;
|
||||
}
|
||||
unsigned int pos = 0;
|
||||
while ((long long int)a > 0) {
|
||||
a <<= 1;
|
||||
pos++;
|
||||
}
|
||||
return pos;
|
||||
}
|
||||
|
||||
// Check implicit conversion will not cause ambiguity.
|
||||
__device__ void test_ambiguity() {
|
||||
short s;
|
||||
unsigned short us;
|
||||
float f;
|
||||
int i;
|
||||
unsigned int ui;
|
||||
__clz(f);
|
||||
__clz(s);
|
||||
__clz(us);
|
||||
__clzll(f);
|
||||
__clzll(i);
|
||||
__clzll(ui);
|
||||
}
|
||||
|
||||
__global__ void HIP_kernel(unsigned int* a, unsigned int* b, unsigned int* c,
|
||||
unsigned long long int* d, int width, int height) {
|
||||
int x = blockDim.x * blockIdx.x + threadIdx.x;
|
||||
int y = blockDim.y * blockIdx.y + threadIdx.y;
|
||||
|
||||
int i = y * width + x;
|
||||
if (i < (width * height)) {
|
||||
a[i] = __clz(b[i]);
|
||||
c[i] = __clzll(d[i]);
|
||||
}
|
||||
}
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main() {
|
||||
unsigned int* hostA;
|
||||
unsigned int* hostB;
|
||||
unsigned int* hostC;
|
||||
unsigned long long int* hostD;
|
||||
|
||||
unsigned int* deviceA;
|
||||
unsigned int* deviceB;
|
||||
unsigned int* deviceC;
|
||||
unsigned long long int* deviceD;
|
||||
|
||||
hipDeviceProp_t devProp;
|
||||
hipGetDeviceProperties(&devProp, 0);
|
||||
cout << " System minor " << devProp.minor << endl;
|
||||
cout << " System major " << devProp.major << endl;
|
||||
cout << " agent prop name " << devProp.name << endl;
|
||||
|
||||
cout << "hip Device prop succeeded " << endl;
|
||||
|
||||
unsigned int i;
|
||||
int errors;
|
||||
|
||||
hostA = (unsigned int*)malloc(NUM * sizeof(unsigned int));
|
||||
hostB = (unsigned int*)malloc(NUM * sizeof(unsigned int));
|
||||
hostC = (unsigned int*)malloc(NUM * sizeof(unsigned int));
|
||||
hostD = (unsigned long long int*)malloc(NUM * sizeof(unsigned long long int));
|
||||
|
||||
// initialize the input data
|
||||
for (i = 0; i < NUM; i++) {
|
||||
hostB[i] = 419430 * i;
|
||||
hostD[i] = i;
|
||||
}
|
||||
|
||||
HIP_ASSERT(hipMalloc((void**)&deviceA, NUM * sizeof(unsigned int)));
|
||||
HIP_ASSERT(hipMalloc((void**)&deviceB, NUM * sizeof(unsigned int)));
|
||||
HIP_ASSERT(hipMalloc((void**)&deviceC, NUM * sizeof(unsigned int)));
|
||||
HIP_ASSERT(hipMalloc((void**)&deviceD, NUM * sizeof(unsigned long long int)));
|
||||
|
||||
HIP_ASSERT(hipMemcpy(deviceB, hostB, NUM * sizeof(unsigned int), hipMemcpyHostToDevice));
|
||||
HIP_ASSERT(
|
||||
hipMemcpy(deviceD, hostD, NUM * sizeof(unsigned long long int), hipMemcpyHostToDevice));
|
||||
|
||||
hipLaunchKernelGGL(HIP_kernel, dim3(WIDTH / THREADS_PER_BLOCK_X, HEIGHT / THREADS_PER_BLOCK_Y),
|
||||
dim3(THREADS_PER_BLOCK_X, THREADS_PER_BLOCK_Y), 0, 0, deviceA, deviceB, deviceC,
|
||||
deviceD, WIDTH, HEIGHT);
|
||||
|
||||
|
||||
HIP_ASSERT(hipMemcpy(hostA, deviceA, NUM * sizeof(unsigned int), hipMemcpyDeviceToHost));
|
||||
HIP_ASSERT(hipMemcpy(hostC, deviceC, NUM * sizeof(unsigned int), hipMemcpyDeviceToHost));
|
||||
|
||||
// verify the results
|
||||
errors = 0;
|
||||
for (i = 0; i < NUM; i++) {
|
||||
printf("gpu_clz =%d, cpu_clz =%d \n", hostA[i], firstbit_u32(hostB[i]));
|
||||
if (hostA[i] != firstbit_u32(hostB[i])) {
|
||||
errors++;
|
||||
}
|
||||
}
|
||||
if (errors != 0) {
|
||||
cout << "FAILED clz" << endl;
|
||||
return -1;
|
||||
} else {
|
||||
cout << "__clz() checked!" << endl;
|
||||
}
|
||||
errors = 0;
|
||||
for (i = 0; i < NUM; i++) {
|
||||
printf("gpu_clzll =%d, cpu_clzll =%d \n", hostC[i], firstbit_u64(hostD[i]));
|
||||
if (hostC[i] != firstbit_u64(hostD[i])) {
|
||||
errors++;
|
||||
}
|
||||
}
|
||||
if (errors != 0) {
|
||||
cout << "FAILED clz" << endl;
|
||||
return -1;
|
||||
} else {
|
||||
cout << "__clzll() checked!" << endl;
|
||||
}
|
||||
|
||||
cout << "clz test PASSED!" << endl;
|
||||
|
||||
HIP_ASSERT(hipFree(deviceA));
|
||||
HIP_ASSERT(hipFree(deviceB));
|
||||
HIP_ASSERT(hipFree(deviceC));
|
||||
HIP_ASSERT(hipFree(deviceD));
|
||||
|
||||
free(hostA);
|
||||
free(hostB);
|
||||
free(hostC);
|
||||
free(hostD);
|
||||
|
||||
return errors;
|
||||
}
|
||||
@@ -1,170 +0,0 @@
|
||||
/*
|
||||
Copyright (c) 2015 - 2021 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:
|
||||
|
||||
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.
|
||||
*/
|
||||
|
||||
/* HIT_START
|
||||
* BUILD: %t %s ../test_common.cpp
|
||||
* TEST: %t
|
||||
* HIT_END
|
||||
*/
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
#include <algorithm>
|
||||
#include <stdlib.h>
|
||||
#include <iostream>
|
||||
#include <hip/hip_runtime.h>
|
||||
#include <hip/device_functions.h>
|
||||
|
||||
#define HIP_ASSERT(x) (assert((x) == hipSuccess))
|
||||
|
||||
|
||||
#define WIDTH 8
|
||||
#define HEIGHT 8
|
||||
|
||||
#define NUM (WIDTH * HEIGHT)
|
||||
|
||||
#define THREADS_PER_BLOCK_X 8
|
||||
#define THREADS_PER_BLOCK_Y 8
|
||||
#define THREADS_PER_BLOCK_Z 1
|
||||
|
||||
template <typename T>
|
||||
int lastbit(T a) {
|
||||
if (a == 0)
|
||||
return 0;
|
||||
int pos = 1;
|
||||
while ((a & 1) != 1) {
|
||||
a >>= 1;
|
||||
pos++;
|
||||
}
|
||||
return pos;
|
||||
}
|
||||
|
||||
|
||||
__global__ void HIP_kernel(unsigned int* a, unsigned int* b, unsigned int* c,
|
||||
unsigned long long int* d, int width, int height) {
|
||||
int x = blockDim.x * blockIdx.x + threadIdx.x;
|
||||
int y = blockDim.y * blockIdx.y + threadIdx.y;
|
||||
|
||||
int i = y * width + x;
|
||||
if (i < (width * height)) {
|
||||
a[i] = __ffs(b[i]);
|
||||
c[i] = __ffsll(d[i]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main() {
|
||||
unsigned int* hostA;
|
||||
unsigned int* hostB;
|
||||
unsigned int* hostC;
|
||||
unsigned long long int* hostD;
|
||||
|
||||
unsigned int* deviceA;
|
||||
unsigned int* deviceB;
|
||||
unsigned int* deviceC;
|
||||
unsigned long long int* deviceD;
|
||||
|
||||
hipDeviceProp_t devProp;
|
||||
hipGetDeviceProperties(&devProp, 0);
|
||||
cout << " System minor " << devProp.minor << endl;
|
||||
cout << " System major " << devProp.major << endl;
|
||||
cout << " agent prop name " << devProp.name << endl;
|
||||
|
||||
cout << "hip Device prop succeeded " << endl;
|
||||
|
||||
|
||||
int i;
|
||||
int errors;
|
||||
|
||||
hostA = (unsigned int*)malloc(NUM * sizeof(unsigned int));
|
||||
hostB = (unsigned int*)malloc(NUM * sizeof(unsigned int));
|
||||
hostC = (unsigned int*)malloc(NUM * sizeof(unsigned int));
|
||||
hostD = (unsigned long long int*)malloc(NUM * sizeof(unsigned long long int));
|
||||
|
||||
// initialize the input data
|
||||
for (i = 0; i < NUM; i++) {
|
||||
hostB[i] = i;
|
||||
hostD[i] = 1099511627776 + i;
|
||||
}
|
||||
|
||||
HIP_ASSERT(hipMalloc((void**)&deviceA, NUM * sizeof(unsigned int)));
|
||||
HIP_ASSERT(hipMalloc((void**)&deviceB, NUM * sizeof(unsigned int)));
|
||||
HIP_ASSERT(hipMalloc((void**)&deviceC, NUM * sizeof(unsigned int)));
|
||||
HIP_ASSERT(hipMalloc((void**)&deviceD, NUM * sizeof(unsigned long long int)));
|
||||
|
||||
HIP_ASSERT(hipMemcpy(deviceB, hostB, NUM * sizeof(unsigned int), hipMemcpyHostToDevice));
|
||||
HIP_ASSERT(
|
||||
hipMemcpy(deviceD, hostD, NUM * sizeof(unsigned long long int), hipMemcpyHostToDevice));
|
||||
|
||||
hipLaunchKernelGGL(HIP_kernel, dim3(WIDTH / THREADS_PER_BLOCK_X, HEIGHT / THREADS_PER_BLOCK_Y),
|
||||
dim3(THREADS_PER_BLOCK_X, THREADS_PER_BLOCK_Y), 0, 0, deviceA, deviceB, deviceC,
|
||||
deviceD, WIDTH, HEIGHT);
|
||||
|
||||
|
||||
HIP_ASSERT(hipMemcpy(hostA, deviceA, NUM * sizeof(unsigned int), hipMemcpyDeviceToHost));
|
||||
HIP_ASSERT(hipMemcpy(hostC, deviceC, NUM * sizeof(unsigned int), hipMemcpyDeviceToHost));
|
||||
|
||||
// verify the results
|
||||
errors = 0;
|
||||
for (i = 0; i < NUM; i++) {
|
||||
printf("gpu_ffs =%d, cpu_ffs =%d \n", hostA[i], lastbit(hostB[i]));
|
||||
if (hostA[i] != lastbit(hostB[i])) {
|
||||
errors++;
|
||||
}
|
||||
}
|
||||
if (errors != 0) {
|
||||
cout << "FAILED: ffs" << endl;
|
||||
return -1;
|
||||
} else {
|
||||
cout << "__ffs() for unsigned checked!" << endl;
|
||||
}
|
||||
errors = 0;
|
||||
for (i = 0; i < NUM; i++) {
|
||||
printf("gpu_ffsll =%d, cpu_ffsll =%d \n", hostC[i], lastbit(hostD[i]));
|
||||
if (hostC[i] != lastbit(hostD[i])) {
|
||||
errors++;
|
||||
}
|
||||
}
|
||||
if (errors != 0) {
|
||||
cout << "FAILED: ffs" << endl;
|
||||
return -1;
|
||||
} else {
|
||||
cout << "__ffsll() for unsigned checked!" << endl;
|
||||
}
|
||||
|
||||
cout << "ffs test PASSED!" << endl;
|
||||
|
||||
HIP_ASSERT(hipFree(deviceA));
|
||||
HIP_ASSERT(hipFree(deviceB));
|
||||
HIP_ASSERT(hipFree(deviceC));
|
||||
HIP_ASSERT(hipFree(deviceD));
|
||||
|
||||
|
||||
free(hostA);
|
||||
free(hostB);
|
||||
free(hostC);
|
||||
free(hostD);
|
||||
|
||||
return errors;
|
||||
}
|
||||
@@ -1,239 +0,0 @@
|
||||
/*
|
||||
Copyright (c) 2015 - 2021 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:
|
||||
|
||||
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.
|
||||
*/
|
||||
|
||||
/* HIT_START
|
||||
* BUILD: %t %s ../test_common.cpp EXCLUDE_HIP_PLATFORM nvidia HIPCC_OPTIONS -std=c++14
|
||||
* TEST: %t
|
||||
* HIT_END
|
||||
*/
|
||||
|
||||
#include <hip/hip_runtime.h>
|
||||
#include <type_traits>
|
||||
#include <random>
|
||||
#include "test_common.h"
|
||||
|
||||
static std::random_device dev;
|
||||
static std::mt19937 rng(dev());
|
||||
|
||||
template <typename T, typename M>
|
||||
__host__ __device__ inline constexpr int count() {
|
||||
return sizeof(T) / sizeof(M);
|
||||
}
|
||||
|
||||
inline float getRandomFloat(float min = 10, float max = 100) {
|
||||
std::uniform_real_distribution<float> gen(min, max);
|
||||
return gen(rng);
|
||||
}
|
||||
|
||||
template <typename T, typename B>
|
||||
void fillMatrix(T* a, int size) {
|
||||
for (int i = 0; i < size; i++) {
|
||||
T t;
|
||||
t.x = getRandomFloat();
|
||||
if constexpr (count<T, B>() >= 2) t.y = getRandomFloat();
|
||||
if constexpr (count<T, B>() >= 3) t.z = getRandomFloat();
|
||||
if constexpr (count<T, B>() >= 4) t.w = getRandomFloat();
|
||||
|
||||
a[i] = t;
|
||||
}
|
||||
}
|
||||
|
||||
// Test operations
|
||||
template <typename T, typename B>
|
||||
__host__ __device__ void testOperations(T& a, T& b) {
|
||||
a.x += b.x;
|
||||
a.x++;
|
||||
b.x++;
|
||||
if constexpr (count<T, B>() >= 2) {
|
||||
a.y = b.x;
|
||||
a.x = b.y;
|
||||
}
|
||||
if constexpr (count<T, B>() >= 3) {
|
||||
if (a.x > 0) b.x /= a.x;
|
||||
a.x *= b.z;
|
||||
a.y--;
|
||||
}
|
||||
if constexpr (count<T, B>() >= 4) {
|
||||
b.w = a.x;
|
||||
a.w += (-b.y);
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T, typename B>
|
||||
__global__ void testOperationsGPU(T* d_a, T* d_b, int size) {
|
||||
int id = threadIdx.x;
|
||||
if (id > size) return;
|
||||
T &a = d_a[id];
|
||||
T &b = d_b[id];
|
||||
|
||||
testOperations<T, B>(a, b);
|
||||
}
|
||||
|
||||
|
||||
template <typename T>
|
||||
void dcopy(T* a, T* b, int size) {
|
||||
for (int i = 0; i < size; i++) {
|
||||
a[i] = b[i];
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
bool isEqual(T* a, T* b, int size) {
|
||||
for (int i = 0; i < size; i++) {
|
||||
if (a[i] != b[i]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// Main function that tests type
|
||||
// T = what you want to test
|
||||
// D = pack of 1 i.e. float1 int1
|
||||
template <typename T, typename D>
|
||||
void testType(int msize) {
|
||||
T *fa, *fb, *fc, *h_fa, *h_fb;
|
||||
fa = new T[msize];
|
||||
fb = new T[msize];
|
||||
fc = new T[msize];
|
||||
h_fa = new T[msize];
|
||||
h_fb = new T[msize];
|
||||
|
||||
T *d_fa, *d_fb;
|
||||
|
||||
constexpr int c = count<T, D>();
|
||||
|
||||
if (c <= 0 || c >= 5) {
|
||||
failed("Invalid Size\n");
|
||||
}
|
||||
|
||||
fillMatrix<T, D>(fa, msize);
|
||||
dcopy(fb, fa, msize);
|
||||
dcopy(h_fa, fa, msize);
|
||||
dcopy(h_fb, fa, msize);
|
||||
for (int i = 0; i < msize; i++) testOperations<T, D>(h_fa[i], h_fb[i]);
|
||||
|
||||
hipMalloc(&d_fa, sizeof(T) * msize);
|
||||
hipMalloc(&d_fb, sizeof(T) * msize);
|
||||
|
||||
hipMemcpy(d_fa, fa, sizeof(T) * msize, hipMemcpyHostToDevice);
|
||||
hipMemcpy(d_fb, fb, sizeof(T) * msize, hipMemcpyHostToDevice);
|
||||
|
||||
auto kernel = testOperationsGPU<T, D>;
|
||||
hipLaunchKernelGGL(kernel, 1, msize, 0, 0, d_fa, d_fb, msize);
|
||||
|
||||
hipMemcpy(fc, d_fa, sizeof(T) * msize, hipMemcpyDeviceToHost);
|
||||
|
||||
bool pass = true;
|
||||
if (!isEqual<T>(h_fa, fc, msize)) {
|
||||
pass = false;
|
||||
}
|
||||
|
||||
delete[] fa;
|
||||
delete[] fb;
|
||||
delete[] fc;
|
||||
delete[] h_fa;
|
||||
delete[] h_fb;
|
||||
hipFree(d_fa);
|
||||
hipFree(d_fb);
|
||||
|
||||
if (!pass) {
|
||||
failed("Failed");
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
const int msize = 100;
|
||||
// double
|
||||
testType<double1, double1>(msize);
|
||||
testType<double2, double1>(msize);
|
||||
testType<double3, double1>(msize);
|
||||
testType<double4, double1>(msize);
|
||||
|
||||
// floats
|
||||
testType<float1, float1>(msize);
|
||||
testType<float2, float1>(msize);
|
||||
testType<float3, float1>(msize);
|
||||
testType<float4, float1>(msize);
|
||||
|
||||
// ints
|
||||
testType<int1, int1>(msize);
|
||||
testType<int2, int1>(msize);
|
||||
testType<int3, int1>(msize);
|
||||
testType<int4, int1>(msize);
|
||||
|
||||
// chars
|
||||
testType<char1, char1>(msize);
|
||||
testType<char2, char1>(msize);
|
||||
testType<char3, char1>(msize);
|
||||
testType<char4, char1>(msize);
|
||||
|
||||
// long
|
||||
testType<long1, long1>(msize);
|
||||
testType<long2, long1>(msize);
|
||||
testType<long3, long1>(msize);
|
||||
testType<long4, long1>(msize);
|
||||
|
||||
// longlong
|
||||
testType<longlong1, longlong1>(msize);
|
||||
testType<longlong2, longlong1>(msize);
|
||||
testType<longlong3, longlong1>(msize);
|
||||
testType<longlong4, longlong1>(msize);
|
||||
|
||||
// short
|
||||
testType<short1, short1>(msize);
|
||||
testType<short2, short1>(msize);
|
||||
testType<short3, short1>(msize);
|
||||
testType<short4, short1>(msize);
|
||||
|
||||
// uints
|
||||
testType<uint1, uint1>(msize);
|
||||
testType<uint2, uint1>(msize);
|
||||
testType<uint3, uint1>(msize);
|
||||
testType<uint4, uint1>(msize);
|
||||
|
||||
// uchars
|
||||
testType<uchar1, uchar1>(msize);
|
||||
testType<uchar2, uchar1>(msize);
|
||||
testType<uchar3, uchar1>(msize);
|
||||
testType<uchar4, uchar1>(msize);
|
||||
|
||||
// ulong
|
||||
testType<ulong1, ulong1>(msize);
|
||||
testType<ulong2, ulong1>(msize);
|
||||
testType<ulong3, ulong1>(msize);
|
||||
testType<ulong4, ulong1>(msize);
|
||||
|
||||
// ulonglong
|
||||
testType<ulonglong1, ulonglong1>(msize);
|
||||
testType<ulonglong2, ulonglong1>(msize);
|
||||
testType<ulonglong3, ulonglong1>(msize);
|
||||
testType<ulonglong4, ulonglong1>(msize);
|
||||
|
||||
// ushort
|
||||
testType<ushort1, ushort1>(msize);
|
||||
testType<ushort2, ushort1>(msize);
|
||||
testType<ushort3, ushort1>(msize);
|
||||
testType<ushort4, ushort1>(msize);
|
||||
|
||||
passed();
|
||||
}
|
||||
@@ -1,252 +0,0 @@
|
||||
/*
|
||||
Copyright (c) 2021 - 2021 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:
|
||||
|
||||
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.
|
||||
*/
|
||||
|
||||
/* HIT_START
|
||||
* BUILD: %t %s ../test_common.cpp
|
||||
* TEST: %t
|
||||
* HIT_END
|
||||
*/
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <iostream>
|
||||
#include <hip/hip_runtime.h>
|
||||
#include <hip/device_functions.h>
|
||||
|
||||
#define HIP_ASSERT(x) (assert((x) == hipSuccess))
|
||||
|
||||
#define NUM_TESTS 65
|
||||
|
||||
#define HI_INT 0xfacefeed
|
||||
#define LO_INT 0xdeadbeef
|
||||
|
||||
__global__ void funnelshift_kernel(unsigned int* l_out, unsigned int* lc_out,
|
||||
unsigned int* r_out, unsigned int* rc_out) {
|
||||
|
||||
for (int i = 0; i < NUM_TESTS; i++) {
|
||||
l_out[i] = __funnelshift_l(LO_INT, HI_INT, i);
|
||||
lc_out[i] = __funnelshift_lc(LO_INT, HI_INT, i);
|
||||
r_out[i] = __funnelshift_r(LO_INT, HI_INT, i);
|
||||
rc_out[i] = __funnelshift_rc(LO_INT, HI_INT, i);
|
||||
}
|
||||
}
|
||||
|
||||
static unsigned int cpu_funnelshift_l(unsigned int lo, unsigned int hi, unsigned int shift)
|
||||
{
|
||||
// Concatenate hi:lo
|
||||
uint64_t val = hi;
|
||||
val <<= 32;
|
||||
val |= lo;
|
||||
// left shift by intput & 31
|
||||
val <<= (shift & 31);
|
||||
// pull out upper 32 bits and return them
|
||||
val >>= 32;
|
||||
return val & 0xffffffff;
|
||||
}
|
||||
|
||||
static unsigned int cpu_funnelshift_lc(unsigned int lo, unsigned int hi, unsigned int shift)
|
||||
{
|
||||
// Concatenate hi:lo
|
||||
uint64_t val = hi;
|
||||
val <<= 32;
|
||||
val |= lo;
|
||||
// left shift by min(input,32)
|
||||
if (shift > 32)
|
||||
shift = 32;
|
||||
val <<= shift;
|
||||
// pull out upper 32 bits and return them
|
||||
val >>= 32;
|
||||
return val & 0xffffffff;
|
||||
}
|
||||
|
||||
static unsigned int cpu_funnelshift_r(unsigned int lo, unsigned int hi, unsigned int shift)
|
||||
{
|
||||
// Concatenate hi:lo
|
||||
uint64_t val = hi;
|
||||
val <<= 32;
|
||||
val |= lo;
|
||||
// right shift by intput & 31
|
||||
val >>= (shift & 31);
|
||||
// return lower 32 bits
|
||||
return val & 0xffffffff;
|
||||
}
|
||||
|
||||
static unsigned int cpu_funnelshift_rc(unsigned int lo, unsigned int hi, unsigned int shift)
|
||||
{
|
||||
// Concatenate hi:lo
|
||||
uint64_t val = hi;
|
||||
val <<= 32;
|
||||
val |= lo;
|
||||
// left shift by min(input, 32)
|
||||
if (shift > 32)
|
||||
shift = 32;
|
||||
val >>= shift;
|
||||
// return lower 32 bits
|
||||
return val & 0xffffffff;
|
||||
}
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main() {
|
||||
unsigned int *host_l_output;
|
||||
unsigned int *host_lc_output;
|
||||
unsigned int *host_r_output;
|
||||
unsigned int *host_rc_output;
|
||||
|
||||
unsigned int *device_l_output;
|
||||
unsigned int *device_lc_output;
|
||||
unsigned int *device_r_output;
|
||||
unsigned int *device_rc_output;
|
||||
|
||||
unsigned int *golden_l;
|
||||
unsigned int *golden_lc;
|
||||
unsigned int *golden_r;
|
||||
unsigned int *golden_rc;
|
||||
|
||||
hipDeviceProp_t devProp;
|
||||
hipGetDeviceProperties(&devProp, 0);
|
||||
cout << " System minor " << devProp.minor << endl;
|
||||
cout << " System major " << devProp.major << endl;
|
||||
cout << " agent prop name " << devProp.name << endl;
|
||||
|
||||
cout << "hip Device prop succeeded " << endl;
|
||||
|
||||
|
||||
int i;
|
||||
int errors;
|
||||
|
||||
host_l_output = (unsigned int*)calloc(NUM_TESTS, sizeof(unsigned int));
|
||||
host_lc_output = (unsigned int*)calloc(NUM_TESTS, sizeof(unsigned int));
|
||||
host_r_output = (unsigned int*)calloc(NUM_TESTS, sizeof(unsigned int));
|
||||
host_rc_output = (unsigned int*)calloc(NUM_TESTS, sizeof(unsigned int));
|
||||
|
||||
golden_l = (unsigned int*)calloc(NUM_TESTS, sizeof(unsigned int));
|
||||
golden_lc = (unsigned int*)calloc(NUM_TESTS, sizeof(unsigned int));
|
||||
golden_r = (unsigned int*)calloc(NUM_TESTS, sizeof(unsigned int));
|
||||
golden_rc = (unsigned int*)calloc(NUM_TESTS, sizeof(unsigned int));
|
||||
|
||||
for (int i = 0; i < NUM_TESTS; i++) {
|
||||
golden_l[i] = cpu_funnelshift_l(LO_INT, HI_INT, i);
|
||||
golden_lc[i] = cpu_funnelshift_lc(LO_INT, HI_INT, i);
|
||||
golden_r[i] = cpu_funnelshift_r(LO_INT, HI_INT, i);
|
||||
golden_rc[i] = cpu_funnelshift_rc(LO_INT, HI_INT, i);
|
||||
}
|
||||
|
||||
HIP_ASSERT(hipMalloc((void**)&device_l_output, NUM_TESTS * sizeof(unsigned int)));
|
||||
HIP_ASSERT(hipMalloc((void**)&device_lc_output, NUM_TESTS * sizeof(unsigned int)));
|
||||
HIP_ASSERT(hipMalloc((void**)&device_r_output, NUM_TESTS * sizeof(unsigned int)));
|
||||
HIP_ASSERT(hipMalloc((void**)&device_rc_output, NUM_TESTS * sizeof(unsigned int)));
|
||||
|
||||
hipLaunchKernelGGL(funnelshift_kernel, dim3(1), dim3(1), 0, 0,
|
||||
device_l_output, device_lc_output, device_r_output,
|
||||
device_rc_output);
|
||||
|
||||
HIP_ASSERT(hipMemcpy(host_l_output, device_l_output, NUM_TESTS * sizeof(unsigned int), hipMemcpyDeviceToHost));
|
||||
HIP_ASSERT(hipMemcpy(host_lc_output, device_lc_output, NUM_TESTS * sizeof(unsigned int), hipMemcpyDeviceToHost));
|
||||
HIP_ASSERT(hipMemcpy(host_r_output, device_r_output, NUM_TESTS * sizeof(unsigned int), hipMemcpyDeviceToHost));
|
||||
HIP_ASSERT(hipMemcpy(host_rc_output, device_rc_output, NUM_TESTS * sizeof(unsigned int), hipMemcpyDeviceToHost));
|
||||
|
||||
// verify the results
|
||||
errors = 0;
|
||||
printf("HI val: 0x%x\n", HI_INT);
|
||||
printf("LO val: 0x%x\n", LO_INT);
|
||||
|
||||
for (i = 0; i < NUM_TESTS; i++) {
|
||||
printf("gpu_funnelshift_l(%d) = 0x%x, cpu_funnelshift_l(%d) = 0x%x\n",
|
||||
i, host_l_output[i], i, golden_l[i]);
|
||||
if (host_l_output[i] != golden_l[i]) {
|
||||
errors++;
|
||||
printf("\tERROR!\n");
|
||||
}
|
||||
}
|
||||
if (errors != 0) {
|
||||
cout << "FAILED: funnelshift_l" << endl;
|
||||
return -1;
|
||||
} else {
|
||||
cout << "funnelshift_l checked!" << endl;
|
||||
}
|
||||
|
||||
errors = 0;
|
||||
for (i = 0; i < NUM_TESTS; i++) {
|
||||
printf("gpu_funnelshift_lc(%d) = 0x%x, cpu_funnelshift_lc(%d) = 0x%x\n",
|
||||
i, host_lc_output[i], i, golden_lc[i]);
|
||||
if (host_lc_output[i] != golden_lc[i]) {
|
||||
errors++;
|
||||
printf("\tERROR!\n");
|
||||
}
|
||||
}
|
||||
if (errors != 0) {
|
||||
cout << "FAILED: funnelshift_lc" << endl;
|
||||
return -1;
|
||||
} else {
|
||||
cout << "funnelshift_lc checked!" << endl;
|
||||
}
|
||||
|
||||
errors = 0;
|
||||
for (i = 0; i < NUM_TESTS; i++) {
|
||||
printf("gpu_funnelshift_r(%d) = 0x%x, cpu_funnelshift_r(%d) = 0x%x\n",
|
||||
i, host_r_output[i], i, golden_r[i]);
|
||||
if (host_r_output[i] != golden_r[i]) {
|
||||
errors++;
|
||||
printf("\tERROR!\n");
|
||||
}
|
||||
}
|
||||
if (errors != 0) {
|
||||
cout << "FAILED: funnelshift_r" << endl;
|
||||
return -1;
|
||||
} else {
|
||||
cout << "funnelshift_r checked!" << endl;
|
||||
}
|
||||
|
||||
errors = 0;
|
||||
for (i = 0; i < NUM_TESTS; i++) {
|
||||
printf("gpu_funnelshift_rc(%d) = 0x%x, cpu_funnelshift_rc(%d) = 0x%x\n",
|
||||
i, host_rc_output[i], i, golden_rc[i]);
|
||||
if (host_rc_output[i] != golden_rc[i]) {
|
||||
errors++;
|
||||
printf("\tERROR!\n");
|
||||
}
|
||||
}
|
||||
if (errors != 0) {
|
||||
cout << "FAILED: funnelshift_rc" << endl;
|
||||
return -1;
|
||||
} else {
|
||||
cout << "funnelshift_rc checked!" << endl;
|
||||
}
|
||||
errors = 0;
|
||||
|
||||
cout << "funnelshift tests PASSED!" << endl;
|
||||
|
||||
HIP_ASSERT(hipFree(device_l_output));
|
||||
HIP_ASSERT(hipFree(device_lc_output));
|
||||
HIP_ASSERT(hipFree(device_r_output));
|
||||
HIP_ASSERT(hipFree(device_rc_output));
|
||||
|
||||
free(host_l_output);
|
||||
free(host_lc_output);
|
||||
free(host_r_output);
|
||||
free(host_rc_output);
|
||||
|
||||
return errors;
|
||||
}
|
||||
@@ -1,128 +0,0 @@
|
||||
/*
|
||||
Copyright (c) 2015 - 2021 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:
|
||||
|
||||
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.
|
||||
*/
|
||||
|
||||
/* HIT_START
|
||||
* BUILD: %t %s ../test_common.cpp EXCLUDE_HIP_PLATFORM nvidia
|
||||
* TEST: %t
|
||||
* HIT_END
|
||||
*/
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
#include <algorithm>
|
||||
#include <stdlib.h>
|
||||
#include <iostream>
|
||||
#include <hip/hip_runtime.h>
|
||||
#include <hip/device_functions.h>
|
||||
|
||||
#define HIP_ASSERT(x) (assert((x) == hipSuccess))
|
||||
|
||||
__global__ void HIP_kernel(unsigned int* mbcnt_lo, unsigned int* mbcnt_hi, unsigned int* lane_id) {
|
||||
int x = blockDim.x * blockIdx.x + threadIdx.x;
|
||||
mbcnt_lo[x] = __builtin_amdgcn_mbcnt_lo(0xFFFFFFFF, 0);
|
||||
mbcnt_hi[x] = __builtin_amdgcn_mbcnt_hi(0xFFFFFFFF, 0);
|
||||
lane_id[x] = __lane_id();
|
||||
}
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main() {
|
||||
|
||||
unsigned int* device_mbcnt_lo;
|
||||
unsigned int* device_mbcnt_hi;
|
||||
unsigned int* device_lane_id;
|
||||
|
||||
hipDeviceProp_t devProp;
|
||||
hipGetDeviceProperties(&devProp, 0);
|
||||
cout << " System minor " << devProp.minor << endl;
|
||||
cout << " System major " << devProp.major << endl;
|
||||
cout << " agent prop name " << devProp.name << endl;
|
||||
|
||||
cout << "hip Device prop succeeded " << endl;
|
||||
|
||||
constexpr unsigned int num_waves_per_block = 2;
|
||||
const unsigned int wave_size = devProp.warpSize;
|
||||
const unsigned int num_threads_per_block = wave_size * num_waves_per_block;
|
||||
const unsigned int num_blocks = 2;
|
||||
const unsigned int num_threads = num_threads_per_block * num_blocks;
|
||||
const size_t buffer_size = num_threads * sizeof(unsigned int);
|
||||
|
||||
HIP_ASSERT(hipMalloc((void**)&device_mbcnt_lo, buffer_size));
|
||||
HIP_ASSERT(hipMalloc((void**)&device_mbcnt_hi, buffer_size));
|
||||
HIP_ASSERT(hipMalloc((void**)&device_lane_id, buffer_size));
|
||||
|
||||
hipLaunchKernelGGL(HIP_kernel, dim3(num_blocks),
|
||||
dim3(num_threads_per_block), 0, 0, device_mbcnt_lo, device_mbcnt_hi, device_lane_id);
|
||||
|
||||
unsigned int* host_mbcnt_lo = (unsigned int*) malloc(buffer_size);
|
||||
unsigned int* host_mbcnt_hi = (unsigned int*) malloc(buffer_size);
|
||||
unsigned int* host_lane_id = (unsigned int*) malloc(buffer_size);
|
||||
|
||||
HIP_ASSERT(hipMemcpy(host_mbcnt_lo, device_mbcnt_lo, buffer_size, hipMemcpyDeviceToHost));
|
||||
HIP_ASSERT(hipMemcpy(host_mbcnt_hi, device_mbcnt_hi, buffer_size, hipMemcpyDeviceToHost));
|
||||
HIP_ASSERT(hipMemcpy(host_lane_id, device_lane_id, buffer_size, hipMemcpyDeviceToHost));
|
||||
|
||||
// verify the results
|
||||
int mbcnt_lo_errors = 0;
|
||||
int mbcnt_hi_errors = 0;
|
||||
int lane_id_errors = 0;
|
||||
for (unsigned int i = 0; i < num_threads; i++) {
|
||||
unsigned int this_lane_id = i % wave_size;
|
||||
unsigned int this_mbcnt_lo = this_lane_id >= 32 ? 32 : this_lane_id;
|
||||
unsigned int this_mbcnt_hi = this_lane_id < 32 ? 0 : (this_lane_id - 32);
|
||||
|
||||
if (host_mbcnt_lo[i] != this_mbcnt_lo)
|
||||
mbcnt_lo_errors++;
|
||||
|
||||
if (host_mbcnt_hi[i] != this_mbcnt_hi)
|
||||
mbcnt_hi_errors++;
|
||||
|
||||
if (host_lane_id[i] != this_lane_id)
|
||||
lane_id_errors++;
|
||||
}
|
||||
|
||||
if (mbcnt_lo_errors == 0)
|
||||
cout << "__mbcnt_lo() PASSED!" << endl;
|
||||
else
|
||||
cout << "__mbcnt_lo() FAILED!" << endl;
|
||||
|
||||
|
||||
if (mbcnt_hi_errors == 0)
|
||||
cout << "__mbcnt_hi() PASSED!" << endl;
|
||||
else
|
||||
cout << "__mbcnt_hi() FAILED!" << endl;
|
||||
|
||||
if (lane_id_errors == 0)
|
||||
cout << "__lane_id() PASSED!" << endl;
|
||||
else
|
||||
cout << "__lane_id() FAILED!" << endl;
|
||||
|
||||
HIP_ASSERT(hipFree(device_mbcnt_lo));
|
||||
HIP_ASSERT(hipFree(device_mbcnt_hi));
|
||||
HIP_ASSERT(hipFree(device_lane_id));
|
||||
|
||||
free(host_mbcnt_lo);
|
||||
free(host_mbcnt_hi);
|
||||
free(host_lane_id);
|
||||
|
||||
return mbcnt_lo_errors + mbcnt_hi_errors + lane_id_errors;
|
||||
}
|
||||
@@ -1,166 +0,0 @@
|
||||
/*
|
||||
Copyright (c) 2015 - 2021 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:
|
||||
|
||||
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.
|
||||
*/
|
||||
|
||||
/* HIT_START
|
||||
* BUILD: %t %s ../test_common.cpp
|
||||
* TEST: %t
|
||||
* HIT_END
|
||||
*/
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
#include <algorithm>
|
||||
#include <stdlib.h>
|
||||
#include <iostream>
|
||||
#include <hip/hip_runtime.h>
|
||||
#include <hip/device_functions.h>
|
||||
|
||||
#define HIP_ASSERT(x) (assert((x) == hipSuccess))
|
||||
|
||||
|
||||
#define WIDTH 16
|
||||
#define HEIGHT 16
|
||||
|
||||
#define NUM (WIDTH * HEIGHT)
|
||||
|
||||
#define THREADS_PER_BLOCK_X 8
|
||||
#define THREADS_PER_BLOCK_Y 8
|
||||
#define THREADS_PER_BLOCK_Z 1
|
||||
|
||||
|
||||
// CPU implementation of popcount
|
||||
template <typename T>
|
||||
unsigned int popcountCPU(T value) {
|
||||
unsigned int ret = 0;
|
||||
while (value) {
|
||||
if (value & 0x1) ++ret;
|
||||
value >>= 1;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
__global__ void HIP_kernel(unsigned int* a, unsigned int* b, unsigned int* c,
|
||||
unsigned long long int* d, int width, int height) {
|
||||
int x = blockDim.x * blockIdx.x + threadIdx.x;
|
||||
int y = blockDim.y * blockIdx.y + threadIdx.y;
|
||||
|
||||
int i = y * width + x;
|
||||
if (i < (width * height)) {
|
||||
a[i] = __popc(b[i]);
|
||||
c[i] = __popcll(d[i]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main() {
|
||||
unsigned int* hostA;
|
||||
unsigned int* hostB;
|
||||
unsigned int* hostC;
|
||||
unsigned long long int* hostD;
|
||||
|
||||
unsigned int* deviceA;
|
||||
unsigned int* deviceB;
|
||||
unsigned int* deviceC;
|
||||
unsigned long long int* deviceD;
|
||||
|
||||
hipDeviceProp_t devProp;
|
||||
hipGetDeviceProperties(&devProp, 0);
|
||||
cout << " System minor " << devProp.minor << endl;
|
||||
cout << " System major " << devProp.major << endl;
|
||||
cout << " agent prop name " << devProp.name << endl;
|
||||
|
||||
cout << "hip Device prop succeeded " << endl;
|
||||
|
||||
|
||||
int i;
|
||||
int errors;
|
||||
|
||||
hostA = (unsigned int*)malloc(NUM * sizeof(unsigned int));
|
||||
hostB = (unsigned int*)malloc(NUM * sizeof(unsigned int));
|
||||
hostC = (unsigned int*)malloc(NUM * sizeof(unsigned int));
|
||||
hostD = (unsigned long long int*)malloc(NUM * sizeof(unsigned long long int));
|
||||
|
||||
// initialize the input data
|
||||
for (i = 0; i < NUM; i++) {
|
||||
hostB[i] = i;
|
||||
hostD[i] = 1099511627776 - i;
|
||||
}
|
||||
|
||||
HIP_ASSERT(hipMalloc((void**)&deviceA, NUM * sizeof(unsigned int)));
|
||||
HIP_ASSERT(hipMalloc((void**)&deviceB, NUM * sizeof(unsigned int)));
|
||||
HIP_ASSERT(hipMalloc((void**)&deviceC, NUM * sizeof(unsigned int)));
|
||||
HIP_ASSERT(hipMalloc((void**)&deviceD, NUM * sizeof(unsigned long long int)));
|
||||
|
||||
HIP_ASSERT(hipMemcpy(deviceB, hostB, NUM * sizeof(unsigned int), hipMemcpyHostToDevice));
|
||||
HIP_ASSERT(
|
||||
hipMemcpy(deviceD, hostD, NUM * sizeof(unsigned long long int), hipMemcpyHostToDevice));
|
||||
|
||||
|
||||
hipLaunchKernelGGL(HIP_kernel, dim3(WIDTH / THREADS_PER_BLOCK_X, HEIGHT / THREADS_PER_BLOCK_Y),
|
||||
dim3(THREADS_PER_BLOCK_X, THREADS_PER_BLOCK_Y), 0, 0, deviceA, deviceB, deviceC,
|
||||
deviceD, WIDTH, HEIGHT);
|
||||
|
||||
|
||||
HIP_ASSERT(hipMemcpy(hostA, deviceA, NUM * sizeof(unsigned int), hipMemcpyDeviceToHost));
|
||||
HIP_ASSERT(hipMemcpy(hostC, deviceC, NUM * sizeof(unsigned int), hipMemcpyDeviceToHost));
|
||||
// verify the results
|
||||
errors = 0;
|
||||
for (i = 0; i < NUM; i++) {
|
||||
if (hostA[i] != popcountCPU(hostB[i])) {
|
||||
errors++;
|
||||
}
|
||||
}
|
||||
if (errors != 0) {
|
||||
cout << "FAILED: popc" << endl;
|
||||
return -1;
|
||||
} else {
|
||||
cout << "__popc() checked!" << endl;
|
||||
}
|
||||
errors = 0;
|
||||
for (i = 0; i < NUM; i++) {
|
||||
if (hostC[i] != popcountCPU(hostD[i])) {
|
||||
errors++;
|
||||
}
|
||||
}
|
||||
if (errors != 0) {
|
||||
cout << "FAILED:popc" << endl;
|
||||
return -1;
|
||||
} else {
|
||||
cout << "__popcll() checked!" << endl;
|
||||
}
|
||||
|
||||
cout << "popc test PASSED!" << endl;
|
||||
|
||||
HIP_ASSERT(hipFree(deviceA));
|
||||
HIP_ASSERT(hipFree(deviceB));
|
||||
HIP_ASSERT(hipFree(deviceC));
|
||||
HIP_ASSERT(hipFree(deviceD));
|
||||
|
||||
free(hostA);
|
||||
free(hostB);
|
||||
free(hostC);
|
||||
free(hostD);
|
||||
|
||||
return errors;
|
||||
}
|
||||
@@ -1,332 +0,0 @@
|
||||
/*
|
||||
Copyright (c) 2015 - 2021 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:
|
||||
|
||||
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.
|
||||
*/
|
||||
|
||||
/* HIT_START
|
||||
* BUILD: %t %s ../test_common.cpp NVCC_OPTIONS --gpu-architecture=sm_35
|
||||
* TEST: %t
|
||||
* HIT_END
|
||||
*/
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
#include <algorithm>
|
||||
#include <stdlib.h>
|
||||
#include <iostream>
|
||||
#include "hip/hip_runtime.h"
|
||||
#include "hip/hip_vector_types.h"
|
||||
#include "test_common.h"
|
||||
|
||||
#if defined(__HIP_PLATFORM_NVIDIA__) || defined(__HIP_CLANG_ONLY__)
|
||||
|
||||
#define HIP_ASSERT(x) (assert((x) == hipSuccess))
|
||||
|
||||
|
||||
#define WIDTH 8
|
||||
#define HEIGHT 8
|
||||
|
||||
#define NUM (WIDTH * HEIGHT)
|
||||
|
||||
#define THREADS_PER_BLOCK_X 8
|
||||
#define THREADS_PER_BLOCK_Y 8
|
||||
#define THREADS_PER_BLOCK_Z 1
|
||||
|
||||
using namespace std;
|
||||
|
||||
template <typename T>
|
||||
__global__ void vectoradd_float(T* a, const T* bm, int width, int height)
|
||||
|
||||
{
|
||||
int x = blockDim.x * blockIdx.x + threadIdx.x;
|
||||
int y = blockDim.y * blockIdx.y + threadIdx.y;
|
||||
|
||||
int i = y * width + x;
|
||||
if (i < (width * height)) {
|
||||
a[i] = __ldg(&bm[i]);
|
||||
}
|
||||
}
|
||||
|
||||
int2 make_vector2(int a) { return make_int2(a, a); }
|
||||
|
||||
char2 make_vector2(signed char a) { return make_char2(a, a); }
|
||||
|
||||
char4 make_vector4(signed char a) { return make_char4(a, a, a, a); }
|
||||
|
||||
short2 make_vector2(short a) { return make_short2(a, a); }
|
||||
|
||||
ushort2 make_vector2(unsigned short a) { return make_ushort2(a, a); }
|
||||
|
||||
short4 make_vector4(short a) { return make_short4(a, a, a, a); }
|
||||
|
||||
int4 make_vector4(int a) { return make_int4(a, a, a, a); }
|
||||
|
||||
uint2 make_vector2(unsigned int a) { return make_uint2(a, a); }
|
||||
|
||||
uint4 make_vector4(unsigned int a) { return make_uint4(a, a, a, a); }
|
||||
|
||||
float2 make_vector2(float a) { return make_float2(a, a); }
|
||||
|
||||
float4 make_vector4(float a) { return make_float4(a, a, a, a); }
|
||||
|
||||
uchar2 make_vector2(unsigned char a) { return make_uchar2(a, a); }
|
||||
|
||||
uchar4 make_vector4(unsigned char a) { return make_uchar4(a, a, a, a); }
|
||||
|
||||
double2 make_vector2(double a) { return make_double2(a, a); }
|
||||
|
||||
|
||||
template <typename T, typename U>
|
||||
bool dataTypesRun() {
|
||||
T* hostA;
|
||||
T* hostB;
|
||||
|
||||
|
||||
T* deviceA;
|
||||
T* deviceB;
|
||||
|
||||
|
||||
int i;
|
||||
int errors;
|
||||
|
||||
hostA = (T*)malloc(NUM * sizeof(T));
|
||||
hostB = (T*)malloc(NUM * sizeof(T));
|
||||
|
||||
// initialize the input data
|
||||
for (i = 0; i < NUM; i++) {
|
||||
hostB[i] = (U)i;
|
||||
}
|
||||
|
||||
HIP_ASSERT(hipMalloc((void**)&deviceA, NUM * sizeof(T)));
|
||||
HIP_ASSERT(hipMalloc((void**)&deviceB, NUM * sizeof(T)));
|
||||
|
||||
HIP_ASSERT(hipMemcpy(deviceB, hostB, NUM * sizeof(T), hipMemcpyHostToDevice));
|
||||
|
||||
|
||||
hipLaunchKernelGGL(vectoradd_float,
|
||||
dim3(WIDTH / THREADS_PER_BLOCK_X, HEIGHT / THREADS_PER_BLOCK_Y),
|
||||
dim3(THREADS_PER_BLOCK_X, THREADS_PER_BLOCK_Y), 0, 0, deviceA,
|
||||
static_cast<const T*>(deviceB), WIDTH, HEIGHT);
|
||||
|
||||
|
||||
HIP_ASSERT(hipMemcpy(hostA, deviceA, NUM * sizeof(T), hipMemcpyDeviceToHost));
|
||||
|
||||
bool ret = false;
|
||||
// verify the results
|
||||
errors = 0;
|
||||
for (i = 0; i < NUM; i++) {
|
||||
if (hostA[i] != (hostB[i])) {
|
||||
errors++;
|
||||
}
|
||||
}
|
||||
if (errors != 0) {
|
||||
std::cout << "FAILED\n" << std::endl;
|
||||
ret = false;
|
||||
} else {
|
||||
ret = true;
|
||||
}
|
||||
|
||||
HIP_ASSERT(hipFree(deviceA));
|
||||
HIP_ASSERT(hipFree(deviceB));
|
||||
|
||||
free(hostA);
|
||||
free(hostB);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
template <typename T, typename U>
|
||||
bool dataTypesRun2() {
|
||||
T* hostA;
|
||||
T* hostB;
|
||||
|
||||
|
||||
T* deviceA;
|
||||
T* deviceB;
|
||||
|
||||
|
||||
int i;
|
||||
int errors;
|
||||
|
||||
hostA = (T*)malloc(NUM * sizeof(T));
|
||||
hostB = (T*)malloc(NUM * sizeof(T));
|
||||
|
||||
// initialize the input data
|
||||
for (i = 0; i < NUM; i++) {
|
||||
hostB[i] = make_vector2((U)i);
|
||||
}
|
||||
|
||||
HIP_ASSERT(hipMalloc((void**)&deviceA, NUM * sizeof(T)));
|
||||
HIP_ASSERT(hipMalloc((void**)&deviceB, NUM * sizeof(T)));
|
||||
|
||||
HIP_ASSERT(hipMemcpy(deviceB, hostB, NUM * sizeof(T), hipMemcpyHostToDevice));
|
||||
hipLaunchKernelGGL(vectoradd_float,
|
||||
dim3(WIDTH / THREADS_PER_BLOCK_X, HEIGHT / THREADS_PER_BLOCK_Y),
|
||||
dim3(THREADS_PER_BLOCK_X, THREADS_PER_BLOCK_Y), 0, 0, deviceA,
|
||||
static_cast<const T*>(deviceB), WIDTH, HEIGHT);
|
||||
|
||||
|
||||
HIP_ASSERT(hipMemcpy(hostA, deviceA, NUM * sizeof(T), hipMemcpyDeviceToHost));
|
||||
|
||||
bool ret = false;
|
||||
// verify the results
|
||||
errors = 0;
|
||||
for (i = 0; i < NUM; i++) {
|
||||
if (hostA[i].x != (hostB[i].x) && hostA[i].y != (hostB[i].y)) {
|
||||
errors++;
|
||||
}
|
||||
}
|
||||
if (errors != 0) {
|
||||
std::cout << "FAILED\n" << std::endl;
|
||||
ret = false;
|
||||
} else {
|
||||
ret = true;
|
||||
}
|
||||
|
||||
HIP_ASSERT(hipFree(deviceA));
|
||||
HIP_ASSERT(hipFree(deviceB));
|
||||
|
||||
free(hostA);
|
||||
free(hostB);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
template <typename T, typename U>
|
||||
bool dataTypesRun4() {
|
||||
T* hostA;
|
||||
T* hostB;
|
||||
|
||||
T* deviceA;
|
||||
T* deviceB;
|
||||
|
||||
int i;
|
||||
int errors;
|
||||
|
||||
hostA = (T*)malloc(NUM * sizeof(T));
|
||||
hostB = (T*)malloc(NUM * sizeof(T));
|
||||
|
||||
// initialize the input data
|
||||
for (i = 0; i < NUM; i++) {
|
||||
hostB[i] = make_vector4((U)i);
|
||||
}
|
||||
|
||||
HIP_ASSERT(hipMalloc((void**)&deviceA, NUM * sizeof(T)));
|
||||
HIP_ASSERT(hipMalloc((void**)&deviceB, NUM * sizeof(T)));
|
||||
|
||||
HIP_ASSERT(hipMemcpy(deviceB, hostB, NUM * sizeof(T), hipMemcpyHostToDevice));
|
||||
|
||||
|
||||
hipLaunchKernelGGL(vectoradd_float,
|
||||
dim3(WIDTH / THREADS_PER_BLOCK_X, HEIGHT / THREADS_PER_BLOCK_Y),
|
||||
dim3(THREADS_PER_BLOCK_X, THREADS_PER_BLOCK_Y), 0, 0, deviceA,
|
||||
static_cast<const T*>(deviceB), WIDTH, HEIGHT);
|
||||
|
||||
|
||||
HIP_ASSERT(hipMemcpy(hostA, deviceA, NUM * sizeof(T), hipMemcpyDeviceToHost));
|
||||
|
||||
bool ret = false;
|
||||
// verify the results
|
||||
errors = 0;
|
||||
for (i = 0; i < NUM; i++) {
|
||||
if (hostA[i].x != (hostB[i].x) && hostA[i].y != (hostB[i].y) &&
|
||||
hostA[i].z != (hostB[i].z) && hostA[i].w != (hostB[i].w)) {
|
||||
errors++;
|
||||
}
|
||||
}
|
||||
if (errors != 0) {
|
||||
std::cout << "FAILED\n" << std::endl;
|
||||
ret = false;
|
||||
} else {
|
||||
ret = true;
|
||||
}
|
||||
|
||||
HIP_ASSERT(hipFree(deviceA));
|
||||
HIP_ASSERT(hipFree(deviceB));
|
||||
|
||||
free(hostA);
|
||||
free(hostB);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int main() {
|
||||
hipDeviceProp_t devProp;
|
||||
hipGetDeviceProperties(&devProp, 0);
|
||||
cout << " System minor " << devProp.minor << endl;
|
||||
cout << " System major " << devProp.major << endl;
|
||||
cout << " agent prop name " << devProp.name << endl;
|
||||
|
||||
int errors;
|
||||
|
||||
errors =
|
||||
dataTypesRun<char, char>() & dataTypesRun<short, short>() & dataTypesRun<int, int>() &
|
||||
dataTypesRun<long, long>() & dataTypesRun<long long, long long>() &
|
||||
dataTypesRun<signed char, signed char>() & dataTypesRun<unsigned char, unsigned char>() &
|
||||
dataTypesRun<unsigned short, unsigned short>() &
|
||||
dataTypesRun<unsigned int, unsigned int>() & dataTypesRun<unsigned long, unsigned long>() &
|
||||
dataTypesRun<unsigned long long, unsigned long long>() & dataTypesRun<float, float>() &
|
||||
dataTypesRun<double, double>();
|
||||
|
||||
if (errors == 1) {
|
||||
errors = 0;
|
||||
std::cout << "ldg working for single element data types\n" << std::endl;
|
||||
} else {
|
||||
std::cout << "Failed single element data types" << std::endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
#if 1
|
||||
errors = dataTypesRun2<int2, int>() & dataTypesRun2<short2, short>() &
|
||||
dataTypesRun2<ushort2, unsigned short>() & dataTypesRun2<char2, signed char>() &
|
||||
dataTypesRun2<uchar2, unsigned char>() & dataTypesRun2<uint2, unsigned int>() &
|
||||
dataTypesRun2<float2, float>() & dataTypesRun2<double2, double>();
|
||||
|
||||
if (errors == 1) {
|
||||
errors = 0;
|
||||
std::cout << "ldg working for two element data types\n" << std::endl;
|
||||
} else {
|
||||
std::cout << "Failed two element vector data types" << std::endl;
|
||||
return -1;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#if 1
|
||||
|
||||
errors = dataTypesRun4<int4, int>() & dataTypesRun4<char4, signed char>() &
|
||||
dataTypesRun4<uchar4, unsigned char>() & dataTypesRun4<short4, short>() &
|
||||
dataTypesRun4<uint4, unsigned int>() & dataTypesRun4<float4, float>();
|
||||
|
||||
if (errors == 1) {
|
||||
errors = 0;
|
||||
std::cout << "ldg working for four element data types\n" << std::endl;
|
||||
} else {
|
||||
std::cout << "Failed four element vector data types" << std::endl;
|
||||
return -1;
|
||||
}
|
||||
#endif
|
||||
|
||||
std::cout << "ldg test PASSED \n" << std::endl;
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,383 +0,0 @@
|
||||
/*
|
||||
Copyright (c) 2015 - 2021 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:
|
||||
|
||||
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.
|
||||
*/
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
#include <algorithm>
|
||||
#include <stdlib.h>
|
||||
#include <iostream>
|
||||
#include "hip/hip_runtime.h"
|
||||
#include "test_common.h"
|
||||
|
||||
#define HIP_ASSERT(x) (assert((x) == hipSuccess))
|
||||
|
||||
|
||||
#define WIDTH 8
|
||||
#define HEIGHT 8
|
||||
|
||||
#define NUM (WIDTH * HEIGHT)
|
||||
|
||||
#define THREADS_PER_BLOCK_X 8
|
||||
#define THREADS_PER_BLOCK_Y 8
|
||||
#define THREADS_PER_BLOCK_Z 1
|
||||
|
||||
|
||||
__global__ void vectoradd_char1(hipLaunchParm lp, char1* a, const char1* bm, const char1* cm,
|
||||
int width, int height)
|
||||
|
||||
{
|
||||
int x = blockDim.x * blockIdx.x + threadIdx.x;
|
||||
int y = blockDim.y * blockIdx.y + threadIdx.y;
|
||||
|
||||
int i = y * width + x;
|
||||
if (i < (width * height)) {
|
||||
a[i] = make_char1(bm[i].x) + make_char1(cm[i].x);
|
||||
}
|
||||
}
|
||||
|
||||
__global__ void vectoradd_char2(hipLaunchParm lp, char2* a, const char2* bm, const char2* cm,
|
||||
int width, int height)
|
||||
|
||||
{
|
||||
int x = blockDim.x * blockIdx.x + threadIdx.x;
|
||||
int y = blockDim.y * blockIdx.y + threadIdx.y;
|
||||
|
||||
int i = y * width + x;
|
||||
if (i < (width * height)) {
|
||||
a[i] = make_char2(bm[i].x, bm[i].y) + make_char2(cm[i].x, cm[i].y);
|
||||
}
|
||||
}
|
||||
|
||||
__global__ void vectoradd_char3(hipLaunchParm lp, char3* a, const char3* bm, const char3* cm,
|
||||
int width, int height)
|
||||
|
||||
{
|
||||
int x = blockDim.x * blockIdx.x + threadIdx.x;
|
||||
int y = blockDim.y * blockIdx.y + threadIdx.y;
|
||||
|
||||
int i = y * width + x;
|
||||
if (i < (width * height)) {
|
||||
a[i] = make_char3(bm[i].x, bm[i].y, bm[i].z) + make_char3(cm[i].x, cm[i].y, cm[i].z);
|
||||
}
|
||||
}
|
||||
__global__ void vectoradd_char4(hipLaunchParm lp, char4* a, const char4* bm, const char4* cm,
|
||||
int width, int height)
|
||||
|
||||
{
|
||||
int x = blockDim.x * blockIdx.x + threadIdx.x;
|
||||
int y = blockDim.y * blockIdx.y + threadIdx.y;
|
||||
|
||||
int i = y * width + x;
|
||||
if (i < (width * height)) {
|
||||
a[i] = make_char4(bm[i].x, bm[i].y, bm[i].z, bm[i].w) +
|
||||
make_char4(cm[i].x, cm[i].y, cm[i].z, cm[i].w);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#if 0
|
||||
__kernel__ void vectoradd_float(float* a, const float* b, const float* c, int width, int height) {
|
||||
|
||||
|
||||
int x = blockDimX * blockIdx.x + threadIdx.x;
|
||||
int y = blockDimY * blockIdy.y + threadIdx.y;
|
||||
|
||||
int i = y * width + x;
|
||||
if ( i < (width * height)) {
|
||||
a[i] = b[i] + c[i];
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
using namespace std;
|
||||
|
||||
template <typename T>
|
||||
bool dataTypesRun() {
|
||||
T* hostA;
|
||||
T* hostB;
|
||||
T* hostC;
|
||||
|
||||
T* deviceA;
|
||||
T* deviceB;
|
||||
T* deviceC;
|
||||
|
||||
int i;
|
||||
int errors;
|
||||
|
||||
hostA = (T*)malloc(NUM * sizeof(T));
|
||||
hostB = (T*)malloc(NUM * sizeof(T));
|
||||
hostC = (T*)malloc(NUM * sizeof(T));
|
||||
|
||||
// initialize the input data
|
||||
for (i = 0; i < NUM; i++) {
|
||||
hostB[i] = (T)i;
|
||||
hostC[i] = (T)i;
|
||||
}
|
||||
|
||||
HIP_ASSERT(hipMalloc((void**)&deviceA, NUM * sizeof(T)));
|
||||
HIP_ASSERT(hipMalloc((void**)&deviceB, NUM * sizeof(T)));
|
||||
HIP_ASSERT(hipMalloc((void**)&deviceC, NUM * sizeof(T)));
|
||||
|
||||
HIP_ASSERT(hipMemcpy(deviceB, hostB, NUM * sizeof(T), hipMemcpyHostToDevice));
|
||||
HIP_ASSERT(hipMemcpy(deviceC, hostC, NUM * sizeof(T), hipMemcpyHostToDevice));
|
||||
|
||||
hipLaunchKernel(HIP_KERNEL_NAME(vectoradd_char1),
|
||||
dim3(WIDTH / THREADS_PER_BLOCK_X, HEIGHT / THREADS_PER_BLOCK_Y),
|
||||
dim3(THREADS_PER_BLOCK_X, THREADS_PER_BLOCK_Y), 0, 0, deviceA, deviceB, deviceC,
|
||||
WIDTH, HEIGHT);
|
||||
|
||||
HIP_ASSERT(hipMemcpy(hostA, deviceA, NUM * sizeof(T), hipMemcpyDeviceToHost));
|
||||
|
||||
bool ret = false;
|
||||
// verify the results
|
||||
errors = 0;
|
||||
for (i = 0; i < NUM; i++) {
|
||||
if (hostA[i] != (hostB[i] + hostC[i])) {
|
||||
errors++;
|
||||
}
|
||||
}
|
||||
if (errors != 0) {
|
||||
printf("FAILED: %d errors\n", errors);
|
||||
ret = false;
|
||||
} else {
|
||||
ret = true;
|
||||
}
|
||||
|
||||
HIP_ASSERT(hipFree(deviceA));
|
||||
HIP_ASSERT(hipFree(deviceB));
|
||||
HIP_ASSERT(hipFree(deviceC));
|
||||
|
||||
free(hostA);
|
||||
free(hostB);
|
||||
free(hostC);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
bool dataTypesRun() {
|
||||
T* hostA;
|
||||
T* hostB;
|
||||
T* hostC;
|
||||
|
||||
T* deviceA;
|
||||
T* deviceB;
|
||||
T* deviceC;
|
||||
|
||||
int i;
|
||||
int errors;
|
||||
|
||||
hostA = (T*)malloc(NUM * sizeof(T));
|
||||
hostB = (T*)malloc(NUM * sizeof(T));
|
||||
hostC = (T*)malloc(NUM * sizeof(T));
|
||||
|
||||
// initialize the input data
|
||||
for (i = 0; i < NUM; i++) {
|
||||
hostB[i] = (T)i;
|
||||
hostC[i] = (T)i;
|
||||
}
|
||||
|
||||
HIP_ASSERT(hipMalloc((void**)&deviceA, NUM * sizeof(T)));
|
||||
HIP_ASSERT(hipMalloc((void**)&deviceB, NUM * sizeof(T)));
|
||||
HIP_ASSERT(hipMalloc((void**)&deviceC, NUM * sizeof(T)));
|
||||
|
||||
HIP_ASSERT(hipMemcpy(deviceB, hostB, NUM * sizeof(T), hipMemcpyHostToDevice));
|
||||
HIP_ASSERT(hipMemcpy(deviceC, hostC, NUM * sizeof(T), hipMemcpyHostToDevice));
|
||||
|
||||
hipLaunchKernel(HIP_KERNEL_NAME(vectoradd_char1),
|
||||
dim3(WIDTH / THREADS_PER_BLOCK_X, HEIGHT / THREADS_PER_BLOCK_Y),
|
||||
dim3(THREADS_PER_BLOCK_X, THREADS_PER_BLOCK_Y), 0, 0, deviceA, deviceB, deviceC,
|
||||
WIDTH, HEIGHT);
|
||||
|
||||
HIP_ASSERT(hipMemcpy(hostA, deviceA, NUM * sizeof(T), hipMemcpyDeviceToHost));
|
||||
|
||||
bool ret = false;
|
||||
// verify the results
|
||||
errors = 0;
|
||||
for (i = 0; i < NUM; i++) {
|
||||
if (hostA[i] != (hostB[i] + hostC[i])) {
|
||||
errors++;
|
||||
}
|
||||
}
|
||||
if (errors != 0) {
|
||||
printf("FAILED: %d errors\n", errors);
|
||||
ret = false;
|
||||
} else {
|
||||
ret = true;
|
||||
}
|
||||
|
||||
HIP_ASSERT(hipFree(deviceA));
|
||||
HIP_ASSERT(hipFree(deviceB));
|
||||
HIP_ASSERT(hipFree(deviceC));
|
||||
|
||||
free(hostA);
|
||||
free(hostB);
|
||||
free(hostC);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
bool dataTypesRun() {
|
||||
T* hostA;
|
||||
T* hostB;
|
||||
T* hostC;
|
||||
|
||||
T* deviceA;
|
||||
T* deviceB;
|
||||
T* deviceC;
|
||||
|
||||
int i;
|
||||
int errors;
|
||||
|
||||
hostA = (T*)malloc(NUM * sizeof(T));
|
||||
hostB = (T*)malloc(NUM * sizeof(T));
|
||||
hostC = (T*)malloc(NUM * sizeof(T));
|
||||
|
||||
// initialize the input data
|
||||
for (i = 0; i < NUM; i++) {
|
||||
hostB[i] = (T)i;
|
||||
hostC[i] = (T)i;
|
||||
}
|
||||
|
||||
HIP_ASSERT(hipMalloc((void**)&deviceA, NUM * sizeof(T)));
|
||||
HIP_ASSERT(hipMalloc((void**)&deviceB, NUM * sizeof(T)));
|
||||
HIP_ASSERT(hipMalloc((void**)&deviceC, NUM * sizeof(T)));
|
||||
|
||||
HIP_ASSERT(hipMemcpy(deviceB, hostB, NUM * sizeof(T), hipMemcpyHostToDevice));
|
||||
HIP_ASSERT(hipMemcpy(deviceC, hostC, NUM * sizeof(T), hipMemcpyHostToDevice));
|
||||
|
||||
hipLaunchKernel(HIP_KERNEL_NAME(vectoradd_char1),
|
||||
dim3(WIDTH / THREADS_PER_BLOCK_X, HEIGHT / THREADS_PER_BLOCK_Y),
|
||||
dim3(THREADS_PER_BLOCK_X, THREADS_PER_BLOCK_Y), 0, 0, deviceA, deviceB, deviceC,
|
||||
WIDTH, HEIGHT);
|
||||
|
||||
HIP_ASSERT(hipMemcpy(hostA, deviceA, NUM * sizeof(T), hipMemcpyDeviceToHost));
|
||||
|
||||
bool ret = false;
|
||||
// verify the results
|
||||
errors = 0;
|
||||
for (i = 0; i < NUM; i++) {
|
||||
if (hostA[i] != (hostB[i] + hostC[i])) {
|
||||
errors++;
|
||||
}
|
||||
}
|
||||
if (errors != 0) {
|
||||
printf("FAILED: %d errors\n", errors);
|
||||
ret = false;
|
||||
} else {
|
||||
ret = true;
|
||||
}
|
||||
|
||||
HIP_ASSERT(hipFree(deviceA));
|
||||
HIP_ASSERT(hipFree(deviceB));
|
||||
HIP_ASSERT(hipFree(deviceC));
|
||||
|
||||
free(hostA);
|
||||
free(hostB);
|
||||
free(hostC);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool dataTypesRunChar4() {
|
||||
char4* hostA;
|
||||
char4* hostB;
|
||||
char4* hostC;
|
||||
|
||||
char4* deviceA;
|
||||
char4* deviceB;
|
||||
char4* deviceC;
|
||||
|
||||
int i;
|
||||
int errors;
|
||||
|
||||
hostA = (T*)malloc(NUM * sizeof(T));
|
||||
hostB = (T*)malloc(NUM * sizeof(T));
|
||||
hostC = (T*)malloc(NUM * sizeof(T));
|
||||
|
||||
// initialize the input data
|
||||
for (i = 0; i < NUM; i++) {
|
||||
hostB[i] = (T)i;
|
||||
hostC[i] = (T)i;
|
||||
}
|
||||
|
||||
HIP_ASSERT(hipMalloc((void**)&deviceA, NUM * sizeof(T)));
|
||||
HIP_ASSERT(hipMalloc((void**)&deviceB, NUM * sizeof(T)));
|
||||
HIP_ASSERT(hipMalloc((void**)&deviceC, NUM * sizeof(T)));
|
||||
|
||||
HIP_ASSERT(hipMemcpy(deviceB, hostB, NUM * sizeof(T), hipMemcpyHostToDevice));
|
||||
HIP_ASSERT(hipMemcpy(deviceC, hostC, NUM * sizeof(T), hipMemcpyHostToDevice));
|
||||
|
||||
hipLaunchKernel(HIP_KERNEL_NAME(vectoradd_char1),
|
||||
dim3(WIDTH / THREADS_PER_BLOCK_X, HEIGHT / THREADS_PER_BLOCK_Y),
|
||||
dim3(THREADS_PER_BLOCK_X, THREADS_PER_BLOCK_Y), 0, 0, deviceA, deviceB, deviceC,
|
||||
WIDTH, HEIGHT);
|
||||
|
||||
HIP_ASSERT(hipMemcpy(hostA, deviceA, NUM * sizeof(T), hipMemcpyDeviceToHost));
|
||||
|
||||
bool ret = false;
|
||||
// verify the results
|
||||
errors = 0;
|
||||
for (i = 0; i < NUM; i++) {
|
||||
if (hostA[i] != (hostB[i] + hostC[i])) {
|
||||
errors++;
|
||||
}
|
||||
}
|
||||
if (errors != 0) {
|
||||
printf("FAILED: %d errors\n", errors);
|
||||
ret = false;
|
||||
} else {
|
||||
ret = true;
|
||||
}
|
||||
|
||||
HIP_ASSERT(hipFree(deviceA));
|
||||
HIP_ASSERT(hipFree(deviceB));
|
||||
HIP_ASSERT(hipFree(deviceC));
|
||||
|
||||
free(hostA);
|
||||
free(hostB);
|
||||
free(hostC);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int main() {
|
||||
hipDeviceProp_t devProp;
|
||||
hipGetDeviceProperties(&devProp, 0);
|
||||
cout << " System minor " << devProp.minor << endl;
|
||||
cout << " System major " << devProp.major << endl;
|
||||
cout << " agent prop name " << devProp.name << endl;
|
||||
|
||||
int errors;
|
||||
|
||||
errors = dataTypesRun<char1>() & dataTypesRun<char2>() & dataTypesRun<char3>() &
|
||||
dataTypesRun<char4>();
|
||||
|
||||
|
||||
// hipResetDefaultAccelerator();
|
||||
if (errors == 1) {
|
||||
passed();
|
||||
} else {
|
||||
std::cout << "Failed Float" << std::endl;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
@@ -1,155 +0,0 @@
|
||||
/*
|
||||
Copyright (c) 2020 - 2021 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:
|
||||
|
||||
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.
|
||||
*/
|
||||
|
||||
|
||||
/* HIT_START
|
||||
* BUILD: %t %s ../test_common.cpp
|
||||
* TEST: %t
|
||||
* HIT_END
|
||||
*/
|
||||
|
||||
#include <hip/hip_runtime.h>
|
||||
#include "test_common.h"
|
||||
|
||||
#define ASSERT_EQUAL(lhs, rhs) assert(lhs == rhs)
|
||||
|
||||
static __global__
|
||||
void kernel_syncthreads_and(int *syncTestD,
|
||||
int *allThreadsZeroD,
|
||||
int *allThreadsOneD,
|
||||
int *oneThreadZeroD,
|
||||
int *allThreadsMinusOneD)
|
||||
{
|
||||
int blockSize = blockDim.x;
|
||||
int predicate = 10;
|
||||
// First block index starts with 0, and second block index starts
|
||||
// with blockSize
|
||||
int i = (blockIdx.x == 0) ? threadIdx.x : blockSize + threadIdx.x;
|
||||
|
||||
// At very first, we need to ensure work-group level syncronization
|
||||
// properly happened, don't bother about predicate testing for now.
|
||||
// Thread 0 and thread 1 writes to shared memory. After call to api,
|
||||
// every thread reads shared memory, and store product for verification
|
||||
__shared__ int sm[2];
|
||||
if (threadIdx.x == 0)
|
||||
sm[0] = 10;
|
||||
else if (threadIdx.x == 1)
|
||||
sm[1] = 20;
|
||||
__syncthreads_and(predicate);
|
||||
syncTestD[i] = sm[0] * sm[1];
|
||||
|
||||
// All threads pass 0 as predicate value, result should be 0
|
||||
predicate = 0;
|
||||
allThreadsZeroD[i] = __syncthreads_and(predicate);
|
||||
|
||||
// All threads pass 1 as predicate value, result should be 1
|
||||
predicate = 1;
|
||||
allThreadsOneD[i] = __syncthreads_and(predicate);
|
||||
|
||||
// Thread 0 pass 0, and all other threads 1 as predicate value,
|
||||
// result should be 0
|
||||
predicate = (threadIdx.x == 0) ? 0 : 1;
|
||||
oneThreadZeroD[i] = __syncthreads_and(predicate);
|
||||
|
||||
// All threads pass -1 as predicate value, result should be 1
|
||||
predicate = -1;
|
||||
allThreadsMinusOneD[i] = __syncthreads_and(predicate);
|
||||
}
|
||||
|
||||
static void test_syncthreads_and(int blockSize)
|
||||
{
|
||||
int nBytes = sizeof(int) * 2 * blockSize;
|
||||
int * syncTestD, *syncTestH;
|
||||
int *allThreadsZeroD, *allThreadsZeroH;
|
||||
int *allThreadsOneD, *allThreadsOneH;
|
||||
int *oneThreadZeroD, *oneThreadZeroH;
|
||||
int *allThreadsMinusOneD, *allThreadsMinusOneH;
|
||||
|
||||
// Allocate device memory
|
||||
ASSERT_EQUAL(hipMalloc((void**)&syncTestD, nBytes), hipSuccess);
|
||||
ASSERT_EQUAL(hipMalloc((void**)&allThreadsZeroD, nBytes), hipSuccess);
|
||||
ASSERT_EQUAL(hipMalloc((void**)&allThreadsOneD, nBytes), hipSuccess);
|
||||
ASSERT_EQUAL(hipMalloc((void**)&oneThreadZeroD, nBytes), hipSuccess);
|
||||
ASSERT_EQUAL(hipMalloc((void**)&allThreadsMinusOneD, nBytes), hipSuccess);
|
||||
|
||||
// Allocate host memory
|
||||
ASSERT_EQUAL(hipHostMalloc((void**)&syncTestH, nBytes), hipSuccess);
|
||||
ASSERT_EQUAL(hipHostMalloc((void**)&allThreadsZeroH, nBytes), hipSuccess);
|
||||
ASSERT_EQUAL(hipHostMalloc((void**)&allThreadsOneH, nBytes), hipSuccess);
|
||||
ASSERT_EQUAL(hipHostMalloc((void**)&oneThreadZeroH, nBytes), hipSuccess);
|
||||
ASSERT_EQUAL(hipHostMalloc((void**)&allThreadsMinusOneH, nBytes), hipSuccess);
|
||||
|
||||
// Launch Kernel
|
||||
hipLaunchKernelGGL(kernel_syncthreads_and,
|
||||
2,
|
||||
blockSize,
|
||||
0,
|
||||
0,
|
||||
syncTestD,
|
||||
allThreadsZeroD,
|
||||
allThreadsOneD,
|
||||
oneThreadZeroD,
|
||||
allThreadsMinusOneD);
|
||||
|
||||
// Copy result from device to host
|
||||
ASSERT_EQUAL(hipMemcpy(syncTestH, syncTestD, nBytes, hipMemcpyDeviceToHost),
|
||||
hipSuccess);
|
||||
ASSERT_EQUAL(hipMemcpy(allThreadsZeroH, allThreadsZeroD, nBytes, hipMemcpyDeviceToHost),
|
||||
hipSuccess);
|
||||
ASSERT_EQUAL(hipMemcpy(allThreadsOneH, allThreadsOneD, nBytes, hipMemcpyDeviceToHost),
|
||||
hipSuccess);
|
||||
ASSERT_EQUAL(hipMemcpy(oneThreadZeroH, oneThreadZeroD, nBytes, hipMemcpyDeviceToHost),
|
||||
hipSuccess);
|
||||
ASSERT_EQUAL(hipMemcpy(allThreadsMinusOneH, allThreadsMinusOneD, nBytes, hipMemcpyDeviceToHost),
|
||||
hipSuccess);
|
||||
|
||||
// Validate results for both blocks together
|
||||
for (int i = 0; i < 2 * blockSize; ++i) {
|
||||
ASSERT_EQUAL(syncTestH[i], 200);
|
||||
ASSERT_EQUAL(allThreadsZeroH[i], 0);
|
||||
ASSERT_EQUAL(allThreadsOneH[i], 1);
|
||||
ASSERT_EQUAL(oneThreadZeroH[i], 0);
|
||||
ASSERT_EQUAL(allThreadsMinusOneH[i], 1);
|
||||
}
|
||||
|
||||
// Free device memory
|
||||
ASSERT_EQUAL(hipFree(syncTestD), hipSuccess);
|
||||
ASSERT_EQUAL(hipFree(allThreadsZeroD), hipSuccess);
|
||||
ASSERT_EQUAL(hipFree(allThreadsOneD), hipSuccess);
|
||||
ASSERT_EQUAL(hipFree(oneThreadZeroD), hipSuccess);
|
||||
ASSERT_EQUAL(hipFree(allThreadsMinusOneD), hipSuccess);
|
||||
|
||||
//Free host memory
|
||||
ASSERT_EQUAL(hipHostFree(syncTestH), hipSuccess);
|
||||
ASSERT_EQUAL(hipHostFree(allThreadsZeroH), hipSuccess);
|
||||
ASSERT_EQUAL(hipHostFree(allThreadsOneH), hipSuccess);
|
||||
ASSERT_EQUAL(hipHostFree(oneThreadZeroH), hipSuccess);
|
||||
ASSERT_EQUAL(hipHostFree(allThreadsMinusOneH), hipSuccess);
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
int blockSizes[] = {10, 40, 70, 130, 240, 723, 32, 64, 128, 256, 512, 1024};
|
||||
for (int i = 0; i < (sizeof(blockSizes) / sizeof(blockSizes[0])); ++i)
|
||||
test_syncthreads_and(blockSizes[i]);
|
||||
passed();
|
||||
}
|
||||
@@ -1,169 +0,0 @@
|
||||
/*
|
||||
Copyright (c) 2020 - 2021 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:
|
||||
|
||||
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.
|
||||
*/
|
||||
|
||||
|
||||
/* HIT_START
|
||||
* BUILD: %t %s ../test_common.cpp
|
||||
* TEST: %t
|
||||
* HIT_END
|
||||
*/
|
||||
|
||||
#include <hip/hip_runtime.h>
|
||||
#include "test_common.h"
|
||||
|
||||
#define ASSERT_EQUAL(lhs, rhs) assert(lhs == rhs)
|
||||
|
||||
static __global__
|
||||
void kernel_syncthreads_count(int *syncTestD,
|
||||
int *allThreadsZeroD,
|
||||
int *allThreadsOneD,
|
||||
int *oddThreadsOneD,
|
||||
int *allThreadsMinusOneD,
|
||||
int *allThreadsIdD)
|
||||
{
|
||||
int blockSize = blockDim.x;
|
||||
int predicate = 10;
|
||||
// First block index starts with 0, and second block index starts
|
||||
// with blockSize
|
||||
int i = (blockIdx.x == 0) ? threadIdx.x : blockSize + threadIdx.x;
|
||||
|
||||
// At very first, we need to ensure work-group level syncronization
|
||||
// properly happened, don't bother about predicate testing for now.
|
||||
// Thread 0 and thread 1 writes to shared memory. After call to api,
|
||||
// every thread reads shared memory, and store sum for verification
|
||||
__shared__ int sm[2];
|
||||
if (threadIdx.x == 0)
|
||||
sm[0] = 10;
|
||||
else if (threadIdx.x == 1)
|
||||
sm[1] = 20;
|
||||
__syncthreads_count(predicate);
|
||||
syncTestD[i] = sm[0] + sm[1];
|
||||
|
||||
// All threads pass 0 as predicate value, result should be 0
|
||||
predicate = 0;
|
||||
allThreadsZeroD[i] = __syncthreads_count(predicate);
|
||||
|
||||
// All threads pass 1 as predicate value, result should be blockSize
|
||||
predicate = 1;
|
||||
allThreadsOneD[i] = __syncthreads_count(predicate);
|
||||
|
||||
// Odd numbered threads pass 1, and even numbered threads pass 0, as
|
||||
// predicate value, result should be blockSize / 2
|
||||
predicate = threadIdx.x % 2;
|
||||
oddThreadsOneD[i] = __syncthreads_count(predicate);
|
||||
|
||||
// All threads pass -1 as predicate value, result should blockSize
|
||||
predicate = -1;
|
||||
allThreadsMinusOneD[i] = __syncthreads_count(predicate);
|
||||
|
||||
// Each thread pass its ID as predicate value, result should be blockSize - 1
|
||||
predicate = threadIdx.x;
|
||||
allThreadsIdD[i] = __syncthreads_count(predicate);
|
||||
}
|
||||
|
||||
void test_syncthreads_count(int blockSize)
|
||||
{
|
||||
int nBytes = sizeof(int) * 2 * blockSize;
|
||||
int * syncTestD, *syncTestH;
|
||||
int *allThreadsZeroD, *allThreadsZeroH;
|
||||
int *allThreadsOneD, *allThreadsOneH;
|
||||
int *oddThreadsOneD, *oddThreadsOneH;
|
||||
int *allThreadsMinusOneD, *allThreadsMinusOneH;
|
||||
int *allThreadsIdD, *allThreadsIdH;
|
||||
|
||||
// Allocate device memory
|
||||
ASSERT_EQUAL(hipMalloc((void**)&syncTestD, nBytes), hipSuccess);
|
||||
ASSERT_EQUAL(hipMalloc((void**)&allThreadsZeroD, nBytes), hipSuccess);
|
||||
ASSERT_EQUAL(hipMalloc((void**)&allThreadsOneD, nBytes), hipSuccess);
|
||||
ASSERT_EQUAL(hipMalloc((void**)&oddThreadsOneD, nBytes), hipSuccess);
|
||||
ASSERT_EQUAL(hipMalloc((void**)&allThreadsMinusOneD, nBytes), hipSuccess);
|
||||
ASSERT_EQUAL(hipMalloc((void**)&allThreadsIdD, nBytes), hipSuccess);
|
||||
|
||||
// Allocate host memory
|
||||
ASSERT_EQUAL(hipHostMalloc((void**)&syncTestH, nBytes), hipSuccess);
|
||||
ASSERT_EQUAL(hipHostMalloc((void**)&allThreadsZeroH, nBytes), hipSuccess);
|
||||
ASSERT_EQUAL(hipHostMalloc((void**)&allThreadsOneH, nBytes), hipSuccess);
|
||||
ASSERT_EQUAL(hipHostMalloc((void**)&oddThreadsOneH, nBytes), hipSuccess);
|
||||
ASSERT_EQUAL(hipHostMalloc((void**)&allThreadsMinusOneH, nBytes), hipSuccess);
|
||||
ASSERT_EQUAL(hipHostMalloc((void**)&allThreadsIdH, nBytes), hipSuccess);
|
||||
|
||||
// Launch Kernel
|
||||
hipLaunchKernelGGL(kernel_syncthreads_count,
|
||||
2,
|
||||
blockSize,
|
||||
0,
|
||||
0,
|
||||
syncTestD,
|
||||
allThreadsZeroD,
|
||||
allThreadsOneD,
|
||||
oddThreadsOneD,
|
||||
allThreadsMinusOneD,
|
||||
allThreadsIdD);
|
||||
|
||||
// Copy result from device to host
|
||||
ASSERT_EQUAL(hipMemcpy(syncTestH, syncTestD, nBytes, hipMemcpyDeviceToHost),
|
||||
hipSuccess);
|
||||
ASSERT_EQUAL(hipMemcpy(allThreadsZeroH, allThreadsZeroD, nBytes, hipMemcpyDeviceToHost),
|
||||
hipSuccess);
|
||||
ASSERT_EQUAL(hipMemcpy(allThreadsOneH, allThreadsOneD, nBytes, hipMemcpyDeviceToHost),
|
||||
hipSuccess);
|
||||
ASSERT_EQUAL(hipMemcpy(oddThreadsOneH, oddThreadsOneD, nBytes, hipMemcpyDeviceToHost),
|
||||
hipSuccess);
|
||||
ASSERT_EQUAL(hipMemcpy(allThreadsMinusOneH, allThreadsMinusOneD, nBytes, hipMemcpyDeviceToHost),
|
||||
hipSuccess);
|
||||
ASSERT_EQUAL(hipMemcpy(allThreadsIdH, allThreadsIdD, nBytes, hipMemcpyDeviceToHost),
|
||||
hipSuccess);
|
||||
|
||||
// Validate results for both the blocks together
|
||||
for (int i = 0; i < 2 * blockSize; ++i) {
|
||||
ASSERT_EQUAL(syncTestH[i], 30);
|
||||
ASSERT_EQUAL(allThreadsZeroH[i], 0);
|
||||
ASSERT_EQUAL(allThreadsOneH[i], blockSize);
|
||||
ASSERT_EQUAL(oddThreadsOneH[i], blockSize / 2);
|
||||
ASSERT_EQUAL(allThreadsMinusOneH[i], blockSize);
|
||||
ASSERT_EQUAL(allThreadsIdH[i], (blockSize-1));
|
||||
}
|
||||
|
||||
// Free device memory
|
||||
ASSERT_EQUAL(hipFree(syncTestD), hipSuccess);
|
||||
ASSERT_EQUAL(hipFree(allThreadsZeroD), hipSuccess);
|
||||
ASSERT_EQUAL(hipFree(allThreadsOneD), hipSuccess);
|
||||
ASSERT_EQUAL(hipFree(oddThreadsOneD), hipSuccess);
|
||||
ASSERT_EQUAL(hipFree(allThreadsMinusOneD), hipSuccess);
|
||||
ASSERT_EQUAL(hipFree(allThreadsIdD), hipSuccess);
|
||||
|
||||
//Free host memory
|
||||
ASSERT_EQUAL(hipHostFree(syncTestH), hipSuccess);
|
||||
ASSERT_EQUAL(hipHostFree(allThreadsZeroH), hipSuccess);
|
||||
ASSERT_EQUAL(hipHostFree(allThreadsOneH), hipSuccess);
|
||||
ASSERT_EQUAL(hipHostFree(oddThreadsOneH), hipSuccess);
|
||||
ASSERT_EQUAL(hipHostFree(allThreadsMinusOneH), hipSuccess);
|
||||
ASSERT_EQUAL(hipHostFree(allThreadsIdH), hipSuccess);
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
int blockSizes[] = {10, 40, 70, 130, 240, 723, 32, 64, 128, 256, 512, 1024};
|
||||
for (int i = 0; i < (sizeof(blockSizes) / sizeof(blockSizes[0])); ++i)
|
||||
test_syncthreads_count(blockSizes[i]);
|
||||
passed();
|
||||
}
|
||||
@@ -1,155 +0,0 @@
|
||||
/*
|
||||
Copyright (c) 2020 - 2021 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:
|
||||
|
||||
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.
|
||||
*/
|
||||
|
||||
|
||||
/* HIT_START
|
||||
* BUILD: %t %s ../test_common.cpp
|
||||
* TEST: %t
|
||||
* HIT_END
|
||||
*/
|
||||
|
||||
#include <hip/hip_runtime.h>
|
||||
#include "test_common.h"
|
||||
|
||||
#define ASSERT_EQUAL(lhs, rhs) assert(lhs == rhs)
|
||||
|
||||
static __global__
|
||||
void kernel_syncthreads_or(int *syncTestD,
|
||||
int *allThreadsZeroD,
|
||||
int *allThreadsOneD,
|
||||
int *oneThreadOneD,
|
||||
int *allThreadsMinusOneD)
|
||||
{
|
||||
int blockSize = blockDim.x;
|
||||
int predicate = 10;
|
||||
// First block index starts with 0, and second block index starts
|
||||
// with blockSize
|
||||
int i = (blockIdx.x == 0) ? threadIdx.x : blockSize + threadIdx.x;
|
||||
|
||||
// At very first, we need to ensure work-group level syncronization
|
||||
// properly happened, don't bother about predicate testing for now.
|
||||
// Thread 0 and thread 1 writes to shared memory. After call to api,
|
||||
// every thread reads shared memory, and store subtraction for verification
|
||||
__shared__ int sm[2];
|
||||
if (threadIdx.x == 0)
|
||||
sm[0] = 10;
|
||||
else if (threadIdx.x == 1)
|
||||
sm[1] = 20;
|
||||
__syncthreads_or(predicate);
|
||||
syncTestD[i] = sm[1] - sm[0];
|
||||
|
||||
// All threads pass 0 as predicate value, result should be 0
|
||||
predicate = 0;
|
||||
allThreadsZeroD[i] = __syncthreads_or(predicate);
|
||||
|
||||
// All threads pass 1 as predicate value, result should be 1
|
||||
predicate = 1;
|
||||
allThreadsOneD[i] = __syncthreads_or(predicate);
|
||||
|
||||
// Thread 0 pass 1, and all other threads 0 as predicate value,
|
||||
// result should be 1
|
||||
predicate = (threadIdx.x == 0) ? 1 : 0;
|
||||
oneThreadOneD[i] = __syncthreads_or(predicate);
|
||||
|
||||
// All threads pass -1 as predicate value, result should be 1
|
||||
predicate = -1;
|
||||
allThreadsMinusOneD[i] = __syncthreads_or(predicate);
|
||||
}
|
||||
|
||||
static void test_syncthreads_or(int blockSize)
|
||||
{
|
||||
int nBytes = sizeof(int) * 2 * blockSize;
|
||||
int * syncTestD, *syncTestH;
|
||||
int *allThreadsZeroD, *allThreadsZeroH;
|
||||
int *allThreadsOneD, *allThreadsOneH;
|
||||
int *oneThreadOneD, *oneThreadOneH;
|
||||
int *allThreadsMinusOneD, *allThreadsMinusOneH;
|
||||
|
||||
// Allocate device memory
|
||||
ASSERT_EQUAL(hipMalloc((void**)&syncTestD, nBytes), hipSuccess);
|
||||
ASSERT_EQUAL(hipMalloc((void**)&allThreadsZeroD, nBytes), hipSuccess);
|
||||
ASSERT_EQUAL(hipMalloc((void**)&allThreadsOneD, nBytes), hipSuccess);
|
||||
ASSERT_EQUAL(hipMalloc((void**)&oneThreadOneD, nBytes), hipSuccess);
|
||||
ASSERT_EQUAL(hipMalloc((void**)&allThreadsMinusOneD, nBytes), hipSuccess);
|
||||
|
||||
// Allocate host memory
|
||||
ASSERT_EQUAL(hipHostMalloc((void**)&syncTestH, nBytes), hipSuccess);
|
||||
ASSERT_EQUAL(hipHostMalloc((void**)&allThreadsZeroH, nBytes), hipSuccess);
|
||||
ASSERT_EQUAL(hipHostMalloc((void**)&allThreadsOneH, nBytes), hipSuccess);
|
||||
ASSERT_EQUAL(hipHostMalloc((void**)&oneThreadOneH, nBytes), hipSuccess);
|
||||
ASSERT_EQUAL(hipHostMalloc((void**)&allThreadsMinusOneH, nBytes), hipSuccess);
|
||||
|
||||
// Launch Kernel
|
||||
hipLaunchKernelGGL(kernel_syncthreads_or,
|
||||
2,
|
||||
blockSize,
|
||||
0,
|
||||
0,
|
||||
syncTestD,
|
||||
allThreadsZeroD,
|
||||
allThreadsOneD,
|
||||
oneThreadOneD,
|
||||
allThreadsMinusOneD);
|
||||
|
||||
// Copy result from device to host
|
||||
ASSERT_EQUAL(hipMemcpy(syncTestH, syncTestD, nBytes, hipMemcpyDeviceToHost),
|
||||
hipSuccess);
|
||||
ASSERT_EQUAL(hipMemcpy(allThreadsZeroH, allThreadsZeroD, nBytes, hipMemcpyDeviceToHost),
|
||||
hipSuccess);
|
||||
ASSERT_EQUAL(hipMemcpy(allThreadsOneH, allThreadsOneD, nBytes, hipMemcpyDeviceToHost),
|
||||
hipSuccess);
|
||||
ASSERT_EQUAL(hipMemcpy(oneThreadOneH, oneThreadOneD, nBytes, hipMemcpyDeviceToHost),
|
||||
hipSuccess);
|
||||
ASSERT_EQUAL(hipMemcpy(allThreadsMinusOneH, allThreadsMinusOneD, nBytes, hipMemcpyDeviceToHost),
|
||||
hipSuccess);
|
||||
|
||||
// Validate results for both blocks together
|
||||
for (int i = 0; i < 2 * blockSize; ++i) {
|
||||
ASSERT_EQUAL(syncTestH[i], 10);
|
||||
ASSERT_EQUAL(allThreadsZeroH[i], 0);
|
||||
ASSERT_EQUAL(allThreadsOneH[i], 1);
|
||||
ASSERT_EQUAL(oneThreadOneH[i], 1);
|
||||
ASSERT_EQUAL(allThreadsMinusOneH[i], 1);
|
||||
}
|
||||
|
||||
// Free device memory
|
||||
ASSERT_EQUAL(hipFree(syncTestD), hipSuccess);
|
||||
ASSERT_EQUAL(hipFree(allThreadsZeroD), hipSuccess);
|
||||
ASSERT_EQUAL(hipFree(allThreadsOneD), hipSuccess);
|
||||
ASSERT_EQUAL(hipFree(oneThreadOneD), hipSuccess);
|
||||
ASSERT_EQUAL(hipFree(allThreadsMinusOneD), hipSuccess);
|
||||
|
||||
//Free host memory
|
||||
ASSERT_EQUAL(hipHostFree(syncTestH), hipSuccess);
|
||||
ASSERT_EQUAL(hipHostFree(allThreadsZeroH), hipSuccess);
|
||||
ASSERT_EQUAL(hipHostFree(allThreadsOneH), hipSuccess);
|
||||
ASSERT_EQUAL(hipHostFree(oneThreadOneH), hipSuccess);
|
||||
ASSERT_EQUAL(hipHostFree(allThreadsMinusOneH), hipSuccess);
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
int blockSizes[] = {10, 40, 70, 130, 240, 723, 32, 64, 128, 256, 512, 1024};
|
||||
for (int i = 0; i < (sizeof(blockSizes) / sizeof(blockSizes[0])); ++i)
|
||||
test_syncthreads_or(blockSizes[i]);
|
||||
passed();
|
||||
}
|
||||
@@ -1,136 +0,0 @@
|
||||
/*
|
||||
Copyright (c) 2015 - 2021 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:
|
||||
|
||||
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.
|
||||
*/
|
||||
|
||||
/* HIT_START
|
||||
* BUILD: %t %s ../test_common.cpp NVCC_OPTIONS -std=c++11 LINK_OPTIONS -lpthread
|
||||
* TEST: %t
|
||||
* HIT_END
|
||||
*/
|
||||
|
||||
#include <vector>
|
||||
#include <atomic>
|
||||
#include <thread>
|
||||
#include <cassert>
|
||||
#include <cstdio>
|
||||
#include "hip/hip_runtime.h"
|
||||
#include "hip/device_functions.h"
|
||||
#include "test_common.h"
|
||||
|
||||
#define HIP_ASSERT(x) (assert((x) == hipSuccess))
|
||||
|
||||
__host__ __device__ void fence_system() {
|
||||
#ifdef __HIP_DEVICE_COMPILE__
|
||||
__threadfence_system();
|
||||
#else
|
||||
std::atomic_thread_fence(std::memory_order_seq_cst);
|
||||
#endif
|
||||
}
|
||||
|
||||
__host__ __device__ void round_robin(const int id, const int num_dev, const int num_iter,
|
||||
volatile int* data, volatile int* flag) {
|
||||
for (int i = 0; i < num_iter; i++) {
|
||||
while (*flag % num_dev != id) fence_system(); // invalid the cache for read
|
||||
|
||||
(*data)++;
|
||||
fence_system(); // make sure the store to data is sequenced before the store to flag
|
||||
(*flag)++;
|
||||
fence_system(); // invalid the cache to flush out flag
|
||||
}
|
||||
}
|
||||
|
||||
__global__ void gpu_round_robin(const int id, const int num_dev, const int num_iter,
|
||||
volatile int* data, volatile int* flag) {
|
||||
round_robin(id, num_dev, num_iter, data, flag);
|
||||
}
|
||||
|
||||
int main() {
|
||||
int num_gpus = 0;
|
||||
HIP_ASSERT(hipGetDeviceCount(&num_gpus));
|
||||
if (num_gpus == 0) {
|
||||
passed();
|
||||
return 0;
|
||||
}
|
||||
|
||||
volatile int* data;
|
||||
if (hipHostMalloc(&data, sizeof(int), hipHostMallocCoherent) != hipSuccess) {
|
||||
warn("Memory allocation failed. Skip test. Is SVM atomic supported?")
|
||||
passed();
|
||||
return 0;
|
||||
}
|
||||
|
||||
constexpr int init_data = 1000;
|
||||
*data = init_data;
|
||||
|
||||
volatile int* flag;
|
||||
if (hipHostMalloc(&flag, sizeof(int), hipHostMallocCoherent) != hipSuccess) {
|
||||
warn("Memory allocation failed. Skip test. Is SVM atomic supported?")
|
||||
passed();
|
||||
return 0;
|
||||
}
|
||||
*flag = 0;
|
||||
|
||||
// number of rounds per device
|
||||
constexpr int num_iter = 1000;
|
||||
|
||||
// one CPU thread + 1 kernel/GPU
|
||||
const int num_dev = num_gpus + 1;
|
||||
|
||||
int next_id = 0;
|
||||
std::vector<std::thread> threads;
|
||||
|
||||
// create a CPU thread for the round_robin
|
||||
threads.push_back(std::thread(round_robin, next_id++, num_dev, num_iter, data, flag));
|
||||
|
||||
// run one thread per GPU
|
||||
dim3 dim_block(1, 1, 1);
|
||||
dim3 dim_grid(1, 1, 1);
|
||||
|
||||
// launch one kernel per device for the round robin
|
||||
for (; next_id < num_dev; ++next_id) {
|
||||
threads.push_back(std::thread([=]() {
|
||||
HIP_ASSERT(hipSetDevice(next_id - 1));
|
||||
hipLaunchKernelGGL(gpu_round_robin, dim_grid, dim_block, 0, 0x0, next_id, num_dev,
|
||||
num_iter, data, flag);
|
||||
HIP_ASSERT(hipDeviceSynchronize());
|
||||
}));
|
||||
}
|
||||
|
||||
for (auto& t : threads) {
|
||||
t.join();
|
||||
}
|
||||
|
||||
int expected_data = init_data + num_dev * num_iter;
|
||||
int expected_flag = num_dev * num_iter;
|
||||
|
||||
bool passed = *data == expected_data && *flag == expected_flag;
|
||||
|
||||
HIP_ASSERT(hipHostFree((void*)data));
|
||||
HIP_ASSERT(hipHostFree((void*)flag));
|
||||
|
||||
if (passed) {
|
||||
passed();
|
||||
} else {
|
||||
failed("Failed Verification!\n");
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -1,112 +0,0 @@
|
||||
/*
|
||||
Copyright (c) 2015 - 2021 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:
|
||||
|
||||
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.
|
||||
*/
|
||||
|
||||
/* HIT_START
|
||||
* BUILD: %t %s
|
||||
* TEST: %t
|
||||
* HIT_END
|
||||
*/
|
||||
|
||||
#include <hip/hip_runtime_api.h>
|
||||
#include <hip/hip_runtime.h>
|
||||
#include "test_common.h"
|
||||
#include <hip/device_functions.h>
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#define HIP_ASSERT(x) (assert((x) == hipSuccess))
|
||||
|
||||
#define LEN 512
|
||||
#define SIZE LEN << 2
|
||||
|
||||
#define TEST_DEBUG (0)
|
||||
|
||||
__global__ void kernel_trig(float* In, float* sin_d, float* cos_d, float* tan_d,
|
||||
float* sin_pd, float* cos_pd) {
|
||||
int tid = threadIdx.x + blockIdx.x * blockDim.x;
|
||||
sin_d[tid] = sinf(In[tid]);
|
||||
cos_d[tid] = cosf(In[tid]);
|
||||
tan_d[tid] = tanf(In[tid]);
|
||||
sincosf(In[tid], &sin_pd[tid], &cos_pd[tid]);
|
||||
}
|
||||
|
||||
int main() {
|
||||
float *In, *sin_h, *cos_h, *tan_h, *sin_ph, *cos_ph;
|
||||
float *In_d, *sin_d, *cos_d, *tan_d, *sin_pd, *cos_pd;
|
||||
int errors = 0;
|
||||
In = new float[LEN];
|
||||
sin_h = new float[LEN];
|
||||
cos_h = new float[LEN];
|
||||
tan_h = new float[LEN];
|
||||
sin_ph = new float[LEN];
|
||||
cos_ph = new float[LEN];
|
||||
for (int i = 0; i < LEN; i++) {
|
||||
In[i] = 1.0f;
|
||||
sin_h[i] = 0.0f;
|
||||
cos_h[i] = 0.0f;
|
||||
tan_h[i] = 0.0f;
|
||||
sin_ph[i] = 0.0f;
|
||||
cos_ph[i] = 0.0f;
|
||||
}
|
||||
HIP_ASSERT(hipMalloc((void**)&In_d, SIZE));
|
||||
HIP_ASSERT(hipMalloc((void**)&sin_d, SIZE));
|
||||
HIP_ASSERT(hipMalloc((void**)&cos_d, SIZE));
|
||||
HIP_ASSERT(hipMalloc((void**)&tan_d, SIZE));
|
||||
HIP_ASSERT(hipMalloc((void**)&sin_pd, SIZE));
|
||||
HIP_ASSERT(hipMalloc((void**)&cos_pd, SIZE));
|
||||
|
||||
hipMemcpy(In_d, In, SIZE, hipMemcpyHostToDevice);
|
||||
hipLaunchKernelGGL(kernel_trig, dim3(LEN, 1, 1), dim3(1, 1, 1), 0, 0,
|
||||
In_d, sin_d, cos_d, tan_d,
|
||||
sin_pd, cos_pd);
|
||||
hipMemcpy(sin_h, sin_d, SIZE, hipMemcpyDeviceToHost);
|
||||
hipMemcpy(cos_h, cos_d, SIZE, hipMemcpyDeviceToHost);
|
||||
hipMemcpy(tan_h, tan_d, SIZE, hipMemcpyDeviceToHost);
|
||||
hipMemcpy(sin_ph, sin_pd, SIZE, hipMemcpyDeviceToHost);
|
||||
hipMemcpy(cos_ph, cos_pd, SIZE, hipMemcpyDeviceToHost);
|
||||
for (int i = 0; i < LEN; i++) {
|
||||
if (sin_h[i] != sin_ph[i] || cos_h[i] != cos_ph[i] || tan_h[i] * cos_h[i] != sin_h[i]) {
|
||||
errors++;
|
||||
#if TEST_DEBUG
|
||||
std::cout << "Check Failed!" << std::endl;
|
||||
std::cout << " sin_h: " << sin_h[i] << " sin_ph: " << sin_ph[i] << "\n"
|
||||
<< " cos_h: " << cos_h[i] << " cos_ph:" << cos_ph[i] << "\n"
|
||||
<< " tan_h * cos_h: " << tan_h[i] * cos_h[i] << " sin_h[i]: " << sin_h[i] << "\n";
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
HIP_ASSERT(hipFree(In_d));
|
||||
HIP_ASSERT(hipFree(sin_d));
|
||||
HIP_ASSERT(hipFree(cos_d));
|
||||
HIP_ASSERT(hipFree(tan_d));
|
||||
HIP_ASSERT(hipFree(sin_pd));
|
||||
HIP_ASSERT(hipFree(cos_pd));
|
||||
|
||||
if (errors != 0) {
|
||||
std::cout << "hip_trig FAILED!" << std::endl;
|
||||
return -1;
|
||||
} else {
|
||||
std::cout << "hip_trig PASSED!" << std::endl;
|
||||
}
|
||||
return errors;
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
/*
|
||||
Copyright (c) 2015 - 2021 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:
|
||||
|
||||
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.
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <type_traits>
|
||||
|
||||
template<bool b, typename T = void>
|
||||
using Enable_if_t = typename std::enable_if<b, T>::type;
|
||||
@@ -1,34 +0,0 @@
|
||||
/*
|
||||
Copyright (c) 2020 - 2021 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:
|
||||
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.
|
||||
*/
|
||||
|
||||
#include "hip/hip_runtime.h"
|
||||
|
||||
extern "C" __global__ void bit_extract_kernel(uint32_t* C_d, const uint32_t*
|
||||
A_d, size_t N) {
|
||||
size_t offset = (blockIdx.x * blockDim.x + threadIdx.x);
|
||||
size_t stride = blockDim.x * gridDim.x;
|
||||
|
||||
for (size_t i = offset; i < N; i += stride) {
|
||||
#ifdef __HIP_PLATFORM_AMD__
|
||||
C_d[i] = __bitextract_u32(A_d[i], 8, 4);
|
||||
#else /* defined __HIP_PLATFORM_NVIDIA__ or other path */
|
||||
C_d[i] = ((A_d[i] & 0xf00) >> 8);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@@ -1,368 +0,0 @@
|
||||
/*
|
||||
Copyright (c) 2020 - 2021 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:
|
||||
|
||||
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.
|
||||
*/
|
||||
|
||||
/* Test for loading device kernels from a library created with extern "C" function
|
||||
*/
|
||||
|
||||
/* HIT_START
|
||||
* BUILD_CMD: libLazyLoad_amd %hc %S/%s -o liblazyLoad.so -I%S/.. -fPIC -lpthread -shared -DTEST_SHARED_LIBRARY EXCLUDE_HIP_PLATFORM nvidia EXCLUDE_HIP_LIB_TYPE static
|
||||
* BUILD_CMD: libLazyLoad_nvidia %hc %S/%s --std=c++11 -o liblazyLoad.so -I%S/.. -Xcompiler -fPIC -lpthread -shared -DTEST_SHARED_LIBRARY EXCLUDE_HIP_PLATFORM amd
|
||||
* BUILD_CMD: %t %hc %S/%s --std=c++11 -o %T/%t -I%S/.. -ldl EXCLUDE_HIP_LIB_TYPE static
|
||||
* TEST: %t
|
||||
* HIT_END
|
||||
*/
|
||||
|
||||
#if !defined(TEST_SHARED_LIBRARY)
|
||||
|
||||
#include <dlfcn.h>
|
||||
#include <iostream>
|
||||
#include "test_common.h"
|
||||
|
||||
__global__ void vector_add(float* C, float* A, float* B, size_t N) {
|
||||
size_t offset = blockIdx.x * blockDim.x + threadIdx.x;
|
||||
size_t stride = blockDim.x * gridDim.x;
|
||||
for (size_t i = offset; i < N; i += stride) {
|
||||
C[i] = A[i] + B[i];
|
||||
}
|
||||
}
|
||||
|
||||
bool launch_local_kernel() {
|
||||
bool testResult = true;
|
||||
float *A_d, *B_d, *C_d;
|
||||
float *A_h, *B_h, *C_h;
|
||||
size_t N = 1000000;
|
||||
size_t Nbytes = N * sizeof(float);
|
||||
static int device = 0;
|
||||
|
||||
HIPCHECK(hipSetDevice(device));
|
||||
hipDeviceProp_t props;
|
||||
HIPCHECK(hipGetDeviceProperties(&props, device /*deviceID*/));
|
||||
|
||||
A_h = reinterpret_cast<float*>(malloc(Nbytes));
|
||||
HIPCHECK(A_h == nullptr ? hipErrorOutOfMemory : hipSuccess);
|
||||
B_h = reinterpret_cast<float*>(malloc(Nbytes));
|
||||
HIPCHECK(B_h == nullptr ? hipErrorOutOfMemory : hipSuccess);
|
||||
C_h = reinterpret_cast<float*>(malloc(Nbytes));
|
||||
HIPCHECK(C_h == nullptr ? hipErrorOutOfMemory : hipSuccess);
|
||||
|
||||
// Fill with Phi + i
|
||||
for (size_t i = 0; i < N; i++) {
|
||||
A_h[i] = 1.618f + i;
|
||||
B_h[i] = 1.618f + i;
|
||||
}
|
||||
|
||||
HIPCHECK(hipMalloc(&A_d, Nbytes));
|
||||
HIPCHECK(hipMalloc(&B_d, Nbytes));
|
||||
HIPCHECK(hipMalloc(&C_d, Nbytes));
|
||||
HIPCHECK(hipMemcpy(A_d, A_h, Nbytes, hipMemcpyHostToDevice));
|
||||
HIPCHECK(hipMemcpy(B_d, B_h, Nbytes, hipMemcpyHostToDevice));
|
||||
|
||||
const unsigned blocks = 512;
|
||||
const unsigned threadsPerBlock = 256;
|
||||
hipLaunchKernelGGL(vector_add, dim3(blocks), dim3(threadsPerBlock),
|
||||
0, 0, C_d, A_d, B_d, N);
|
||||
HIPCHECK(hipMemcpy(C_h, C_d, Nbytes, hipMemcpyDeviceToHost));
|
||||
|
||||
for (size_t i=0; i < N ; i++) {
|
||||
if (C_h[i] != (A_h[i] + B_h[i])) {
|
||||
printf("data mismatch. Local kernel failed");
|
||||
testResult = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
HIPCHECK(hipFree(A_d));
|
||||
HIPCHECK(hipFree(B_d));
|
||||
HIPCHECK(hipFree(C_d));
|
||||
|
||||
free(A_h);
|
||||
free(B_h);
|
||||
free(C_h);
|
||||
|
||||
std::cout << "Local kernel executed successfully\n";
|
||||
return testResult;
|
||||
}
|
||||
|
||||
bool launch_dynamically_loaded_kernel() {
|
||||
bool testResult = true;
|
||||
int ret = 1;
|
||||
|
||||
void* handle = dlopen("./liblazyLoad.so", RTLD_LAZY);
|
||||
|
||||
if (!handle) {
|
||||
std::cout << dlerror() << "\n";
|
||||
testResult = false;
|
||||
return testResult;
|
||||
}
|
||||
|
||||
std::cout << "loaded liblazyLoad.so\n";
|
||||
|
||||
void* sym = dlsym(handle, "lazyLoad");
|
||||
if (!sym) {
|
||||
std::cout << "unable to locate lazyLoad within lazyLoad.so\n";
|
||||
std::cout << dlerror() << "\n";
|
||||
dlclose(handle);
|
||||
testResult = false;
|
||||
return testResult;
|
||||
}
|
||||
|
||||
int(*fp)() = reinterpret_cast<int(*)()>(sym);
|
||||
|
||||
ret = fp();
|
||||
|
||||
if (ret == 0) {
|
||||
std::cout << "dynamic launch failed\n";
|
||||
testResult = false;
|
||||
} else {
|
||||
std::cout << "dynamic launch succeeded\n";
|
||||
}
|
||||
|
||||
dlclose(handle);
|
||||
return testResult;
|
||||
}
|
||||
|
||||
int main() {
|
||||
bool testResult = true;
|
||||
|
||||
testResult &= launch_local_kernel();
|
||||
testResult &= launch_dynamically_loaded_kernel();
|
||||
|
||||
if (testResult == true) {
|
||||
passed();
|
||||
} else {
|
||||
failed("One or more tests failed");
|
||||
}
|
||||
}
|
||||
|
||||
#else // !defined(TEST_SHARED_LIBRARY)
|
||||
|
||||
#include <iostream>
|
||||
#include "test_common.h"
|
||||
|
||||
__global__ void vAdd(float* C, float* A, float* B, size_t N) {
|
||||
size_t offset = hipBlockIdx_x * hipBlockDim_x + hipThreadIdx_x;
|
||||
size_t stride = hipBlockDim_x * hipGridDim_x;
|
||||
|
||||
for (size_t i = offset; i < N; i += stride) {
|
||||
C[i] = A[i] + B[i];
|
||||
}
|
||||
}
|
||||
|
||||
int vectorAddKernelTest() {
|
||||
int testResult = 1;
|
||||
float *A_d, *B_d, *C_d;
|
||||
float *A_h, *B_h, *C_h;
|
||||
size_t N = 1000000;
|
||||
size_t Nbytes = N * sizeof(float);
|
||||
static int device = 0;
|
||||
|
||||
HIPCHECK(hipSetDevice(device));
|
||||
hipDeviceProp_t props;
|
||||
HIPCHECK(hipGetDeviceProperties(&props, device /*deviceID*/));
|
||||
A_h = reinterpret_cast<float*>(malloc(Nbytes));
|
||||
HIPCHECK(A_h == nullptr ? hipErrorOutOfMemory : hipSuccess);
|
||||
B_h = reinterpret_cast<float*>(malloc(Nbytes));
|
||||
HIPCHECK(B_h == nullptr ? hipErrorOutOfMemory : hipSuccess);
|
||||
C_h = reinterpret_cast<float*>(malloc(Nbytes));
|
||||
HIPCHECK(C_h == nullptr ? hipErrorOutOfMemory : hipSuccess);
|
||||
|
||||
// Fill with Phi + i
|
||||
for (size_t i = 0; i < N; i++) {
|
||||
A_h[i] = 1.618f + i;
|
||||
B_h[i] = 1.618f + i;
|
||||
}
|
||||
|
||||
HIPCHECK(hipMalloc(&A_d, Nbytes));
|
||||
HIPCHECK(hipMalloc(&B_d, Nbytes));
|
||||
HIPCHECK(hipMalloc(&C_d, Nbytes));
|
||||
HIPCHECK(hipMemcpy(A_d, A_h, Nbytes, hipMemcpyHostToDevice));
|
||||
HIPCHECK(hipMemcpy(B_d, B_h, Nbytes, hipMemcpyHostToDevice));
|
||||
|
||||
const unsigned blocks = 512;
|
||||
const unsigned threadsPerBlock = 256;
|
||||
|
||||
std::cout << "info: Launching vAdd kernel\n";
|
||||
hipLaunchKernelGGL(vAdd, dim3(blocks), dim3(threadsPerBlock),
|
||||
0, 0, C_d, A_d, B_d, N);
|
||||
HIPCHECK(hipMemcpy(C_h, C_d, Nbytes, hipMemcpyDeviceToHost));
|
||||
|
||||
for (size_t i=0; i < N ; i++) {
|
||||
if (C_h[i] != (A_h[i] + B_h[i])) {
|
||||
printf("info: data mismatch. vAdd kernel failed");
|
||||
testResult = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (testResult) {
|
||||
std::cout << "info: vAdd kernel executed fine\n";
|
||||
}
|
||||
|
||||
HIPCHECK(hipFree(A_d));
|
||||
HIPCHECK(hipFree(B_d));
|
||||
HIPCHECK(hipFree(C_d));
|
||||
|
||||
free(A_h);
|
||||
free(B_h);
|
||||
free(C_h);
|
||||
return testResult;
|
||||
}
|
||||
|
||||
#include "hip/hip_runtime.h"
|
||||
#include "hip/hip_runtime_api.h"
|
||||
#include "hip/hip_cooperative_groups.h"
|
||||
|
||||
namespace cg = cooperative_groups;
|
||||
|
||||
static const uint BufferSizeInDwords = 448 * 1024 * 1024;
|
||||
|
||||
__global__ void test_gws(uint* buf, uint bufSize,
|
||||
long* tmpBuf, long* result) {
|
||||
extern __shared__ long tmp[];
|
||||
uint offset = blockIdx.x * blockDim.x + threadIdx.x;
|
||||
uint stride = gridDim.x * blockDim.x;
|
||||
cg::grid_group gg = cg::this_grid();
|
||||
|
||||
long sum = 0;
|
||||
|
||||
for (uint i = offset; i < bufSize; i += stride) {
|
||||
sum += buf[i];
|
||||
}
|
||||
|
||||
tmp[threadIdx.x] = sum;
|
||||
__syncthreads();
|
||||
|
||||
if (threadIdx.x == 0) {
|
||||
sum = 0;
|
||||
for (uint i = 0; i < blockDim.x; i++) {
|
||||
sum += tmp[i];
|
||||
}
|
||||
tmpBuf[blockIdx.x] = sum;
|
||||
}
|
||||
|
||||
gg.sync();
|
||||
|
||||
if (offset == 0) {
|
||||
for (uint i = 1; i < gridDim.x; ++i) {
|
||||
sum += tmpBuf[i];
|
||||
}
|
||||
*result = sum;
|
||||
}
|
||||
}
|
||||
|
||||
int cooperativeKernelTest() {
|
||||
int testResult = 1;
|
||||
uint* dA;
|
||||
long* dB;
|
||||
long* dC;
|
||||
long* Ah;
|
||||
|
||||
hipDeviceProp_t deviceProp;
|
||||
hipGetDeviceProperties(&deviceProp, 0);
|
||||
|
||||
if (!deviceProp.cooperativeLaunch) {
|
||||
std::cout << "info: Device doesn't support cooperative launch!"
|
||||
"skipping the test!\n";
|
||||
return testResult;
|
||||
}
|
||||
|
||||
uint32_t* init = new uint32_t[BufferSizeInDwords];
|
||||
|
||||
for (uint32_t i = 0; i < BufferSizeInDwords; ++i) {
|
||||
init[i] = i;
|
||||
}
|
||||
|
||||
std::cout << "info: Launch kernel to test hipLaunchCooperativeKernel api\n";
|
||||
std::cout << "info: running on bus 0x" << deviceProp.pciBusID << " " <<
|
||||
deviceProp.name << "\n";
|
||||
|
||||
size_t SIZE = BufferSizeInDwords * sizeof(uint);
|
||||
|
||||
HIPCHECK(hipMalloc(reinterpret_cast<void**>(&dA), SIZE));
|
||||
HIPCHECK(hipMalloc(reinterpret_cast<void**>(&dC), sizeof(long)));
|
||||
HIPCHECK(hipMemcpy(dA, init, SIZE, hipMemcpyHostToDevice));
|
||||
Ah = reinterpret_cast<long*>(malloc(sizeof(long)));
|
||||
|
||||
hipStream_t stream;
|
||||
HIPCHECK(hipStreamCreate(&stream));
|
||||
|
||||
dim3 dimBlock = dim3(1);
|
||||
dim3 dimGrid = dim3(1);
|
||||
|
||||
int numBlocks = 0;
|
||||
uint workgroups[4] = {32, 64, 128, 256};
|
||||
|
||||
for (uint i = 0; i < 4; ++i) {
|
||||
dimBlock.x = workgroups[i];
|
||||
/* Calculate the device occupancy to know how many blocks can be
|
||||
run concurrently */
|
||||
hipOccupancyMaxActiveBlocksPerMultiprocessor(&numBlocks,
|
||||
test_gws, dimBlock.x * dimBlock.y * dimBlock.z, dimBlock.x * sizeof(long));
|
||||
dimGrid.x = deviceProp.multiProcessorCount * std::min(numBlocks, 32);
|
||||
HIPCHECK(hipMalloc(reinterpret_cast<void**>(&dB),
|
||||
dimGrid.x * sizeof(long)));
|
||||
|
||||
void *params[4];
|
||||
params[0] = reinterpret_cast<void*>(&dA);
|
||||
params[1] = (void*)&BufferSizeInDwords;
|
||||
params[2] = reinterpret_cast<void*>(&dB);
|
||||
params[3] = reinterpret_cast<void*>(&dC);
|
||||
|
||||
std::cout << "Testing with grid size = " << dimGrid.x <<
|
||||
" and block size = " << dimBlock.x << "\n";
|
||||
|
||||
HIPCHECK(hipLaunchCooperativeKernel(reinterpret_cast<void*>(test_gws),
|
||||
dimGrid, dimBlock, params,
|
||||
dimBlock.x * sizeof(long), stream));
|
||||
|
||||
HIPCHECK(hipMemcpy(Ah, dC, sizeof(long), hipMemcpyDeviceToHost));
|
||||
|
||||
if (*Ah != (((long)(BufferSizeInDwords) * (BufferSizeInDwords - 1)) / 2)) {
|
||||
std::cout << "Data validation failed for grid size = " << dimGrid.x <<
|
||||
" and block size = " << dimBlock.x << "\n";
|
||||
HIPCHECK(hipFree(dB));
|
||||
std::cout << "Test failed! \n";
|
||||
testResult = 0;
|
||||
break;
|
||||
|
||||
} else {
|
||||
std::cout << "info: data validated!\n";
|
||||
HIPCHECK(hipFree(dB));
|
||||
}
|
||||
}
|
||||
|
||||
if (testResult) {
|
||||
std::cout <<"info: hipLaunchCooperativeKernel api executed fine\n";
|
||||
}
|
||||
|
||||
HIPCHECK(hipStreamDestroy(stream));
|
||||
HIPCHECK(hipFree(dC));
|
||||
HIPCHECK(hipFree(dA));
|
||||
delete [] init;
|
||||
free(Ah);
|
||||
return testResult;
|
||||
}
|
||||
|
||||
extern "C" int lazyLoad() {
|
||||
return vectorAddKernelTest() & cooperativeKernelTest();
|
||||
}
|
||||
|
||||
#endif // !defined(TEST_SHARED_LIBRARY)
|
||||
@@ -1,163 +0,0 @@
|
||||
/*
|
||||
Copyright (c) 2020 - 2021 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:
|
||||
|
||||
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.
|
||||
*/
|
||||
|
||||
/* Test is to load hip runtime using dlopen and get function pointer
|
||||
* using dlsym for hip apis using dlsym()
|
||||
* */
|
||||
|
||||
/* HIT_START
|
||||
* BUILD_CMD: bit_extract_kernel.code %hc --genco %S/bit_extract_kernel.cpp -o bit_extract_kernel.code EXCLUDE_HIP_PLATFORM nvidia
|
||||
* BUILD_CMD: %t %hc %S/%s -I%S/.. -o %T/%t -ldl EXCLUDE_HIP_PLATFORM nvidia EXCLUDE_HIP_LIB_TYPE static
|
||||
* TEST: %t
|
||||
* HIT_END
|
||||
*/
|
||||
|
||||
#include "test_common.h"
|
||||
#include <stdio.h>
|
||||
#include <iostream>
|
||||
#include <dlfcn.h>
|
||||
#include <fstream>
|
||||
#include <vector>
|
||||
|
||||
#define fileName "bit_extract_kernel.code"
|
||||
|
||||
#define LEN 64
|
||||
#define SIZE LEN * sizeof(float)
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
uint32_t *A_d, *C_d;
|
||||
uint32_t *A_h, *C_h;
|
||||
size_t N = 1000000;
|
||||
size_t Nbytes = N * sizeof(uint32_t);
|
||||
|
||||
void* handle = dlopen("libamdhip64.so", RTLD_LAZY);
|
||||
if (!handle) {
|
||||
std::cout << dlerror() << "\n";
|
||||
failed("hip runtime failed to load from dlopen\n");
|
||||
}
|
||||
|
||||
std::cout << "hip runtime loaded using dlopen\n";
|
||||
|
||||
void* sym_hipGetDevice = dlsym(handle, "hipGetDevice");
|
||||
void* sym_hipMalloc = dlsym(handle, "hipMalloc");
|
||||
void* sym_hipMemcpyHtoD = dlsym(handle, "hipMemcpyHtoD");
|
||||
void* sym_hipMemcpyDtoH = dlsym(handle, "hipMemcpyDtoH");
|
||||
void* sym_hipModuleLoad = dlsym(handle, "hipModuleLoad");
|
||||
void* sym_hipGetDeviceProperties = dlsym(handle, "hipGetDeviceProperties");
|
||||
void* sym_hipModuleGetFunction = dlsym(handle, "hipModuleGetFunction");
|
||||
void* sym_hipModuleLaunchKernel = dlsym(handle, "hipModuleLaunchKernel");
|
||||
|
||||
dlclose(handle);
|
||||
hipError_t (*dyn_hipGetDevice)(hipDevice_t*, int) = reinterpret_cast
|
||||
<hipError_t (*)(hipDevice_t*, int)>(sym_hipGetDevice);
|
||||
|
||||
hipError_t (*dyn_hipMalloc)(void**, uint32_t) = reinterpret_cast
|
||||
<hipError_t (*)(void**, uint32_t)>(sym_hipMalloc);
|
||||
|
||||
hipError_t (*dyn_hipMemcpyHtoD)(hipDeviceptr_t, void*, size_t) = reinterpret_cast
|
||||
<hipError_t (*)(hipDeviceptr_t, void*, size_t)>(sym_hipMemcpyHtoD);
|
||||
|
||||
hipError_t (*dyn_hipMemcpyDtoH)(void*, hipDeviceptr_t, size_t) = reinterpret_cast
|
||||
<hipError_t (*)(void*, hipDeviceptr_t, size_t)>(sym_hipMemcpyDtoH);
|
||||
|
||||
hipError_t (*dyn_hipModuleLoad)(hipModule_t*, const char*) = reinterpret_cast
|
||||
<hipError_t (*)(hipModule_t*, const char*)>(sym_hipModuleLoad);
|
||||
|
||||
hipError_t (*dyn_hipGetDeviceProperties)(hipDeviceProp_t*, int) = reinterpret_cast
|
||||
<hipError_t (*)(hipDeviceProp_t*, int)>(sym_hipGetDeviceProperties);
|
||||
|
||||
hipError_t (*dyn_hipModuleGetFunction)(hipFunction_t*, hipModule_t, const char*) =
|
||||
reinterpret_cast<hipError_t (*)(hipFunction_t*, hipModule_t, const char*)>
|
||||
(sym_hipModuleGetFunction);
|
||||
|
||||
hipError_t (*dyn_hipModuleLaunchKernel)(hipFunction_t, unsigned int, unsigned int,
|
||||
unsigned int, unsigned int, unsigned int, unsigned int, unsigned int,
|
||||
hipStream_t, void**, void**) = reinterpret_cast<hipError_t(*)
|
||||
(hipFunction_t, unsigned int, unsigned int, unsigned int, unsigned int,
|
||||
unsigned int, unsigned int, unsigned int, hipStream_t, void**, void**)>
|
||||
(sym_hipModuleLaunchKernel);
|
||||
|
||||
hipDevice_t device;
|
||||
HIPCHECK(dyn_hipGetDevice(&device, 0));
|
||||
|
||||
hipDeviceProp_t props;
|
||||
HIPCHECK(dyn_hipGetDeviceProperties(&props, device));
|
||||
printf("info: running on device #%d %s\n", device, props.name);
|
||||
printf("info: allocate host mem (%6.2f MB)\n", 2 * Nbytes / 1024.0 / 1024.0);
|
||||
A_h = reinterpret_cast<uint32_t*>(malloc(Nbytes));
|
||||
HIPASSERT(A_h != NULL);
|
||||
C_h = reinterpret_cast<uint32_t*>(malloc(Nbytes));
|
||||
HIPASSERT(C_h != NULL);
|
||||
|
||||
for (size_t i = 0; i < N; i++) {
|
||||
A_h[i] = i;
|
||||
}
|
||||
|
||||
printf("info: allocate device mem (%6.2f MB)\n", 2 * Nbytes / 1024.0 / 1024.0);
|
||||
HIPCHECK(dyn_hipMalloc(reinterpret_cast<void**>(&A_d), Nbytes));
|
||||
HIPCHECK(dyn_hipMalloc(reinterpret_cast<void**>(&C_d), Nbytes));
|
||||
|
||||
printf("info: copy Host2Device\n");
|
||||
HIPCHECK(dyn_hipMemcpyHtoD((hipDeviceptr_t)(A_d), A_h, Nbytes));
|
||||
|
||||
printf("info: launch 'bit_extract_kernel' \n");
|
||||
|
||||
struct {
|
||||
void* _Cd;
|
||||
void* _Ad;
|
||||
size_t _N;
|
||||
} args;
|
||||
args._Cd = reinterpret_cast<void**> (C_d);
|
||||
args._Ad = reinterpret_cast<void**> (A_d);
|
||||
args._N = (size_t) N;
|
||||
size_t size = sizeof(args);
|
||||
|
||||
void* config[] = {HIP_LAUNCH_PARAM_BUFFER_POINTER, &args,
|
||||
HIP_LAUNCH_PARAM_BUFFER_SIZE, &size, HIP_LAUNCH_PARAM_END};
|
||||
|
||||
hipModule_t Module;
|
||||
HIPCHECK(dyn_hipModuleLoad(&Module, fileName));
|
||||
|
||||
hipFunction_t Function;
|
||||
HIPCHECK(dyn_hipModuleGetFunction(&Function, Module, "bit_extract_kernel"));
|
||||
|
||||
HIPCHECK(dyn_hipModuleLaunchKernel(Function, 1, 1, 1, LEN, 1, 1, 0, 0, NULL,
|
||||
reinterpret_cast<void**>(&config)));
|
||||
|
||||
printf("info: copy Device2Host\n");
|
||||
HIPCHECK(dyn_hipMemcpyDtoH(C_h, (hipDeviceptr_t)(C_d), Nbytes));
|
||||
|
||||
printf("info: check result\n");
|
||||
for (size_t i = 0; i < N; i++) {
|
||||
unsigned Agold = ((A_h[i] & 0xf00) >> 8);
|
||||
if (C_h[i] != Agold) {
|
||||
fprintf(stderr, "mismatch detected.\n");
|
||||
printf("%zu: %08x =? %08x (Ain=%08x)\n", i, C_h[i], Agold, A_h[i]);
|
||||
failed("Test failed\n");
|
||||
}
|
||||
}
|
||||
HIPCHECK(hipFree(A_d));
|
||||
HIPCHECK(hipFree(C_d));
|
||||
free(A_h);
|
||||
free(C_h);
|
||||
passed();
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
/*
|
||||
Copyright (c) 2015 - 2021 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:
|
||||
|
||||
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.
|
||||
*/
|
||||
|
||||
|
||||
#include "hip/hip_runtime_api.h"
|
||||
|
||||
#define size 1024*1024
|
||||
|
||||
int main(){
|
||||
float *Ad;
|
||||
hipMalloc((void**)&Ad, size);
|
||||
}
|
||||
@@ -1,68 +0,0 @@
|
||||
/*
|
||||
Copyright (c) 2015 - 2021 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:
|
||||
|
||||
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.
|
||||
*/
|
||||
|
||||
|
||||
#include"gHipApi.h"
|
||||
#include "hip/hip_runtime_api.h"
|
||||
#include"stdio.h"
|
||||
|
||||
void _h2d(mem_manager *self){
|
||||
hipMemcpy(self->dev_ptr, self->hst_ptr, self->size, hipMemcpyHostToDevice);
|
||||
}
|
||||
|
||||
void _d2h(mem_manager *self)
|
||||
{
|
||||
hipMemcpy(self->hst_ptr, self->dev_ptr, self->size, hipMemcpyDeviceToHost);
|
||||
}
|
||||
|
||||
void _malloc_hip(mem_manager *self)
|
||||
{
|
||||
hipMalloc(&(self->dev_ptr), self->size);
|
||||
}
|
||||
|
||||
void _malloc_hst(mem_manager *self)
|
||||
{
|
||||
self->hst_ptr = malloc(self->size);
|
||||
}
|
||||
|
||||
void memset_hst(mem_manager *mem, float val)
|
||||
{
|
||||
float *tmp = (float*)mem->hst_ptr;
|
||||
int i;
|
||||
for(i=0;i<(mem->size)/sizeof(float);i++)
|
||||
{
|
||||
tmp[i] = val;
|
||||
}
|
||||
}
|
||||
|
||||
mem_manager *mem_manager_start(size_t _size)
|
||||
{
|
||||
mem_manager *tmp = (mem_manager*)malloc(sizeof(mem_manager));
|
||||
tmp->size = _size;
|
||||
tmp->h2d = _h2d;
|
||||
tmp->d2h = _d2h;
|
||||
tmp->malloc_hip = _malloc_hip;
|
||||
tmp->malloc_hst = _malloc_hst;
|
||||
return tmp;
|
||||
}
|
||||
|
||||
|
||||
Некоторые файлы не были показаны из-за слишком большого количества измененных файлов Показать больше
Ссылка в новой задаче
Block a user