google-research

Форк
0
/
transpose_launcher.cu.cc 
58 строк · 2.5 Кб
1
// Copyright 2024 The Google Research Authors.
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
//     http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14

15
#if GOOGLE_CUDA
16
#define EIGEN_USE_GPU  // For definition of Eigen::GpuDevice.
17
#include "sparse/ops/cc/common.h"
18
#include "sparse/ops/cc/cusparse_util.h"
19
#include "sparse/ops/cc/transpose_launcher.h"
20

21
namespace sgk {
22

23
void AllocateTransposeWorkspace(
24
    tensorflow::OpKernelContext *context, const Eigen::GpuDevice &d, int m,
25
    int n, int nonzeros, const float *values, const int *row_offsets,
26
    const int *column_indices, float *output_values, int *output_row_offsets,
27
    int *output_column_indices, tensorflow::Tensor *workspace) {
28
  // Calculate the buffer size.
29
  size_t buffer_size = 0;
30
  CUSPARSE_CALL(cusparseCsr2cscEx2_bufferSize(
31
      GetHandleForStream(d.stream()), m, n, nonzeros, values, row_offsets,
32
      column_indices, output_values, output_row_offsets, output_column_indices,
33
      CUDA_R_32F, CUSPARSE_ACTION_NUMERIC, CUSPARSE_INDEX_BASE_ZERO,
34
      CUSPARSE_CSR2CSC_ALG1, &buffer_size));
35

36
  // Allocate the temporary buffer. Round up to the nearest
37
  // float for the size of the buffer.
38
  int64 buffer_size_signed = (buffer_size + sizeof(float) - 1) / sizeof(float);
39
  tensorflow::TensorShape shape = {buffer_size_signed};
40
  OP_REQUIRES_OK(
41
      context, context->allocate_temp(tensorflow::DT_FLOAT, shape, workspace));
42
}
43

44
void LaunchTranspose(const Eigen::GpuDevice &d, int m, int n, int nonzeros,
45
                     const float *values, const int *row_offsets,
46
                     const int *column_indices, float *output_values,
47
                     int *output_row_offsets, int *output_column_indices,
48
                     float *workspace) {
49
  // Launch the kernel.
50
  CUSPARSE_CALL(cusparseCsr2cscEx2(
51
      GetHandleForStream(d.stream()), m, n, nonzeros, values, row_offsets,
52
      column_indices, output_values, output_row_offsets, output_column_indices,
53
      CUDA_R_32F, CUSPARSE_ACTION_NUMERIC, CUSPARSE_INDEX_BASE_ZERO,
54
      CUSPARSE_CSR2CSC_ALG1, workspace));
55
}
56

57
}  // namespace sgk
58
#endif  // GOOGLE_CUDA
59

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.