-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests: add gradient tests for all backends (#932)
* tests: add gradient checking to test-backend-ops * remove old comment * reorder includes * adjust SIN/COS parameters * add documentation, use supports_op if possible
- Loading branch information
1 parent
d3a58b0
commit d02b23d
Showing
10 changed files
with
1,080 additions
and
92 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#include "sumrows.cuh" | ||
#include "sum.cuh" | ||
|
||
#include <cstdint> | ||
|
||
#if !defined(GGML_USE_HIPBLAS) && !defined(GGML_USE_MUSA) | ||
#include <cub/cub.cuh> | ||
using namespace cub; | ||
#endif // !defined(GGML_USE_HIPBLAS) && !defined(GGML_USE_MUSA) | ||
|
||
void sum_f32_cuda(ggml_cuda_pool & pool, const float * x, float * dst, const int64_t ne, cudaStream_t stream) { | ||
#if !defined(GGML_USE_HIPBLAS) && !defined(GGML_USE_MUSA) | ||
size_t tmp_size = 0; | ||
DeviceReduce::Sum(nullptr, tmp_size, x, dst, ne, stream); | ||
ggml_cuda_pool_alloc<uint8_t> tmp_alloc(pool, tmp_size); | ||
DeviceReduce::Sum(tmp_alloc.ptr, tmp_size, x, dst, ne, stream); | ||
#else | ||
// Use (inefficient) sum_rows implementation as a fallback. | ||
// For AMD there is rocPRIM which could be used as a drop-in replacement via hipcub but this would require C++11 -> C++14. | ||
sum_rows_f32_cuda(x, dst, ne, 1, stream); | ||
GGML_UNUSED(pool); | ||
#endif // !defined(GGML_USE_HIPBLAS) && !defined(GGML_USE_MUSA) | ||
} | ||
|
||
void ggml_cuda_op_sum(ggml_backend_cuda_context & ctx, ggml_tensor * dst) { | ||
const ggml_tensor * src0 = dst->src[0]; | ||
|
||
GGML_ASSERT(src0->type == GGML_TYPE_F32); | ||
GGML_ASSERT( dst->type == GGML_TYPE_F32); | ||
GGML_ASSERT(ggml_is_contiguous(src0)); | ||
|
||
const float * src0_d = (const float *) src0->data; | ||
float * dst_d = (float *) dst->data; | ||
|
||
const int64_t ne = ggml_nelements(src0); | ||
|
||
ggml_cuda_pool & pool = ctx.pool(); | ||
cudaStream_t stream = ctx.stream(); | ||
|
||
sum_f32_cuda(pool, src0_d, dst_d, ne, stream); | ||
} |
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,5 @@ | ||
#include "common.cuh" | ||
|
||
void sum_f32_cuda(ggml_cuda_pool & pool, const float * x, float * dst, const int64_t ne, cudaStream_t stream); | ||
|
||
void ggml_cuda_op_sum(ggml_backend_cuda_context & ctx, ggml_tensor * dst); |
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
Oops, something went wrong.