Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compile vulkan in ncnn python setup #4

Merged
merged 3 commits into from
Aug 24, 2023
Merged
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
13 changes: 7 additions & 6 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,18 @@ def find_version():

# Parse parameters from environment
NCNN_VULKAN = False
NCNN_CI_VULKAN = False
for i, arg in enumerate(sys.argv):
if arg == "-g" or arg == "--gpu":
NCNN_VULKAN = True

# Parse environment variables
NCNN_VULKAN_FLAG = os.environ.get("NCNN_VULKAN", "FALSE")
USE_CI_VULKAN_FLAG = os.environ.get("USE_CI_VULKAN", "FALSE")
NCNN_CI_VULKAN_FLAG = os.environ.get("NCNN_CI_VULKAN", "FALSE")
if (NCNN_VULKAN_FLAG == "TRUE"):
NCNN_VULKAN = True
if (USE_CI_VULKAN_FLAG == "TRUE"):
USE_CI_VULKAN = True
if (NCNN_CI_VULKAN_FLAG == "TRUE"):
NCNN_CI_VULKAN = True

# Convert distutils Windows platform specifiers to CMake -A arguments
PLAT_TO_CMAKE = {
Expand Down Expand Up @@ -87,10 +88,10 @@ def build_extension(self, ext):
cmake_args.append("-DNCNN_VULKAN=ON")
else:
cmake_args.append("-DNCNN_VULKAN=OFF")
if USE_CI_VULKAN:
cmake_args.append("-DUSE_CI_VULKAN=ON")
if NCNN_CI_VULKAN:
cmake_args.append("-DNCNN_CI_VULKAN=ON")
else:
cmake_args.append("-DUSE_CI_VULKAN=OFF")
cmake_args.append("-DNCNN_CI_VULKAN=OFF")
build_args = []

if self.compiler.compiler_type == "msvc":
Expand Down
8 changes: 8 additions & 0 deletions src/layer/arm/unaryop_arm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -402,10 +402,14 @@ struct unary_op_round
#endif
return y;
#else
#ifdef FE_TONEAREST
int old_rm = fegetround();
fesetround(FE_TONEAREST);
#endif
float y = nearbyintf(x);
#ifdef FE_TONEAREST
fesetround(old_rm);
#endif
return y;
#endif
}
Expand All @@ -431,13 +435,17 @@ struct unary_op_round
#else
float tmp[4];
vst1q_f32(tmp, x);
#ifdef FE_TONEAREST
int old_rm = fegetround();
fesetround(FE_TONEAREST);
#endif
tmp[0] = nearbyintf(tmp[0]);
tmp[1] = nearbyintf(tmp[1]);
tmp[2] = nearbyintf(tmp[2]);
tmp[3] = nearbyintf(tmp[3]);
#ifdef FE_TONEAREST
fesetround(old_rm);
#endif
float32x4_t y = vld1q_f32(tmp);
return y;
#endif
Expand Down
4 changes: 4 additions & 0 deletions src/layer/arm/unaryop_arm_asimdhp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -471,10 +471,14 @@ struct unary_op_round_fp16s
:);
return y;
#else
#ifdef FE_TONEAREST
int old_rm = fegetround();
fesetround(FE_TONEAREST);
#endif
__fp16 y = (__fp16)nearbyintf(x);
#ifdef FE_TONEAREST
fesetround(old_rm);
#endif
return y;
#endif
}
Expand Down
4 changes: 4 additions & 0 deletions src/layer/loongarch/unaryop_loongarch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -383,10 +383,14 @@ struct unary_op_round
:);
return y;
#else
#ifdef FE_TONEAREST
int old_rm = fegetround();
fesetround(FE_TONEAREST);
#endif
float y = nearbyintf(x);
#ifdef FE_TONEAREST
fesetround(old_rm);
#endif
return y;
#endif
}
Expand Down
4 changes: 4 additions & 0 deletions src/layer/mips/unaryop_mips.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -397,10 +397,14 @@ struct unary_op_round
:);
return y;
#else
#ifdef FE_TONEAREST
int old_rm = fegetround();
fesetround(FE_TONEAREST);
#endif
float y = nearbyintf(x);
#ifdef FE_TONEAREST
fesetround(old_rm);
#endif
return y;
#endif
}
Expand Down
4 changes: 4 additions & 0 deletions src/layer/unaryop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,10 +198,14 @@ struct unary_op_round
float operator()(const float& x) const
{
// round to nearest even
#ifdef FE_TONEAREST
int old_rm = fegetround();
fesetround(FE_TONEAREST);
#endif
float y = nearbyintf(x);
#ifdef FE_TONEAREST
fesetround(old_rm);
#endif
return y;
}
};
Expand Down
2 changes: 1 addition & 1 deletion src/layer/vulkan/convolution_vulkan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ int Convolution_vulkan::create_pipeline(const Option& _opt)
specializations[1].i = activation_type;
specializations[2].f = activation_params.w >= 1 ? activation_params[0] : 0.f;
specializations[3].f = activation_params.w == 2 ? activation_params[1] : 0.f;
specializations[4 + 0].i = shape_winograd_gemm_packed.c;
specializations[4 + 0].i = shape_winograd_gemm_packed.h;
specializations[4 + 1].i = shape_winograd_gemm_packed.cstep;
specializations[4 + 2].i = block_x;
specializations[4 + 3].i = block_y;
Expand Down
4 changes: 4 additions & 0 deletions src/layer/x86/unaryop_x86.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -578,10 +578,14 @@ struct unary_op_round
{
// round to nearest even
// return (x + 12582912.f) - 12582912.f;
#ifdef FE_TONEAREST
int old_rm = fegetround();
fesetround(FE_TONEAREST);
#endif
float y = nearbyintf(x);
#ifdef FE_TONEAREST
fesetround(old_rm);
#endif
return y;
}
#if __SSE2__
Expand Down