cean_util.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. /*
  2. Copyright (c) 2014-2016 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. #include "offload_util.h"
  30. // CEAN expression representation
  31. struct Dim_Desc {
  32. int64_t size; // Length of data type
  33. int64_t lindex; // Lower index
  34. int64_t lower; // Lower section bound
  35. int64_t upper; // Upper section bound
  36. int64_t stride; // Stride
  37. };
  38. struct Arr_Desc {
  39. int64_t base; // Base address
  40. int64_t rank; // Rank of array
  41. Dim_Desc dim[1];
  42. };
  43. struct CeanReadDim {
  44. int64_t count; // The number of elements in this dimension
  45. int64_t size; // The number of bytes between successive
  46. // elements in this dimension.
  47. };
  48. struct CeanReadRanges {
  49. Arr_Desc* arr_desc;
  50. void * ptr;
  51. int64_t current_number; // the number of ranges read
  52. int64_t range_max_number; // number of contiguous ranges
  53. int64_t range_size; // size of max contiguous range
  54. int last_noncont_ind; // size of Dim array
  55. int64_t init_offset; // offset of 1-st element from array left bound
  56. CeanReadDim Dim[1];
  57. };
  58. struct IntervalDesc {
  59. int64_t lower; // Lower index
  60. int64_t size; // Size of each element at this interval
  61. };
  62. struct NonContigDesc {
  63. int64_t base; // Base address
  64. int64_t interval_cnt; // Number of intervals
  65. struct IntervalDesc interval[1];
  66. };
  67. // array descriptor length
  68. #define __arr_desc_length(rank) \
  69. (sizeof(int64_t) + sizeof(Dim_Desc) * (rank))
  70. // returns offset and length of the data to be transferred
  71. DLL_LOCAL void __arr_data_offset_and_length(const Arr_Desc *adp,
  72. int64_t &offset,
  73. int64_t &length);
  74. // define if data array described by argument is contiguous one
  75. DLL_LOCAL bool is_arr_desc_contiguous(const Arr_Desc *ap);
  76. // allocate element of CeanReadRanges type initialized
  77. // to read consequently contiguous ranges described by "ap" argument
  78. DLL_LOCAL CeanReadRanges * init_read_ranges_arr_desc(const Arr_Desc *ap);
  79. // check if ranges described by 1 argument could be transferred into ranges
  80. // described by 2-nd one
  81. DLL_LOCAL bool cean_ranges_match(
  82. CeanReadRanges * read_rng1,
  83. CeanReadRanges * read_rng2
  84. );
  85. // first argument - returned value by call to init_read_ranges_arr_desc.
  86. // returns true if offset and length of next range is set successfuly.
  87. // returns false if the ranges is over.
  88. DLL_LOCAL bool get_next_range(
  89. CeanReadRanges * read_rng,
  90. int64_t *offset
  91. );
  92. // returns number of transferred bytes
  93. DLL_LOCAL int64_t cean_get_transf_size(CeanReadRanges * read_rng);
  94. #if OFFLOAD_DEBUG > 0
  95. // prints array descriptor contents to stderr
  96. DLL_LOCAL void __arr_desc_dump(
  97. const char *spaces,
  98. const char *name,
  99. const Arr_Desc *adp,
  100. bool dereference,
  101. bool print_values);
  102. DLL_LOCAL void noncont_struct_dump(
  103. const char *spaces,
  104. const char *name,
  105. struct NonContigDesc *desc_p);
  106. DLL_LOCAL int64_t get_noncont_struct_size(struct NonContigDesc *desc_p);
  107. #define ARRAY_DESC_DUMP(spaces, name, adp, dereference, print_values) \
  108. if (console_enabled >= 2) \
  109. __arr_desc_dump(spaces, name, adp, dereference, print_values);
  110. #else
  111. #define ARRAY_DESC_DUMP(spaces, name, adp, dereference, print_values)
  112. #endif // OFFLOAD_DEBUG
  113. #endif // CEAN_UTIL_H_INCLUDED