1// 2// Copyright 2010 Intel Corporation 3// 4// Licensed under the Apache License, Version 2.0 (the "License"); 5// you may not use this file except in compliance with the License. 6// You may obtain a copy of the License at 7// 8// http://www.apache.org/licenses/LICENSE-2.0 9// 10// Unless required by applicable law or agreed to in writing, software 11// distributed under the License is distributed on an "AS IS" BASIS, 12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13// See the License for the specific language governing permissions and 14// limitations under the License. 15// 16#ifndef RCCE_H 17#define RCCE_H 18 19#include <stdlib.h> 20#include <stdio.h> 21 22#define _RCCE "1.0.7 release" 23// little trick to allow the application to be called "RCCE_APP" under 24// OpenMP, and "main" otherwise 25#ifndef _OPENMP 26 #define RCCE_APP main 27#endif 28 29// modify next line for BareMetal, which supports stdout, but not stdferr 30#define STDERR stdout 31 32#define LOG2_LINE_SIZE 5 33#define RCCE_LINE_SIZE (1<<LOG2_LINE_SIZE) 34// RCCE_BUFF_SIZE_MAX is space per UE, which is half of the space per tile 35#define RCCE_BUFF_SIZE_MAX (1<<13) 36#define RCCE_MAXNP 48 37#define RCCE_SUCCESS 0 38#define RCCE_ERROR_BASE 1234321 39#define RCCE_ERROR_TARGET (RCCE_ERROR_BASE + 1) 40#define RCCE_ERROR_SOURCE (RCCE_ERROR_BASE + 2) 41#define RCCE_ERROR_ID (RCCE_ERROR_BASE + 3) 42#define RCCE_ERROR_MESSAGE_LENGTH (RCCE_ERROR_BASE + 4) 43#define RCCE_ERROR_FLAG_UNDEFINED (RCCE_ERROR_BASE + 5) 44#define RCCE_ERROR_NUM_UES (RCCE_ERROR_BASE + 6) 45#define RCCE_ERROR_DATA_OVERLAP (RCCE_ERROR_BASE + 7) 46#define RCCE_ERROR_ALIGNMENT (RCCE_ERROR_BASE + 8) 47#define RCCE_ERROR_DEBUG_FLAG (RCCE_ERROR_BASE + 9) 48#define RCCE_ERROR_FLAG_NOT_IN_COMM_BUFFER (RCCE_ERROR_BASE + 10) 49#define RCCE_ERROR_FLAG_STATUS_UNDEFINED (RCCE_ERROR_BASE + 11) 50#define RCCE_ERROR_FLAG_NOT_ALLOCATED (RCCE_ERROR_BASE + 12) 51#define RCCE_ERROR_VAL_UNDEFINED (RCCE_ERROR_BASE + 13) 52#define RCCE_ERROR_INVALID_ERROR_CODE (RCCE_ERROR_BASE + 14) 53#define RCCE_ERROR_RPC_NOT_ALLOCATED (RCCE_ERROR_BASE + 15) 54#define RCCE_ERROR_RPC_INTERNAL (RCCE_ERROR_BASE + 16) 55#define RCCE_ERROR_MULTIPLE_RPC_REQUESTS (RCCE_ERROR_BASE + 17) 56#define RCCE_ERROR_FDIVIDER (RCCE_ERROR_BASE + 18) 57#define RCCE_ERROR_FREQUENCY_EXCEEDED (RCCE_ERROR_BASE + 19) 58#define RCCE_ERROR_NO_ACTIVE_RPC_REQUEST (RCCE_ERROR_BASE + 20) 59#define RCCE_ERROR_STALE_RPC_REQUEST (RCCE_ERROR_BASE + 21) 60#define RCCE_ERROR_COMM_UNDEFINED (RCCE_ERROR_BASE + 22) 61#define RCCE_ERROR_ILLEGAL_OP (RCCE_ERROR_BASE + 23) 62#define RCCE_ERROR_ILLEGAL_TYPE (RCCE_ERROR_BASE + 24) 63#define RCCE_ERROR_MALLOC (RCCE_ERROR_BASE + 25) 64#define RCCE_ERROR_COMM_INITIALIZED (RCCE_ERROR_BASE + 26) 65#define RCCE_ERROR_CORE_NOT_IN_HOSTFILE (RCCE_ERROR_BASE + 27) 66#define RCCE_MAX_ERROR_STRING 45 67 68#define RCCE_DEBUG_ALL 111111 69#define RCCE_DEBUG_SYNCH 111444 70#define RCCE_DEBUG_COMM 111555 71#define RCCE_DEBUG_RPC 111666 72#define RCCE_DEBUG_DEBUG 111888 73 74#define RCCE_FLAG_SET 1 75#define RCCE_FLAG_UNSET 0 76 77#define RCCE_NUM_OPS 4 78#define RCCE_OP_BASE 23232323 79#define RCCE_SUM (RCCE_OP_BASE) 80#define RCCE_MIN (RCCE_OP_BASE+1) 81#define RCCE_MAX (RCCE_OP_BASE+2) 82#define RCCE_PROD (RCCE_OP_BASE+3) 83 84#define RCCE_TYPE_BASE 63636363 85#define RCCE_INT (RCCE_TYPE_BASE) 86#define RCCE_LONG (RCCE_TYPE_BASE+1) 87#define RCCE_FLOAT (RCCE_TYPE_BASE+2) 88#define RCCE_DOUBLE (RCCE_TYPE_BASE+3) 89 90// MPB pointer type 91typedef volatile unsigned char* t_vcharp; 92 93#ifdef SINGLEBITFLAGS 94typedef struct { 95 int location; /* location of bit within line (0-255) */ 96 t_vcharp line_address; /* start of cache line containing flag */ 97} RCCE_FLAG; 98#else 99typedef volatile int *RCCE_FLAG; 100#endif 101 102typedef int RCCE_FLAG_STATUS; 103typedef struct { 104 int size; 105 int my_rank; 106 int initialized; 107 int member[RCCE_MAXNP]; 108 RCCE_FLAG gather; 109 RCCE_FLAG release; 110} RCCE_COMM; 111 112#ifdef RC_POWER_MANAGEMENT 113typedef struct{ 114 int release; 115 int old_voltage_level; 116 int new_voltage_level; 117 int old_frequency_divider; 118 int new_frequency_divider; 119 long long start_cycle; 120 } RCCE_REQUEST; 121int RCCE_power_domain(void); 122int RCCE_iset_power(int, RCCE_REQUEST *, int *, int *); 123int RCCE_wait_power(RCCE_REQUEST *); 124int RCCE_set_frequency_divider(int, int *); 125int RCCE_power_domain_master(void); 126int RCCE_power_domain_size(void); 127#endif 128 129int RCCE_init(int *, char***); 130int RCCE_finalize(void); 131double RCCE_wtime(void); 132int RCCE_ue(void); 133int RCCE_num_ues(void); 134#ifdef GORY 135t_vcharp RCCE_malloc(size_t); 136t_vcharp RCCE_malloc_request(size_t, size_t *); 137void RCCE_free(t_vcharp); 138int RCCE_put(t_vcharp, t_vcharp, int, int); 139int RCCE_get(t_vcharp, t_vcharp, int, int); 140int RCCE_wait_until(RCCE_FLAG, RCCE_FLAG_STATUS); 141int RCCE_flag_alloc(RCCE_FLAG *); 142int RCCE_flag_free(RCCE_FLAG *); 143int RCCE_flag_write(RCCE_FLAG *, RCCE_FLAG_STATUS, int); 144int RCCE_flag_read(RCCE_FLAG, RCCE_FLAG_STATUS *, int); 145int RCCE_send(char *, t_vcharp, size_t, RCCE_FLAG *, RCCE_FLAG *, size_t, int); 146int RCCE_recv(char *, t_vcharp, size_t, RCCE_FLAG *, RCCE_FLAG *, size_t, int); 147int RCCE_recv_test(char *, t_vcharp, size_t, RCCE_FLAG *, RCCE_FLAG *, 148 size_t, int, int *); 149#else 150int RCCE_send(char *, size_t, int); 151int RCCE_recv(char *, size_t, int); 152int RCCE_recv_test(char *, size_t, int, int *); 153int RCCE_allreduce(char *, char *, int, int, int, RCCE_COMM); 154int RCCE_reduce(char *, char *, int, int, int, int, RCCE_COMM); 155int RCCE_bcast(char *, size_t, int, RCCE_COMM); 156#endif 157int RCCE_comm_split(int (*)(int, void *), void *, RCCE_COMM *); 158int RCCE_comm_free(RCCE_COMM *); 159int RCCE_comm_size(RCCE_COMM, int *); 160int RCCE_comm_rank(RCCE_COMM, int *); 161void RCCE_fence(void); 162int RCCE_barrier(RCCE_COMM *); 163int RCCE_error_string(int, char *, int *); 164int RCCE_debug_set(int); 165int RCCE_debug_unset(int); 166 167extern RCCE_COMM RCCE_COMM_WORLD; 168#ifdef RC_POWER_MANAGEMENT 169extern RCCE_COMM RCCE_P_COMM; 170#define RCCE_POWER_DEFAULT -99999 171#endif 172 173#ifdef _OPENMP 174#pragma omp threadprivate (RCCE_COMM_WORLD) 175#ifdef RC_POWER_MANAGEMENT 176#pragma omp threadprivate (RCCE_P_COMM) 177#endif 178#endif 179 180#endif 181 182