1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619
|
/*
* Copyright 2010-2013 Intel Corporation.
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation, version 2.1.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA.
*
* Disclaimer: The codes contained in these modules may be specific
* to the Intel Software Development Platform codenamed Knights Ferry,
* and the Intel product codenamed Knights Corner, and are not backward
* compatible with other Intel products. Additionally, Intel will NOT
* support the codes or instruction set in future products.
*
* Intel offers no warranty of any kind regarding the code. This code is
* licensed on an "AS IS" basis and Intel is not obligated to provide
* any support, assistance, installation, training, or other services
* of any kind. Intel is also not obligated to provide any updates,
* enhancements or extensions. Intel specifically disclaims any warranty
* of merchantability, non-infringement, fitness for any particular
* purpose, and any other warranty.
*
* Further, Intel disclaims all liability of any kind, including but
* not limited to liability for infringement of any proprietary rights,
* relating to the use of the code, even if Intel is notified of the
* possibility of such liability. Except as expressly stated in an Intel
* license agreement provided with this code and agreed upon with Intel,
* no license, express or implied, by estoppel or otherwise, to any
* intellectual property rights is granted herein.
*/
/**
* Description:
* External APIs of MYO runtime (MYO stands for Mine, Yours and Ours).
**/
#ifndef _MYO_H_
#define _MYO_H_
#include "myotypes.h"
#include "myoimpl.h"
/** @ingroup MYO
* @addtogroup MYO_API
@{
* @file myo.h
*/
#ifdef __cplusplus
extern "C" {
#endif
/****************************************************************************
Arena-based APIs
***************************************************************************/
/*
* Arena is a set of memory pages with the same ownership type. The ownership
* type of all the memory pages inside the same arena can only be changed as
* a whole. For "OURS", it is also the minimal unit of sync operations to
* implement "release consistency".
*/
/** @fn extern MyoError myoArenaCreate(MyoOwnershipType in_Type,
* int in_Property, MyoArena *out_pArena)
* @brief Create an arena with specified ownership type and property.
*
* @param in_Type Specified ownership type (MYO_ARENA_OURS or
* MYO_ARENA_MINE).
* @param in_Property Specified properties of the arena. Set it
* to 0 to use default properties.
*
* MYO_RELEASE_CONSISTENCY or MYO_STRONG_RELEASE_CONSISTENCY
* or MYO_STRONG_CONSISTENCY:
*
* Consistency modes for "OURS" arenas. For MYO_RELEASE_CONSISTENCY,
* there are 2 functions, "Acquire" and "Release", which are
* used for memory ordering. "Release" makes all local stores
* prior to the release globally visible; "Acquire" syncs up the
* local memory with all stores that have been made globally
* visible. However, there is no definite answer as to whether
* local stores can be globally visible before reaching a release
* point, nor whether the newest globally visible stores can be
* updated to local before reaching an acquire point. By using
* MYO_STRONG_RELEASE_CONSISTENCY, the answer to these questions
* is "no". A sequential consistency model is maintained to the
* arena when using MYO_STRONG_CONSISTENCY.
* MYO_RELEASE_CONSISTENCY is the default property.
*
* MYO_UPDATE_ON_DEMAND or MYO_UPDATE_ON_ACQUIRE:
*
* Only apply to "OURS" arenas with "Release Consistency".
* MYO_UPDATE_ON_ACQUIRE means that the shared pages of this
* arena will be updated on acquire point; MYO_UPDATE_ON_DEMAND
* means that the shared pages will not be updated until they
* are accessed. MYO_UPDATE_ON_DEMAND is the default property.
*
* MYO_RECORD_DIRTY or MYO_NOT_RECORD_DIRTY:
*
* This property controls whether to record dirty pages.
* There will be runtime overhead when recording dirty pages,
* as it can reduce the communication data. It is a trade-off
* for performance. Also when MYO_NOT_RECORD_DIRTY is set for
* "OURS" arena, the runtime cannot guarantee the correctness
* when the host and card modify the same shared page between
* the same sync segment. MYO_RECORD_DIRTY is the default
* property.
*
* MYO_ONE_VERSION or MYO_MULTI_VERSION:
*
* Only apply to "OURS" arenas with "Release Consistency". When
* MYO_MULTI_VERSION is set, this arena can only be "release" on
* HOST side and "acquire" on CARD side. Releasing the arena on
* HOST will create a new versioned data and put it into a FIFO;
* acquiring the arena on CARD will get the versioned data
* from the FIFO one by one. MYO_ONE_VERSION is the default
* property.
*
* MYO_CONSISTENCY or MYO_NO_CONSISTENCY:
*
* Only apply to "OURS" arenas with "Release Consistency". When
* MYO_NO_CONSISTENCY is set, the consistency of the arena will
* not be maintained. That is, it is a no-op operation when
* calling acquire/release for such arenas. MYO_CONSISTENCY is
* the default property.
*
* MYO_HOST_TO_DEVICE and MYO_DEVICE_TO_HOST:
*
* When it is certain that there is only one communication
* direction for this arena, it can be created with only
* MYO_HOST_TO_DEVICE or MYO_DEVICE_TO_HOST so the runtime
* can perform optimizations. The default property is
* MYO_HOST_TO_DEVICE | MYO_DEVICE_TO_HOST.
*
* @param out_pArena Used to store the handle of the created arena.
* @return
* MYO_SUCCESS; or
* an error number to indicate the error.
**/
MYOACCESSAPI
CILK_SHARED MyoError myoArenaCreate(MyoOwnershipType in_Type, int in_Property, MyoArena *out_pArena);
/** @fn extern MyoError myoArenaDestroy(MyoArena in_Arena)
* @brief Destroy an arena. As a result, the arena can not be
* referred any more.
*
* @param in_Arena Arena handle returned by previous call to
* myoArenaCreate.
* @return
* MYO_SUCCESS; or
* an error number to indicate the error.
**/
MYOACCESSAPI
CILK_SHARED MyoError myoArenaDestroy(MyoArena in_Arena);
/** @fn extern void *myoArenaMalloc(MyoArena in_Arena, size_t in_Size)
* @brief Allocates size bytes from the specified arena, and returns
* the start address of the allocated memory. The memory is not
* cleared.
*
* @param in_Arena Arena handle returned by previous call to
* myoArenaCreate.
* @param in_Size Size (bytes) of the required memory space.
* @return
* The start address of the allocated memory space.
* NULL: Failed.
**/
MYOACCESSAPI
void *myoArenaMalloc(MyoArena in_Arena, size_t in_Size);
/** @fn extern void myoArenaFree(MyoArena in_Arena, void *in_pPtr)
* @brief Frees the memory space allocated by myoArenaMalloc to the
* specified arena.
*
* @param in_Arena Arena handle returned by previous call to
* myoArenaCreate.
* @param in_pPtr The start address of the specified memory
* space, which must be retured by myoArenaMalloc.
* @return
**/
MYOACCESSAPI
void myoArenaFree(MyoArena in_Arena, void *in_pPtr);
/** @fn extern void *myoArenaAlignedMalloc(MyoArena in_Arena,
* size_t in_Size, size_t in_Alignment)
* @brief Allocates size bytes from the specified arena. The
* start address of the allocated memory will be a multiple of the
* alignment, which must be a power of two.
*
* @param in_Arena Arena handle returned by previous call to
* myoArenaCreate.
* @param in_Size Size (bytes) of the required memory space.
* @param in_Alignment The alignment value (must be a power
* of two).
* @return
* The start address of the allocated memory space.
* NULL: Failed.
**/
MYOACCESSAPI
void *myoArenaAlignedMalloc(MyoArena in_Arena, size_t in_Size, size_t in_Alignment);
/** @fn extern void myoArenaAlignedFree(MyoArena in_Arena, void *in_pPtr)
* @brief Frees the memory space allocated by myoArenaAlignedMalloc
* to the specified arena.
*
* @param in_Arena Arena handle returned by previous call to
* myoArenaCreate.
* @param in_pPtr The start address of the specified memory space,
* which must be returned by myoArenaAlignedMalloc.
* @return
**/
MYOACCESSAPI
void myoArenaAlignedFree(MyoArena in_Arena, void *in_pPtr);
/** @fn extern MyoError myoArenaAcquire(MyoArena in_Arena)
* @brief myoArenaAcquire is the sync point for "OURS" arena with
* "Release Consistency". myoArenaAcquire is used to obtain all
* stores of "OURS" arena that have been made globally visible prior
* to this point.
*
* @param in_Arena Arena handle returned by previous call to
* myoArenaCreate.
* @return
* MYO_SUCCESS; or
* an error number to indicate the error.
**/
MYOACCESSAPI
CILK_SHARED MyoError myoArenaAcquire(MyoArena in_Arena);
/** @fn extern MyoError myoArenaRelease(MyoArena in_Arena)
* @brief myoArenaRelease is the sync point for "OURS" arena with
* "Release Consistency". myoArenaRelease is used to flush all prior
* stores of "OURS" arena to be globally visible.
*
* @param in_Arena Arena handle returned by previous call to
* myoArenaCreate.
* @return
* MYO_SUCCESS; or
* an error number to indicate the error.
**/
MYOACCESSAPI
CILK_SHARED MyoError myoArenaRelease(MyoArena in_Arena);
/** @fn extern MyoError myoArenaAcquireOwnership(MyoArena in_Arena)
* @brief Changes the ownership type of the arena to MYO_ARENA_MINE.
*
* @param in_Arena Arena handle returned by previous call to
* myoArenaCreate.
* @return
* MYO_SUCCESS; or
* an error number to indicate the error.
**/
MYOACCESSAPI
MyoError myoArenaAcquireOwnership(MyoArena in_Arena);
/** @fn extern MyoError myoArenaReleaseOwnership(MyoArena in_Arena)
* @brief Change the ownership type of the arena to MYO_ARENA_OURS.
*
* @param in_Arena Arena handle returned by previous call to
* myoArenaCreate.
* @return
* MYO_SUCCESS; or
* an error number to indicate the error.
**/
MYOACCESSAPI
MyoError myoArenaReleaseOwnership(MyoArena in_Arena);
/** @fn extern MyoError myoArenaGetHandle(void *in_pPtr,
* MyoArena *out_pArena)
* @brief Gets the arena handle of the arena that contains the memory
* space pointed to by "in_pPtr". This API can be used when it is
* not clear which arena handle should be used for other arena
* related APIs.
*
* @param in_pPtr The start address of a chunk of memory space.
* @param out_pArena Handle of the arena.
* @return
* MYO_SUCCESS; or
* an error number to indicate the error.
**/
MYOACCESSAPI
CILK_SHARED MyoError myoArenaGetHandle(void *in_pPtr, MyoArena *out_pArena);
/********************************************************************************
APIs for the default arena
*******************************************************************************/
/**
* There will be a default arena inside MYO runtime, which will be used when
* there is no specified arena.
**/
/** @fn extern void* myoSharedMalloc(size_t in_Size)
* @brief Allocates size bytes from the default arena, and returns the
* start address of the allocated memory. The memory is not cleared.
*
@param in_Size Size (bytes) of the required memory space.
* @return
* The start address of the allocated memory space.
* NULL: Failed.
**/
MYOACCESSAPI
void* myoSharedMalloc(size_t in_Size);
/** @fn extern void myoSharedFree(void *in_pPtr)
* @brief Frees the memory space allocated by myoArenaMalloc to the
* default arena.
*
* @param in_pPtr The start address of the specified memory space,
* which must be retured by myoSharedMalloc.
* @return
**/
MYOACCESSAPI
void myoSharedFree(void *in_pPtr);
/** @fn extern void* myoSharedAlignedMalloc(size_t in_Size,
* size_t in_Alignment)
* @brief Allocates size bytes from the default arena. The start
* address of the allocated memory will be a multiple of alignment,
* which must be a power of two.
*
* @param in_Size Size (bytes) of the required memory space.
* @param in_Alignment The alignment value, which must be an power of two.
* @return
* The start address of the allocated memory space.
* NULL: Failed.
**/
MYOACCESSAPI
void* myoSharedAlignedMalloc(size_t in_Size, size_t in_Alignment);
/** @fn extern void myoSharedAlignedFree(void *in_pPtr)
* @brief Frees the memory space allocated by myoArenaAlignedMalloc
* to the default arena.
*
* @param in_pPtr The start address of the specified memory space,
* which must be returned by myoArenaAlignedMalloc.
* @return
**/
MYOACCESSAPI
void myoSharedAlignedFree(void *in_pPtr);
/** @fn extern MyoError myoAcquire()
* @brief myoAcquire is the sync point for the default arena with
* "Release Consistency". myoAcquire is used to obtain all stores of
* the default arena that have been made globally visible prior to
* this point.
*
* @return
* MYO_SUCCESS; or
* an error number to indicate the error.
**/
MYOACCESSAPI
MyoError myoAcquire();
/** @fn extern MyoError myoRelease()
* @brief myoRelease is the sync point for the default arena with
* "Release Consistency". myoRelease is used to flush all prior stores
* of the default arena to be globally visible.
*
* @return
* MYO_SUCCESS; or
* an error number to indicate the error.
**/
MYOACCESSAPI
MyoError myoRelease();
/** @fn extern MyoError myoAcquireOwnership()
* @brief Changes the ownership type of the default arena to
* MYO_ARENA_MINE.
*
* @return
* MYO_SUCCESS; or
* an error number to indicate the error.
**/
MYOACCESSAPI
MyoError myoAcquireOwnership();
/** @fn extern MyoError myoReleaseOwnership()
* @brief Change the ownership type of the default arena to
* MYO_ARENA_OURS.
*
* @return
* MYO_SUCCESS; or
* an error number to indicate the error.
**/
MYOACCESSAPI
MyoError myoReleaseOwnership();
/*****************************************************************************
APIs for global sync operations.
*****************************************************************************/
/** @fn extern MyoError myoMutexCreate(MyoMutex *out_pMutex)
* @brief Create a mutex and return the mutex handle.
*
* @param out_pMutex Used to store the handle of the created mutex.
* @return
* MYO_SUCCESS; or
* an error number to indicate the error.
**/
MYOACCESSAPI
MyoError myoMutexCreate(MyoMutex *out_pMutex);
/** @fn extern MyoError myoMutexLock(MyoMutex in_Mutex)
* @brief Lock the mutex. If the mutex is already locked by other peers,
* the call blocks until the mutex becomes available. Currently,
* attempting to re-acquire the mutex will cause a deadlock.
*
* @param in_Mutex the mutex handle returned by myoMutexCreate.
* @return
* MYO_SUCCESS; or
* an error number to indicate the error.
**/
MYOACCESSAPI
MyoError myoMutexLock(MyoMutex in_Mutex);
/** @fn extern MyoError myoMutexUnlock(MyoMutex in_Mutex)
* @brief Release the locked mutex.
* Currently, attempting to release an unlocked mutex will cause
* undefined results.
*
* @param in_Mutex the mutex handle returned by myoMutexCreate.
* @return
* MYO_SUCCESS; or
* an error number to indicate the error.
**/
MYOACCESSAPI
MyoError myoMutexUnlock(MyoMutex in_Mutex);
/** @fn extern MyoError myoMutexTryLock(MyoMutex in_Mutex)
* @brief Try to lock the mutex. myoMutexTryLock is equivalent to
* myoMutexLock, except that myoMutexLock will return immediately if
* the mutex is already locked.
*
* @param in_Mutex the mutex handle returned by myoMutexCreate.
* @return
* MYO_SUCCESS; or
* an error number to indicate the error.
**/
MYOACCESSAPI
MyoError myoMutexTryLock(MyoMutex in_Mutex);
/** @fn extern MyoError myoMutexDestroy(MyoMutex in_Mutex)
* @brief Destroy the mutex.
*
* @param in_Mutex the mutex handle returned by myoMutexCreate.
* @return
* MYO_SUCCESS; or
* an error number to indicate the error.
**/
MYOACCESSAPI
MyoError myoMutexDestroy(MyoMutex in_Mutex);
/** @fn extern MyoError myoSemCreate(int in_Value, MyoSem *out_pSem)
* @brief Create a semaphore and return the semaphore handle.
*
* @param in_Value the initial value for the semaphore.
* @param out_pSem Used to store the handle of the created semaphore.
* @return
* MYO_SUCCESS; or
* an error number to indicate the error.
**/
MYOACCESSAPI
MyoError myoSemCreate(int in_Value, MyoSem *out_pSem);
/** @fn extern MyoError myoSemWait(MyoSem in_Sem)
* @brief Decrements (locks) the semaphore. If the semaphore value is
* greater than zero, then the decrement proceeds and the function
* returns immediately, or else the call blocks until the semaphore
* value rises above zero.
*
* @param in_Sem the semaphore handle returned by myoSemCreate.
* @return
* MYO_SUCCESS; or
* an error number to indicate the error.
**/
MYOACCESSAPI
MyoError myoSemWait(MyoSem in_Sem);
/** @fn extern MyoError myoSemPost(MyoSem in_Sem)
* @brief Increments (unlocks) the semaphore. If the semaphore value
* becomes greater than zero, one blocked myoSemWait call will be
* notified to return.
*
* @param in_Sem the semaphore handle returned by myoSemCreate.
* @return
* MYO_SUCCESS; or
* an error number to indicate the error.
**/
MYOACCESSAPI
MyoError myoSemPost(MyoSem in_Sem);
/** @fn extern MyoError myoSemTryWait(MyoSem in_Sem)
* @brief Try to lock semaphore. myoSemTryWait is the same as
* myoSemAcquire, except that if the decrement cannot be immediately
* performed, then the call returns instead of blocking.
*
* @param in_Sem the semaphore handle returned by myoSemCreate.
* @return
* MYO_SUCCESS; or
* an error number to indicate the error.
**/
MYOACCESSAPI
MyoError myoSemTryWait(MyoSem in_Sem);
/** @fn extern MyoError myoSemDestroy(MyoSem in_Sem)
* @brief Destroy the semaphore.
*
* @param in_Sem the semaphore handle returned by myoSemCreate.
* @return
* MYO_SUCCESS; or
* an error number to indicate the error.
**/
MYOACCESSAPI
MyoError myoSemDestroy(MyoSem in_Sem);
/** @fn extern MyoError myoBarrierCreate(int in_Count, MyoBarrier *out_pBarrier)
* @brief Create a barrier and return the barrier handle.
*
* @param in_Count the number of threads that must call
* myoBarrierWait before any of them successfully return.
* @param out_pBarrier Used to store the handle of the created
* barrier.
* @return
* MYO_SUCCESS; or
* an error number to indicate the error.
**/
MYOACCESSAPI
MyoError myoBarrierCreate(int in_Count, MyoBarrier *out_pBarrier);
/** @fn extern MyoError myoBarrierWait(MyoBarrier in_Barrier)
* @brief The caller will block until the required number of threads
* have called myoBarrierWait with the same barrier handle.
*
* @param in_Barrier the barrier handle returned by myoBarrierCreate.
* @return
* MYO_SUCCESS; or
* an error number to indicate the error.
**/
MYOACCESSAPI
MyoError myoBarrierWait(MyoBarrier in_Barrier);
/** @fn extern MyoError myoBarrierDestroy(MyoBarrier in_Barrier)
* @brief Destroy the barrier.
*
* @param in_Barrier the barrier handle returned by myoBarrierCreate.
* @return
* MYO_SUCCESS; or
* an error number to indicate the error.
**/
MYOACCESSAPI
MyoError myoBarrierDestroy(MyoBarrier in_Barrier);
/*****************************************************************************
MISC APIs.
*****************************************************************************/
/**
* @cond INCLUDE_MYO_INTERNAL_DOCUMENTATION
**/
MYOACCESSAPI
int myoMyId();
/* int myoNumNodes() returns the number of peers, minus one, to
equal the number of cards in the system. */
MYOACCESSAPI
int myoNumNodes();
MYOACCESSAPI
unsigned long long myoTicks();
MYOACCESSAPI
unsigned long long myoWallTime();
MYOACCESSAPI
void myoStatOn();
MYOACCESSAPI
void myoStatOff();
/** @fn extern MyoError myoGetMemUsage(uint64 *out_memUsedMB)
* @brief Retrieves the amount of shared memory currently used.
* myoGetMemUsage() fills in out_memUsedMB when the pointer is not NULL.
*
* @param out_memUsedBytes, pointer to the current size shared memory used.
* @return
* MYO_SUCCESS; or
* an error number to indicate the error.
**/
MYOACCESSAPI
MyoError myoGetMemUsage(unsigned int *out_memUsedMB);
/** @fn extern MyoError myoHTimeOn(int in_On)
* @brief Toggle MYO HTime report feature on/off.
*
* @param in_On: 1 turn on MYO HTime report
* 0 turn off MYO HTime report
* @return
* MYO_SUCCESS; or
* an error number to indicate the error.
**/
extern MyoError myoHTimeOn(int in_On);
#ifdef __cplusplus
}
#endif
#endif
/**
* @endcond
**/
/*! @} */
|