forked from apache/tvm
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[CherryPick][Intrinsic] lower_bound and upper_bound for binary search…
… in Sparse TIR. (apache#483) (#4) * upd * upd * fix * upd * upd * upd * upd * upd * fix * upd * upd * upd * upd * upd * upd * upd * codegen-rule * upd * upd * test * upd * fix * two arguments Co-authored-by: Zihao Ye <[email protected]>
- Loading branch information
1 parent
7d90bc5
commit a701744
Showing
10 changed files
with
247 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
/*! | ||
* \file cuda_binary_search.h | ||
* \brief Binary search function definition for cuda codegen. | ||
*/ | ||
#ifndef TVM_TARGET_SOURCE_LITERAL_CUDA_BINARY_SEARCH_H_ | ||
#define TVM_TARGET_SOURCE_LITERAL_CUDA_BINARY_SEARCH_H_ | ||
|
||
static constexpr const char* _cuda_binary_search_def = R"( | ||
template <typename DType> | ||
__forceinline__ __device__ int32_t __lower_bound( | ||
const DType* __restrict__ arr, | ||
DType val, | ||
int32_t l, | ||
int32_t r) { | ||
int32_t low = l - 1, high = r; | ||
/* loop invariant: low < mid < high, arr[low] < val, arr[high] >= val */ | ||
while (low + 1 < high) { | ||
int32_t mid = (low + high) >> 1; | ||
if (arr[mid] < val) { | ||
low = mid; | ||
} else { | ||
high = mid; | ||
} | ||
} | ||
// high = low + 1, arr[low] < val, arr[high] >= val | ||
return high; | ||
} | ||
template <typename DType> | ||
__forceinline__ __device__ int32_t __upper_bound( | ||
const DType* __restrict__ arr, | ||
DType val, | ||
int32_t l, | ||
int32_t r) { | ||
int32_t low = l - 1, high = r; | ||
/* loop invariant: low < mid < high, arr[low] < val, arr[high] > val */ | ||
while (low + 1 < high) { | ||
int32_t mid = (low + high) >> 1; | ||
if (arr[mid] > val) { | ||
high = mid; | ||
} else { | ||
low = mid; | ||
} | ||
} | ||
// high = low + 1, arr[low] <= val, arr[high] > val | ||
return high; | ||
} | ||
)"; | ||
|
||
#endif // TVM_TARGET_SOURCE_LITERAL_CUDA_BINARY_SEARCH_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters