1 //===------------- target_interface.h - Target interfaces --------- C++ -*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 // This file contains interfaces that must be implemented by each target.
11 //===----------------------------------------------------------------------===//
13 #ifndef _OMPTARGET_TARGET_INTERFACE_H_
14 #define _OMPTARGET_TARGET_INTERFACE_H_
18 #include "DeviceEnvironment.h"
19 #include "target_impl.h"
21 // Calls to the NVPTX layer (assuming 1D layout)
22 EXTERN
int __kmpc_get_hardware_thread_id_in_block();
23 EXTERN
int GetBlockIdInKernel();
24 EXTERN NOINLINE
int __kmpc_get_hardware_num_blocks();
25 EXTERN NOINLINE
int __kmpc_get_hardware_num_threads_in_block();
26 EXTERN
unsigned __kmpc_get_warp_size();
27 EXTERN
unsigned GetWarpId();
28 EXTERN
unsigned GetLaneId();
31 uint32_t __kmpc_atomic_add(uint32_t *, uint32_t);
32 uint32_t __kmpc_atomic_inc(uint32_t *, uint32_t);
33 uint32_t __kmpc_atomic_max(uint32_t *, uint32_t);
34 uint32_t __kmpc_atomic_exchange(uint32_t *, uint32_t);
35 uint32_t __kmpc_atomic_cas(uint32_t *, uint32_t, uint32_t);
36 static_assert(sizeof(unsigned long long) == sizeof(uint64_t), "");
37 unsigned long long __kmpc_atomic_exchange(unsigned long long *,
39 unsigned long long __kmpc_atomic_add(unsigned long long *, unsigned long long);
42 EXTERN
void __kmpc_impl_init_lock(omp_lock_t
*lock
);
43 EXTERN
void __kmpc_impl_destroy_lock(omp_lock_t
*lock
);
44 EXTERN
void __kmpc_impl_set_lock(omp_lock_t
*lock
);
45 EXTERN
void __kmpc_impl_unset_lock(omp_lock_t
*lock
);
46 EXTERN
int __kmpc_impl_test_lock(omp_lock_t
*lock
);
48 EXTERN
void __kmpc_impl_threadfence();
49 EXTERN
void __kmpc_impl_threadfence_block();
50 EXTERN
void __kmpc_impl_threadfence_system();
52 EXTERN
double __kmpc_impl_get_wtick();
53 EXTERN
double __kmpc_impl_get_wtime();
55 EXTERN
void __kmpc_impl_unpack(uint64_t val
, uint32_t &lo
, uint32_t &hi
);
56 EXTERN
uint64_t __kmpc_impl_pack(uint32_t lo
, uint32_t hi
);
57 EXTERN __kmpc_impl_lanemask_t
__kmpc_impl_lanemask_lt();
58 EXTERN __kmpc_impl_lanemask_t
__kmpc_impl_lanemask_gt();
59 EXTERN
uint32_t __kmpc_impl_smid();
61 EXTERN __kmpc_impl_lanemask_t
__kmpc_impl_activemask();
63 EXTERN
void __kmpc_impl_syncthreads();
64 EXTERN
void __kmpc_impl_syncwarp(__kmpc_impl_lanemask_t Mask
);
66 // Kernel initialization
67 EXTERN
void __kmpc_impl_target_init();
70 EXTERN
void *__kmpc_impl_malloc(size_t);
71 EXTERN
void __kmpc_impl_free(void *);
73 // Barrier until num_threads arrive.
74 EXTERN
void __kmpc_impl_named_sync(uint32_t num_threads
);
76 extern DeviceEnvironmentTy omptarget_device_environment
;
78 #endif // _OMPTARGET_TARGET_INTERFACE_H_