mirror of
https://github.com/capstone-engine/llvm-capstone.git
synced 2024-12-01 01:31:26 +00:00
[OpenMP] Implementing omp_get_device_num()
This patch implements omp_get_device_num() in the host and the device. It uses the already existing getDeviceNum in the device config for the device. And in the host it uses the omp_get_num_devices(). Two simple tests added Differential Revision: https://reviews.llvm.org/D128347
This commit is contained in:
parent
cbeca742a4
commit
616dd9ae14
@ -28,8 +28,7 @@ enum DebugKind : uint32_t {
|
||||
/// host by omp_get_num_devices.
|
||||
uint32_t getNumDevices();
|
||||
|
||||
/// Return the number of devices in the system, same number as returned on the
|
||||
/// host by omp_get_num_devices.
|
||||
/// Return the device number in the system for omp_get_device_num.
|
||||
uint32_t getDeviceNum();
|
||||
|
||||
/// Return the user choosen debug level.
|
||||
|
@ -126,6 +126,8 @@ int omp_get_default_device(void);
|
||||
|
||||
int omp_get_num_devices(void);
|
||||
|
||||
int omp_get_device_num(void);
|
||||
|
||||
int omp_get_num_teams(void);
|
||||
|
||||
int omp_get_team_num();
|
||||
|
@ -504,6 +504,8 @@ int omp_get_default_device(void) { return -1; }
|
||||
|
||||
int omp_get_num_devices(void) { return config::getNumDevices(); }
|
||||
|
||||
int omp_get_device_num(void) { return config::getDeviceNum(); }
|
||||
|
||||
int omp_get_num_teams(void) { return mapping::getNumberOfBlocks(); }
|
||||
|
||||
int omp_get_team_num() { return mapping::getBlockId(); }
|
||||
|
@ -202,6 +202,7 @@ extern "C" {
|
||||
#endif
|
||||
|
||||
int omp_get_num_devices(void);
|
||||
int omp_get_device_num(void);
|
||||
int omp_get_initial_device(void);
|
||||
void *omp_target_alloc(size_t size, int device_num);
|
||||
void omp_target_free(void *device_ptr, int device_num);
|
||||
|
@ -30,6 +30,15 @@ EXTERN int omp_get_num_devices(void) {
|
||||
return DevicesSize;
|
||||
}
|
||||
|
||||
EXTERN int omp_get_device_num(void) {
|
||||
TIMESCOPE();
|
||||
int HostDevice = omp_get_initial_device();
|
||||
|
||||
DP("Call to omp_get_device_num returning %d\n", HostDevice);
|
||||
|
||||
return HostDevice;
|
||||
}
|
||||
|
||||
EXTERN int omp_get_initial_device(void) {
|
||||
TIMESCOPE();
|
||||
int hostDevice = omp_get_num_devices();
|
||||
|
@ -29,6 +29,7 @@ VERS1.0 {
|
||||
__kmpc_push_target_tripcount;
|
||||
__kmpc_push_target_tripcount_mapper;
|
||||
omp_get_num_devices;
|
||||
omp_get_device_num;
|
||||
omp_get_initial_device;
|
||||
omp_target_alloc;
|
||||
omp_target_free;
|
||||
|
33
openmp/libomptarget/test/api/omp_get_device_num.c
Normal file
33
openmp/libomptarget/test/api/omp_get_device_num.c
Normal file
@ -0,0 +1,33 @@
|
||||
// RUN: %libomptarget-compile-run-and-check-generic
|
||||
|
||||
#include <stdio.h>
|
||||
#include <omp.h>
|
||||
|
||||
int test_omp_get_device_num()
|
||||
{
|
||||
/* checks that omp_get_device_num() == omp_get_num_devices() in the host */
|
||||
int device_num = omp_get_device_num();
|
||||
printf("device_num = %d\n", device_num);
|
||||
|
||||
#pragma omp target
|
||||
{}
|
||||
|
||||
return (device_num == omp_get_num_devices());
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
int i;
|
||||
int failed=0;
|
||||
|
||||
if (!test_omp_get_device_num()) {
|
||||
failed++;
|
||||
}
|
||||
if (failed)
|
||||
printf("FAIL\n");
|
||||
else
|
||||
printf("PASS\n");
|
||||
return failed;
|
||||
}
|
||||
|
||||
// CHECK: PASS
|
27
openmp/runtime/test/api/omp_get_device_num.c
Normal file
27
openmp/runtime/test/api/omp_get_device_num.c
Normal file
@ -0,0 +1,27 @@
|
||||
// RUN: %libomp-compile-and-run
|
||||
// Linking fails for icc 18
|
||||
// UNSUPPORTED: icc-18
|
||||
|
||||
#include <stdio.h>
|
||||
#include "omp_testsuite.h"
|
||||
|
||||
int test_omp_get_device_num()
|
||||
{
|
||||
/* checks that omp_get_device_num */
|
||||
int device_num = omp_get_device_num();
|
||||
|
||||
return (device_num == omp_get_num_devices());
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
int i;
|
||||
int num_failed=0;
|
||||
|
||||
for(i = 0; i < REPETITIONS; i++) {
|
||||
if(!test_omp_get_device_num()) {
|
||||
num_failed++;
|
||||
}
|
||||
}
|
||||
return num_failed;
|
||||
}
|
Loading…
Reference in New Issue
Block a user