cean_util.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /*
  2. Copyright (c) 2014 Intel Corporation. All Rights Reserved.
  3. Redistribution and use in source and binary forms, with or without
  4. modification, are permitted provided that the following conditions
  5. are met:
  6. * Redistributions of source code must retain the above copyright
  7. notice, this list of conditions and the following disclaimer.
  8. * Redistributions in binary form must reproduce the above copyright
  9. notice, this list of conditions and the following disclaimer in the
  10. documentation and/or other materials provided with the distribution.
  11. * Neither the name of Intel Corporation nor the names of its
  12. contributors may be used to endorse or promote products derived
  13. from this software without specific prior written permission.
  14. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  15. "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  16. LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  17. A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  18. HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  19. SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  20. LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  21. DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  22. THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  23. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  24. OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  25. */
  26. #ifndef CEAN_UTIL_H_INCLUDED
  27. #define CEAN_UTIL_H_INCLUDED
  28. #include <stdint.h>
  29. // CEAN expression representation
  30. struct dim_desc {
  31. int64_t size; // Length of data type
  32. int64_t lindex; // Lower index
  33. int64_t lower; // Lower section bound
  34. int64_t upper; // Upper section bound
  35. int64_t stride; // Stride
  36. };
  37. struct arr_desc {
  38. int64_t base; // Base address
  39. int64_t rank; // Rank of array
  40. dim_desc dim[1];
  41. };
  42. struct CeanReadDim {
  43. int64_t count; // The number of elements in this dimension
  44. int64_t size; // The number of bytes between successive
  45. // elements in this dimension.
  46. };
  47. struct CeanReadRanges {
  48. void * ptr;
  49. int64_t current_number; // the number of ranges read
  50. int64_t range_max_number; // number of contiguous ranges
  51. int64_t range_size; // size of max contiguous range
  52. int last_noncont_ind; // size of Dim array
  53. int64_t init_offset; // offset of 1-st element from array left bound
  54. CeanReadDim Dim[1];
  55. };
  56. // array descriptor length
  57. #define __arr_desc_length(rank) \
  58. (sizeof(int64_t) + sizeof(dim_desc) * (rank))
  59. // returns offset and length of the data to be transferred
  60. void __arr_data_offset_and_length(const arr_desc *adp,
  61. int64_t &offset,
  62. int64_t &length);
  63. // define if data array described by argument is contiguous one
  64. bool is_arr_desc_contiguous(const arr_desc *ap);
  65. // allocate element of CeanReadRanges type initialized
  66. // to read consequently contiguous ranges described by "ap" argument
  67. CeanReadRanges * init_read_ranges_arr_desc(const arr_desc *ap);
  68. // check if ranges described by 1 argument could be transfered into ranges
  69. // described by 2-nd one
  70. bool cean_ranges_match(
  71. CeanReadRanges * read_rng1,
  72. CeanReadRanges * read_rng2
  73. );
  74. // first argument - returned value by call to init_read_ranges_arr_desc.
  75. // returns true if offset and length of next range is set successfuly.
  76. // returns false if the ranges is over.
  77. bool get_next_range(
  78. CeanReadRanges * read_rng,
  79. int64_t *offset
  80. );
  81. // returns number of transfered bytes
  82. int64_t cean_get_transf_size(CeanReadRanges * read_rng);
  83. #if OFFLOAD_DEBUG > 0
  84. // prints array descriptor contents to stderr
  85. void __arr_desc_dump(
  86. const char *spaces,
  87. const char *name,
  88. const arr_desc *adp,
  89. bool dereference);
  90. #else
  91. #define __arr_desc_dump(
  92. spaces,
  93. name,
  94. adp,
  95. dereference)
  96. #endif // OFFLOAD_DEBUG
  97. #endif // CEAN_UTIL_H_INCLUDED