forked from pytorch/FBGEMM
-
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.
Break up
fbgemm_cuda_utils.cuh
, pt 7 (pytorch#2806)
Summary: Pull Request resolved: pytorch#2806 X-link: facebookresearch/FBGEMM#13 - Break up `fbgemm_cuda_utils.cuh`, pt 7 Reviewed By: jianyuh Differential Revision: D59357908 fbshipit-source-id: 01e3c1a52c562f7b689f97a83aace77b20c34573
- Loading branch information
1 parent
eb73980
commit 24e6f96
Showing
10 changed files
with
356 additions
and
293 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <ATen/ATen.h> | ||
|
||
#include "fbgemm_gpu/utils/vec4.cuh" | ||
|
||
namespace fbgemm_gpu { | ||
|
||
//////////////////////////////////////////////////////////////////////////////// | ||
// Find Quantization Parameters | ||
//////////////////////////////////////////////////////////////////////////////// | ||
|
||
template <typename scalar_t> | ||
__device__ float2 thrust_find_qparams(scalar_t* input_row, int D) { | ||
float2 qparams; | ||
|
||
scalar_t scalar_minimum = *(input_row++); | ||
scalar_t scalar_maximum = scalar_minimum; | ||
|
||
while (--D > 0) { | ||
scalar_t next = *(input_row++); | ||
scalar_minimum = (scalar_minimum <= next) ? scalar_minimum : next; | ||
scalar_maximum = (scalar_maximum >= next) ? scalar_maximum : next; | ||
} | ||
float minimum_element = scalar_minimum; | ||
float maximum_element = scalar_maximum; | ||
|
||
float range = maximum_element - minimum_element; | ||
qparams.x = range / 255.0f; | ||
qparams.y = minimum_element; | ||
return qparams; | ||
} | ||
|
||
template <typename scalar_t> | ||
__device__ float2 | ||
thrust_find_qparams(fbgemm_gpu::Vec4T<scalar_t>* input_row, int D) { | ||
// TODO: replace uses in backward kernels with warp find qparams | ||
float2 qparams; | ||
float min_val = input_row[0].vmin(); | ||
float max_val = input_row[0].vmax(); | ||
for (int i = 0; i < D / 4; ++i) { | ||
min_val = min(min_val, input_row[i].vmin()); | ||
max_val = max(max_val, input_row[i].vmax()); | ||
} | ||
qparams.x = (max_val - min_val) / 255.0f; | ||
qparams.y = min_val; | ||
return qparams; | ||
} | ||
|
||
} // namespace fbgemm_gpu |
Oops, something went wrong.