Commit 5f37917f authored by Shucai Xiao's avatar Shucai Xiao
Browse files

clang format

parent f50bcff2
......@@ -11,27 +11,28 @@ namespace device {
__global__ void add_kernel(__half* a, __half* b, __half* r, int n)
{
int tid = blockIdx.x * blockDim.x + threadIdx.x;
if (tid < n)
if(tid < n)
{
r[tid] = a[tid] + b[tid%768];
r[tid] = a[tid] + b[tid % 768];
}
}
void add(hipStream_t stream, const argument& result, const argument& arg1, const argument& arg2)
{
auto s2 = arg2.get_shape();
if (s2.element_space() == 768 and s2.type() == shape::half_type)
if(s2.element_space() == 768 and s2.type() == shape::half_type)
{
auto elem_num = s2.elements();
auto elem_num = s2.elements();
int block_size = 1024;
int block_num = (elem_num + block_size - 1) / block_size;
int block_num = (elem_num + block_size - 1) / block_size;
add_kernel<<<block_num, block_size>>>(reinterpret_cast<__half*>(arg1.data()),
reinterpret_cast<__half*>(arg2.data()),
reinterpret_cast<__half*>(result.data()), elem_num);
reinterpret_cast<__half*>(arg2.data()),
reinterpret_cast<__half*>(result.data()),
elem_num);
}
else
{
nary(stream, result, arg1, arg2)([](auto x, auto y) __device__ { return x + y; });
nary(stream, result, arg1, arg2)([](auto x, auto y) __device__ { return x + y; });
}
}
......
......@@ -14,7 +14,7 @@ void contiguous_nonstandard(hipStream_t stream, const argument& result, const ar
visit_all(result, arg)([&](auto output_v, auto input_v) {
hip_visit_views(output_v, input_v, s)([&](auto output, auto input, auto standard_shape) {
gs_launch(stream, s.elements())([=](auto i) __device__ {
auto idx = standard_shape.multi(i);
auto idx = standard_shape.multi(i);
output[idx] = input[idx];
});
// mi_gs_launch(stream,
......@@ -34,8 +34,8 @@ void contiguous_packed(hipStream_t stream, const argument& result, const argumen
// auto* output = device_cast(output_v.data());
// const __half2* input2 = reinterpret_cast<__half2*>(input_v.data());
// __half2* output2 = reinterpret_cast<__half2*>(output_v.data());
// gs_launch(stream, nelements / 2)([=](auto i) __device__ {
// output2[i] = input2[i];
// gs_launch(stream, nelements / 2)([=](auto i) __device__ {
// output2[i] = input2[i];
// if (i == 0 and (nelements % 2) == 1)
// {
// output[nelements - 1] = input[nelements - 1];
......@@ -45,11 +45,11 @@ void contiguous_packed(hipStream_t stream, const argument& result, const argumen
// }
// else
// {
visit_all(result, arg)([&](auto output_v, auto input_v) {
const auto* input = device_cast(input_v.data());
auto* output = device_cast(output_v.data());
gs_launch(stream, nelements)([=](auto i) __device__ { output[i] = input[i]; });
});
visit_all(result, arg)([&](auto output_v, auto input_v) {
const auto* input = device_cast(input_v.data());
auto* output = device_cast(output_v.data());
gs_launch(stream, nelements)([=](auto i) __device__ { output[i] = input[i]; });
});
// }
}
......
......@@ -57,8 +57,8 @@ inline auto mi_nglobal(const hip_shape<N>& s, index_int nlocal)
{
assert(s.standard);
assert(s.elements() > 0);
index_int n = s.elements();
index_int groups = (n + nlocal - 1) / nlocal;
index_int n = s.elements();
index_int groups = (n + nlocal - 1) / nlocal;
// change the max group num to 1 Million
index_int nglobal = std::min<index_int>((1 << 20), groups) * nlocal;
......
......@@ -11,28 +11,28 @@ namespace device {
__global__ void mul_kernel(__half* a, __half* b, __half* r, int n)
{
int tid = blockIdx.x * blockDim.x + threadIdx.x;
if (tid < n)
if(tid < n)
{
r[tid] = a[tid] * b[tid%768];
r[tid] = a[tid] * b[tid % 768];
}
}
void mul(hipStream_t stream, const argument& result, const argument& arg1, const argument& arg2)
{
auto s2 = arg2.get_shape();
if (s2.element_space() == 768 and s2.type() == shape::half_type)
if(s2.element_space() == 768 and s2.type() == shape::half_type)
{
auto elem_num = s2.elements();
auto elem_num = s2.elements();
int block_size = 1024;
int block_num = (elem_num + block_size - 1) / block_size;
int block_num = (elem_num + block_size - 1) / block_size;
mul_kernel<<<block_num, block_size>>>(reinterpret_cast<__half*>(arg1.data()),
reinterpret_cast<__half*>(arg2.data()),
reinterpret_cast<__half*>(result.data()), elem_num);
reinterpret_cast<__half*>(arg2.data()),
reinterpret_cast<__half*>(result.data()),
elem_num);
}
else
{
nary(stream, result, arg1, arg2)([](auto x, auto y) __device__ { return x * y; });
nary(stream, result, arg1, arg2)([](auto x, auto y) __device__ { return x * y; });
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment