Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions csrc/mlp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@ std::vector<at::Tensor> mlp_forward(int use_bias, int activation, std::vector<at
auto reserved_size = get_mlp_reserved_space(batch_size, num_layers, output_features.data());

// create output/workspace tensor
auto out = at::empty({batch_size, output_features.back()}, inputs[0].type());
auto reserved_space = at::empty({static_cast<long>(reserved_size)}, inputs[0].type());
auto out = at::empty({batch_size, output_features.back()}, inputs[0].options());
auto reserved_space = at::empty({static_cast<long>(reserved_size)}, inputs[0].options());
// allocate fixed 4MB workspace for cublaslt for now, and this gets at least 4 MB
auto lt_workspace = at::empty({1 << 22}, inputs[0].type());
auto lt_workspace = at::empty({1 << 22}, inputs[0].options());

AT_DISPATCH_FLOATING_TYPES_AND_HALF(inputs[0].scalar_type(), "mlp_forward", [&] {
std::vector<scalar_t*> w_ptr;
Expand Down Expand Up @@ -118,7 +118,7 @@ std::vector<at::Tensor> mlp_backward(
// create outputs, length of inputs
std::vector<at::Tensor> outputs;
for (int i = 0; i < inputs.size(); i++) {
outputs.push_back(at::empty(inputs[i].sizes(), inputs[i].type())); // clone for testing now
outputs.push_back(at::empty(inputs[i].sizes(), inputs[i].options())); // clone for testing now
}

AT_DISPATCH_FLOATING_TYPES_AND_HALF(inputs[0].scalar_type(), "mlp_backward", [&] {
Expand All @@ -135,7 +135,7 @@ std::vector<at::Tensor> mlp_backward(
get_mlp_bp_workspace_in_bytes<scalar_t>(batch_size, num_layers, output_features.data());

// auto work_space = at::empty({work_size*4}, at::kByte);
auto work_space = at::empty({static_cast<long>(work_size / sizeof(scalar_t))}, inputs[0].type());
auto work_space = at::empty({static_cast<long>(work_size / sizeof(scalar_t))}, inputs[0].options());

auto result = mlp_bp<scalar_t>(
inputs[0].data_ptr<scalar_t>(),
Expand Down
15 changes: 8 additions & 7 deletions csrc/mlp_cuda.cu
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <ATen/ATen.h>
#include <ATen/cuda/CUDAContext.h>
#include <assert.h>
#include <cstdint>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
Expand Down Expand Up @@ -434,7 +435,7 @@ CLEANUP:
// Bias ADD. Assume input X is [features x batch size], column major.
// Bias is one 'features' long vector, with implicit broadcast.
template <typename T>
__global__ void biasAdd_fprop(T *X, T *b, uint batch_size, uint features) {
__global__ void biasAdd_fprop(T *X, T *b, uint32_t batch_size, uint32_t features) {
T r_x[ILP];
T r_b[ILP];
if(is_aligned(X) && is_aligned(b) && features % ILP ==0) {
Expand Down Expand Up @@ -481,7 +482,7 @@ __global__ void biasAdd_fprop(T *X, T *b, uint batch_size, uint features) {
// Bias ADD + ReLU. Assume input X is [features x batch size], column major.
// Activation support fuesed ReLU. Safe to call in-place.
template <typename T>
__global__ void biasAddRelu_fprop(T *X, T *b, uint batch_size, uint features) {
__global__ void biasAddRelu_fprop(T *X, T *b, uint32_t batch_size, uint32_t features) {
T r_x[ILP];
T r_b[ILP];
if(is_aligned(X) && is_aligned(b) && features % ILP ==0) {
Expand Down Expand Up @@ -528,7 +529,7 @@ __global__ void biasAddRelu_fprop(T *X, T *b, uint batch_size, uint features) {
// ReLU. Assume input X is [features x batch size], column major.
// Safe to call in-place.
template <typename T>
__global__ void Relu_fprop(T *X, uint batch_size, uint features) {
__global__ void Relu_fprop(T *X, uint32_t batch_size, uint32_t features) {
T r_x[ILP];
if(is_aligned(X) && features % ILP ==0) {
int tid = blockIdx.x * blockDim.x + threadIdx.x;
Expand Down Expand Up @@ -568,7 +569,7 @@ __global__ void Relu_fprop(T *X, uint batch_size, uint features) {
// Sigmoid. Assume input X is [features x batch size], column major.
// Safe to call in-place.
template <typename T>
__global__ void Sigmoid_fprop(T *X, uint batch_size, uint features) {
__global__ void Sigmoid_fprop(T *X, uint32_t batch_size, uint32_t features) {
T r_x[ILP];
if(is_aligned(X) && features % ILP ==0) {
int tid = blockIdx.x * blockDim.x + threadIdx.x;
Expand Down Expand Up @@ -608,7 +609,7 @@ __global__ void Sigmoid_fprop(T *X, uint batch_size, uint features) {
// ReLU. Assume input X is [features x batch size], column major.
// Safe to call in-place.
template <typename T>
__global__ void Relu_bprop(T *dY, T *Y, uint batch_size, uint features, T *dX) {
__global__ void Relu_bprop(T *dY, T *Y, uint32_t batch_size, uint32_t features, T *dX) {
T r_dy[ILP];
T r_y[ILP];
if(is_aligned(dY) &&
Expand Down Expand Up @@ -656,7 +657,7 @@ __global__ void Relu_bprop(T *dY, T *Y, uint batch_size, uint features, T *dX) {
// Sigmoid. Assume input X is [features x batch size], column major.
// Safe to call in-place.
template <typename T>
__global__ void Sigmoid_bprop(T *dY, T *Y, uint batch_size, uint features, T *dX) {
__global__ void Sigmoid_bprop(T *dY, T *Y, uint32_t batch_size, uint32_t features, T *dX) {
T r_dy[ILP];
T r_y[ILP];
if(is_aligned(dY) &&
Expand Down Expand Up @@ -1324,7 +1325,7 @@ int mlp_fp(
return 1;
}

const uint &input_size = ofeat;
const uint32_t &input_size = ofeat;
int num_blocks = 0;
int num_SMs = at::cuda::getCurrentDeviceProperties()->multiProcessorCount;
// Call biasReLU
Expand Down
12 changes: 6 additions & 6 deletions csrc/multi_tensor_axpby_kernel.cu
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,11 @@ struct AxpbyFunctor
{
r_out[ii] = a*static_cast<float>(r_x[ii]) + b*static_cast<float>(r_y[ii]);
if(arg_to_check == -1)
finite = finite && (isfinite(r_x[ii]) && isfinite(r_y[ii]));
finite = finite && (!isnan(static_cast<float>(r_x[ii])) && !isinf(static_cast<float>(r_x[ii])) && !isnan(static_cast<float>(r_y[ii])) && !isinf(static_cast<float>(r_y[ii])));
if(arg_to_check == 0)
finite = finite && isfinite(r_x[ii]);
finite = finite && !isnan(static_cast<float>(r_x[ii])) && !isinf(static_cast<float>(r_x[ii]));
if(arg_to_check == 1)
finite = finite && isfinite(r_y[ii]);
finite = finite && !isnan(static_cast<float>(r_y[ii])) && !isinf(static_cast<float>(r_y[ii]));
}
// store
load_store(out, r_out, i_start , 0);
Expand Down Expand Up @@ -104,11 +104,11 @@ struct AxpbyFunctor
{
r_out[ii] = a*static_cast<float>(r_x[ii]) + b*static_cast<float>(r_y[ii]);
if(arg_to_check == -1)
finite = finite && (isfinite(r_x[ii]) && isfinite(r_y[ii]));
finite = finite && (!isnan(static_cast<float>(r_x[ii])) && !isinf(static_cast<float>(r_x[ii])) && !isnan(static_cast<float>(r_y[ii])) && !isinf(static_cast<float>(r_y[ii])));
if(arg_to_check == 0)
finite = finite && isfinite(r_x[ii]);
finite = finite && !isnan(static_cast<float>(r_x[ii])) && !isinf(static_cast<float>(r_x[ii]));
if(arg_to_check == 1)
finite = finite && isfinite(r_y[ii]);
finite = finite && !isnan(static_cast<float>(r_y[ii])) && !isinf(static_cast<float>(r_y[ii]));
}
// see note in multi_tensor_scale_kernel.cu
#pragma unroll
Expand Down
4 changes: 2 additions & 2 deletions csrc/multi_tensor_scale_kernel.cu
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ struct ScaleFunctor
for(int ii = 0; ii < ILP; ii++)
{
r_out[ii] = static_cast<float>(r_in[ii]) * scale;
finite = finite && isfinite(r_in[ii]);
finite = finite && !isnan(static_cast<float>(r_in[ii])) && !isinf(static_cast<float>(r_in[ii]));
}
// store
load_store(out, r_out, i_start, 0);
Expand Down Expand Up @@ -94,7 +94,7 @@ struct ScaleFunctor
for(int ii = 0; ii < ILP; ii++)
{
r_out[ii] = static_cast<float>(r_in[ii]) * scale;
finite = finite && isfinite(r_in[ii]);
finite = finite && !isnan(static_cast<float>(r_in[ii])) && !isinf(static_cast<float>(r_in[ii]));
}
#pragma unroll
for(int ii = 0; ii < ILP; ii++)
Expand Down
Loading