Skip to content

Commit

Permalink
Format C and Cuda code with clang-format using its default style
Browse files Browse the repository at this point in the history
  • Loading branch information
oschuett committed Aug 19, 2020
1 parent 0bcd69a commit f0bff68
Show file tree
Hide file tree
Showing 30 changed files with 4,098 additions and 4,291 deletions.
21 changes: 12 additions & 9 deletions src/base/machine_cpuid.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,19 @@
extern "C" {
#endif

/* This routine determines the CPUID according to the given compiler flags (expected to be similar to Fortran).
* Similar to other Fortran compilers, "gfortran -E -dM -mavx - < /dev/null | grep AVX" defines a variety of
* predefined macros (also similar to C). However, with a Fortran translation unit only a subset of these
* definitions disappears ("gfortran -E -dM -mavx my.F | grep AVX") hence an implementation in C is used.
*/
//******************************************************************************
// \brief This routine determines the CPUID according to the given compiler
// flags (expected to be similar to Fortran). Similar to other Fortran
// compilers, "gfortran -E -dM -mavx - < /dev/null | grep AVX" defines a
// variety of predefined macros (also similar to C). However, with a
// Fortran translation unit only a subset of these definitions disappears
// ("gfortran -E -dM -mavx my.F | grep AVX")
// hence an implementation in C is used.
//******************************************************************************
int m_cpuid_static(void); /* avoid pedantic warning about missing prototype */
int m_cpuid_static(void)
{
#if (__AVX512F__ && __AVX512CD__ && __AVX2__ && __FMA__ && __AVX__ && __SSE4_2__ && __SSE4_1__ && __SSE3__)
int m_cpuid_static(void) {
#if (__AVX512F__ && __AVX512CD__ && __AVX2__ && __FMA__ && __AVX__ && \
__SSE4_2__ && __SSE4_1__ && __SSE3__)
return CP_MACHINE_X86_AVX512;
#elif (__AVX2__ && __FMA__ && __AVX__ && __SSE4_2__ && __SSE4_1__ && __SSE3__)
return CP_MACHINE_X86_AVX2;
Expand All @@ -34,4 +38,3 @@ int m_cpuid_static(void)
#if defined(__cplusplus)
}
#endif

8 changes: 4 additions & 4 deletions src/base/machine_cpuid.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
* Copyright (C) 2000 - 2020 CP2K developers group *
*****************************************************************************/

#define CP_MACHINE_CPU_GENERIC 0
#define CP_MACHINE_X86_SSE4 1000
#define CP_MACHINE_X86_AVX 1001
#define CP_MACHINE_X86_AVX2 1002
#define CP_MACHINE_CPU_GENERIC 0
#define CP_MACHINE_X86_SSE4 1000
#define CP_MACHINE_X86_AVX 1001
#define CP_MACHINE_X86_AVX2 1002
#define CP_MACHINE_X86_AVX512 1003
78 changes: 39 additions & 39 deletions src/common/cuda_nvtx_cu.cu
Original file line number Diff line number Diff line change
Expand Up @@ -3,62 +3,62 @@
* Copyright (C) 2000 - 2020 CP2K developers group *
*****************************************************************************/

#if defined( __CUDA_PROFILING)
#if defined(__CUDA_PROFILING)

#include <nvToolsExt.h>
#include <stdio.h>
#include <pthread.h>
#include <stdio.h>

const uint32_t colormap[] = { 0xFFFFFF00, // Yellow
0xFFFF00FF, // Fuchsia
0xFFFF0000, // Red
0xFFC0C0C0, // Silver
0xFF808080, // Gray
0xFF808000, // Olive
0xFF800080, // Purple
0xFF800000, // Maroon
0xFF00FFFF, // Aqua
0xFF00FF00, // Lime
0xFF008080, // Teal
0xFF008000, // Green
0xFF0000FF, // Blue
0xFF000080}; // Navy
const uint32_t colormap[] = {0xFFFFFF00, // Yellow
0xFFFF00FF, // Fuchsia
0xFFFF0000, // Red
0xFFC0C0C0, // Silver
0xFF808080, // Gray
0xFF808000, // Olive
0xFF800080, // Purple
0xFF800000, // Maroon
0xFF00FFFF, // Aqua
0xFF00FF00, // Lime
0xFF008080, // Teal
0xFF008000, // Green
0xFF0000FF, // Blue
0xFF000080}; // Navy

//==============================================================================
extern "C" int cuda_nvtx_range_push_cu(const char* message) {
extern "C" int cuda_nvtx_range_push_cu(const char *message) {

//assembling event attribute
nvtxEventAttributes_t eventAttrib = {0};
eventAttrib.version = NVTX_VERSION;
eventAttrib.size = NVTX_EVENT_ATTRIB_STRUCT_SIZE;
eventAttrib.messageType = NVTX_MESSAGE_TYPE_ASCII;
eventAttrib.message.ascii = message;
// assembling event attribute
nvtxEventAttributes_t eventAttrib = {0};
eventAttrib.version = NVTX_VERSION;
eventAttrib.size = NVTX_EVENT_ATTRIB_STRUCT_SIZE;
eventAttrib.messageType = NVTX_MESSAGE_TYPE_ASCII;
eventAttrib.message.ascii = message;

// colors are picked based on a (very simple) hash value of the message
int hash=0;
for (int i=0; i < strlen(message); i++)
hash += i*message[i]*message[i];
eventAttrib.colorType = NVTX_COLOR_ARGB;
eventAttrib.color = colormap[hash%14];
// colors are picked based on a (very simple) hash value of the message
int hash = 0;
for (int i = 0; i < strlen(message); i++)
hash += i * message[i] * message[i];
eventAttrib.colorType = NVTX_COLOR_ARGB;
eventAttrib.color = colormap[hash % 14];

//these field could be fild with useful stuff
eventAttrib.payloadType = NVTX_PAYLOAD_TYPE_INT64;
eventAttrib.payload.llValue = 123;
eventAttrib.category = 42;
// these field could be fild with useful stuff
eventAttrib.payloadType = NVTX_PAYLOAD_TYPE_INT64;
eventAttrib.payload.llValue = 123;
eventAttrib.category = 42;

int level = nvtxRangePushEx(&eventAttrib);
return(level);
int level = nvtxRangePushEx(&eventAttrib);
return (level);
}

//==============================================================================
extern "C" int cuda_nvtx_range_pop_cu() {
int level = nvtxRangePop();
return(level);
int level = nvtxRangePop();
return (level);
}

//==============================================================================
extern "C" void cuda_nvtx_name_osthread_cu(char* name){
nvtxNameOsThread(pthread_self(), name);
extern "C" void cuda_nvtx_name_osthread_cu(char *name) {
nvtxNameOsThread(pthread_self(), name);
}

#endif

0 comments on commit f0bff68

Please sign in to comment.