Files
clang-p2996/openmp/libomptarget/deviceRTLs/common/support.h
Johannes Doerfert cd0ea03e6f [OpenMP][NFC] Remove unused and untested code from the device runtime
Summary:
We carried a lot of unused and untested code in the device runtime.
Among other reasons, we are planning major rewrites for which reduced
size is going to help a lot.

The number of code lines reduced by 14%!

Before:
-------------------------------------------------------------------------------
Language                     files          blank        comment           code
-------------------------------------------------------------------------------
CUDA                            13            489            841           2454
C/C++ Header                    14            322            493           1377
C                               12            117            124            559
CMake                            4             64             64            262
C++                              1              6              6             39
-------------------------------------------------------------------------------
SUM:                            44            998           1528           4691
-------------------------------------------------------------------------------

After:
-------------------------------------------------------------------------------
Language                     files          blank        comment           code
-------------------------------------------------------------------------------
CUDA                            13            366            733           1879
C/C++ Header                    14            317            484           1293
C                               12            117            124            559
CMake                            4             64             64            262
C++                              1              6              6             39
-------------------------------------------------------------------------------
SUM:                            44            870           1411           4032
-------------------------------------------------------------------------------

Reviewers: hfinkel, jhuber6, fghanim, JonChesterfield, grokos, AndreyChurbanov, ye-luo, tianshilei1992, ggeorgakoudis, Hahnfeld, ABataev, hbae, ronlieb, gregrodgers

Subscribers: jvesely, yaxunl, bollu, guansong, jfb, sstefan1, aaron.ballman, openmp-commits, cfe-commits

Tags: #clang, #openmp

Differential Revision: https://reviews.llvm.org/D83349
2020-07-10 19:09:41 -05:00

99 lines
3.7 KiB
C

//===--------- support.h - OpenMP GPU support functions ---------- CUDA -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
// Wrapper to some functions natively supported by the GPU.
//
//===----------------------------------------------------------------------===//
#ifndef OMPTARGET_SUPPORT_H
#define OMPTARGET_SUPPORT_H
#include "interface.h"
#include "target_impl.h"
////////////////////////////////////////////////////////////////////////////////
// Execution Parameters
////////////////////////////////////////////////////////////////////////////////
enum ExecutionMode {
Spmd = 0x00u,
Generic = 0x01u,
ModeMask = 0x01u,
};
enum RuntimeMode {
RuntimeInitialized = 0x00u,
RuntimeUninitialized = 0x02u,
RuntimeMask = 0x02u,
};
DEVICE void setExecutionParameters(ExecutionMode EMode, RuntimeMode RMode);
DEVICE bool isGenericMode();
DEVICE bool isSPMDMode();
DEVICE bool isRuntimeUninitialized();
DEVICE bool isRuntimeInitialized();
////////////////////////////////////////////////////////////////////////////////
// Execution Modes based on location parameter fields
////////////////////////////////////////////////////////////////////////////////
DEVICE bool checkSPMDMode(kmp_Ident *loc);
DEVICE bool checkGenericMode(kmp_Ident *loc);
DEVICE bool checkRuntimeUninitialized(kmp_Ident *loc);
DEVICE bool checkRuntimeInitialized(kmp_Ident *loc);
////////////////////////////////////////////////////////////////////////////////
// get info from machine
////////////////////////////////////////////////////////////////////////////////
// get global ids to locate tread/team info (constant regardless of OMP)
DEVICE int GetLogicalThreadIdInBlock(bool isSPMDExecutionMode);
DEVICE int GetMasterThreadID();
DEVICE int GetNumberOfWorkersInTeam();
// get OpenMP thread and team ids
DEVICE int GetOmpThreadId(int threadId,
bool isSPMDExecutionMode); // omp_thread_num
DEVICE int GetOmpTeamId(); // omp_team_num
// get OpenMP number of threads and team
DEVICE int GetNumberOfOmpThreads(bool isSPMDExecutionMode); // omp_num_threads
DEVICE int GetNumberOfOmpTeams(); // omp_num_teams
// get OpenMP number of procs
DEVICE int GetNumberOfProcsInTeam(bool isSPMDExecutionMode);
DEVICE int GetNumberOfProcsInDevice(bool isSPMDExecutionMode);
// masters
DEVICE int IsTeamMaster(int ompThreadId);
// Parallel level
DEVICE void IncParallelLevel(bool ActiveParallel, __kmpc_impl_lanemask_t Mask);
DEVICE void DecParallelLevel(bool ActiveParallel, __kmpc_impl_lanemask_t Mask);
////////////////////////////////////////////////////////////////////////////////
// Memory
////////////////////////////////////////////////////////////////////////////////
// safe alloc and free
DEVICE void *SafeMalloc(size_t size, const char *msg); // check if success
DEVICE void *SafeFree(void *ptr, const char *msg);
// pad to a alignment (power of 2 only)
DEVICE unsigned long PadBytes(unsigned long size, unsigned long alignment);
#define ADD_BYTES(_addr, _bytes) \
((void *)((char *)((void *)(_addr)) + (_bytes)))
#define SUB_BYTES(_addr, _bytes) \
((void *)((char *)((void *)(_addr)) - (_bytes)))
////////////////////////////////////////////////////////////////////////////////
// Teams Reduction Scratchpad Helpers
////////////////////////////////////////////////////////////////////////////////
DEVICE unsigned int *GetTeamsReductionTimestamp();
DEVICE char *GetTeamsReductionScratchpad();
#endif