Skip to content

Commit

Permalink
初始化
Browse files Browse the repository at this point in the history
  • Loading branch information
朱林 committed Aug 20, 2019
1 parent 19b8253 commit 07eef61
Show file tree
Hide file tree
Showing 313 changed files with 1,326 additions and 449 deletions.
58 changes: 58 additions & 0 deletions FaceDetect/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# Built application files
*.apk
*.ap_

# Files for the ART/Dalvik VM
*.dex

# Java class files
*.class

# Generated files
bin/
gen/
out/

# Gradle files
.gradle/
build/

# Local configuration file (sdk path, etc)
local.properties

# Proguard folder generated by Eclipse
proguard/

# Log Files
*.log

# Android Studio Navigation editor temp files
.navigation/

# Android Studio captures folder
captures/

# IntelliJ
*.iml
.idea/workspace.xml
.idea/tasks.xml
.idea/gradle.xml
.idea/dictionaries
.idea/libraries

# Keystore files
# Uncomment the following line if you do not want to check your keystore files in.
#*.jks

# External native build folder generated in Android Studio 2.2 and later
.externalNativeBuild

# Google Services (e.g. APIs or Firebase)
google-services.json

# Freeline
freeline.py
freeline/
freeline_project_description.json
app/official/
.idea/
33 changes: 33 additions & 0 deletions FaceDetect/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
cmake_minimum_required(VERSION 3.4.1)

set(lib_DIR ${CMAKE_SOURCE_DIR}/libs)
include_directories(${CMAKE_SOURCE_DIR}/includes)

set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fopenmp")
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fopenmp")
set (CMAKE_LINKER_FLAGS "${CMAKE_LINKER_FLAGS} -fopenmp")

set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O2 -fvisibility=hidden -fomit-frame-pointer -fstrict-aliasing -ffunction-sections -fdata-sections -ffast-math")
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O2 -fvisibility=hidden -fvisibility-inlines-hidden -fomit-frame-pointer -fstrict-aliasing -ffunction-sections -fdata-sections -ffast-math")
set (CMAKE_LINKER_FLAGS "${CMAKE_LINKER_FLAGS} -Wl,--gc-sections")

add_library(libncnn STATIC IMPORTED)
set_target_properties(libncnn PROPERTIES IMPORTED_LOCATION ${lib_DIR}/${ANDROID_ABI}/libncnn.a)

add_library(libopencv_java3 SHARED IMPORTED)
set_target_properties(libopencv_java3 PROPERTIES IMPORTED_LOCATION ${lib_DIR}/${ANDROID_ABI}/libopencv_java3.so)

file(GLOB_RECURSE CPP_SRCS src/main/cpp/*.h
src/main/cpp/*.cpp
src/main/cpp/mtcnn.cpp
src/main/cpp/mtcnn_gpu.cpp
src/main/cpp/mtcnn_gpu_jni.cpp
src/main/cpp/mtcnn_jni.cpp)

add_library(faceDetect SHARED ${CPP_SRCS} )

find_library(log-lib log)
find_library(jnigraphics-lib jnigraphics)
find_library(vulkan-lib vulkan)

target_link_libraries(faceDetect libncnn libopencv_java3 z ${log-lib} ${jnigraphics-lib} ${vulkan-lib})
52 changes: 52 additions & 0 deletions FaceDetect/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
apply plugin: 'com.android.library'

android {
compileSdkVersion 28

defaultConfig {
minSdkVersion 21
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
externalNativeBuild {
cmake {
arguments "-DANDROID_STL=c++_shared"
arguments "-DANDROID_TOOLCHAIN=clang", "-DANDROID_ARM_NEON=TRUE", "-DANDROID_PLATFORM=android-24"
abiFilters 'armeabi-v7a'
}
}
ndk {
abiFilters 'armeabi-v7a'
stl "gnustl_static"
}
}
compileOptions {
targetCompatibility JavaVersion.VERSION_1_8
sourceCompatibility JavaVersion.VERSION_1_8
}

buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}

externalNativeBuild {
cmake {
path "CMakeLists.txt"
}
}

sourceSets {
main {
jniLibs.srcDirs = ['libs']
}
}

}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,20 +56,39 @@ static inline size_t alignSize(size_t sz, int n)

static inline void* fastMalloc(size_t size)
{
#if _MSC_VER
return _aligned_malloc(size, MALLOC_ALIGN);
#elif _POSIX_C_SOURCE >= 200112L || (__ANDROID__ && __ANDROID_API__ >= 17)
void* ptr = 0;
if (posix_memalign(&ptr, MALLOC_ALIGN, size))
ptr = 0;
return ptr;
#elif __ANDROID__ && __ANDROID_API__ < 17
return memalign(MALLOC_ALIGN, size);
#else
unsigned char* udata = (unsigned char*)malloc(size + sizeof(void*) + MALLOC_ALIGN);
if (!udata)
return 0;
unsigned char** adata = alignPtr((unsigned char**)udata + 1, MALLOC_ALIGN);
adata[-1] = udata;
return adata;
#endif
}

static inline void fastFree(void* ptr)
{
if (ptr)
{
#if _MSC_VER
_aligned_free(ptr);
#elif _POSIX_C_SOURCE >= 200112L || (__ANDROID__ && __ANDROID_API__ >= 17)
free(ptr);
#elif __ANDROID__ && __ANDROID_API__ < 17
free(ptr);
#else
unsigned char* udata = ((unsigned char**)ptr)[-1];
free(udata);
#endif
}
}

Expand Down Expand Up @@ -100,40 +119,6 @@ static inline void fastFree(void* ptr)
static inline int NCNN_XADD(int* addr, int delta) { int tmp = *addr; *addr += delta; return tmp; }
#endif

#ifdef _WIN32
class Mutex
{
public:
Mutex() { InitializeSRWLock(&srwlock); }
~Mutex() {}
void lock() { AcquireSRWLockExclusive(&srwlock); }
void unlock() { ReleaseSRWLockExclusive(&srwlock); }
private:
// NOTE SRWLock is available from windows vista
SRWLOCK srwlock;
};
#else // _WIN32
class Mutex
{
public:
Mutex() { pthread_mutex_init(&mutex, 0); }
~Mutex() { pthread_mutex_destroy(&mutex); }
void lock() { pthread_mutex_lock(&mutex); }
void unlock() { pthread_mutex_unlock(&mutex); }
private:
pthread_mutex_t mutex;
};
#endif // _WIN32

class MutexLockGuard
{
public:
MutexLockGuard(Mutex& _mutex) : mutex(_mutex) { mutex.lock(); }
~MutexLockGuard() { mutex.unlock(); }
private:
Mutex& mutex;
};

class Allocator
{
public:
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ namespace ncnn {
class Command
{
public:
Command(const VulkanDevice* vkdev, uint32_t queue_index);
~Command();
Command(const VulkanDevice* vkdev, uint32_t queue_family_index);
virtual ~Command();

protected:
int create_command_pool();
Expand All @@ -39,14 +39,11 @@ class Command
// record issue
int begin_command_buffer();
int end_command_buffer();
int queue_submit();
int wait_fence();
int queue_submit_and_wait_fence();

protected:
const VulkanDevice* vkdev;
uint32_t queue_index;

VkQueue queue;
uint32_t queue_family_index;

VkCommandPool command_pool;
VkCommandBuffer command_buffer;
Expand All @@ -72,12 +69,18 @@ class VkCompute : public Command

void record_pipeline(const Pipeline* pipeline, const std::vector<VkMat>& bindings, const std::vector<vk_constant_type>& constants, const VkMat& m);

int submit();
void record_write_timestamp(uint32_t query);

int wait();
int submit_and_wait();

int reset();

#if NCNN_BENCHMARK
int create_query_pool(uint32_t query_count);

int get_query_pool_results(uint32_t first_query, uint32_t query_count, std::vector<uint64_t>& results);
#endif // NCNN_BENCHMARK

protected:
// record pipeline things
void record_bind_pipeline(VkPipeline pipeline);
Expand All @@ -95,6 +98,10 @@ class VkCompute : public Command
void record_prepare_transfer_barrier(const VkMat& m);
void record_prepare_compute_barrier(const VkMat& m);

#if NCNN_BENCHMARK
void reset_query_pool();
#endif // NCNN_BENCHMARK

protected:
// recording issue
void copy_buffer(VkBuffer src, size_t src_offset, VkBuffer dst, size_t dst_offset, size_t size);
Expand All @@ -108,6 +115,9 @@ class VkCompute : public Command
void compute_transfer_barrier(VkBuffer buffer, size_t offset, size_t size);
void compute_compute_barrier(VkBuffer buffer, size_t offset, size_t size);
void transfer_transfer_barrier(VkBuffer buffer, size_t offset, size_t size);
#if NCNN_BENCHMARK
void write_timestamp(uint32_t query);
#endif // NCNN_BENCHMARK

protected:
// delayed record
Expand All @@ -126,6 +136,7 @@ class VkCompute : public Command
// 7=compute-transfer barrier
// 8=compute-compute barrier
// 9=transfer-transfer barrier
// 10=write timestamp
int type;

union
Expand All @@ -140,12 +151,20 @@ class VkCompute : public Command
struct { VkBuffer buffer; size_t offset; size_t size; } compute_transfer_barrier;
struct { VkBuffer buffer; size_t offset; size_t size; } compute_compute_barrier;
struct { VkBuffer buffer; size_t offset; size_t size; } transfer_transfer_barrier;
#if NCNN_BENCHMARK
struct { uint32_t query; } write_timestamp;
#endif // NCNN_BENCHMARK
};

std::vector<VkBufferCopy> regions;
std::vector<vk_constant_type> constants;
};
std::vector<record_type> delayed_records;

#if NCNN_BENCHMARK
uint32_t query_count;
VkQueryPool query_pool;
#endif // NCNN_BENCHMARK
};

class VkTransfer : public Command
Expand All @@ -154,13 +173,9 @@ class VkTransfer : public Command
VkTransfer(const VulkanDevice* vkdev);
~VkTransfer();

void record_upload(const Mat& src, VkMat& dst);

void record_download(const VkMat& src, Mat& dst);
void record_upload(const Mat& src, VkMat& dst, const Option& opt);

int submit();

int wait();
int submit_and_wait();

public:
VkAllocator* weight_vkallocator;
Expand All @@ -178,9 +193,6 @@ class VkTransfer : public Command
// delayed record
struct record_type
{
// 0=upload
// 1=download
int type;
size_t size;
Mat mat;
VkMat vkmat;
Expand Down
File renamed without changes.
Loading

0 comments on commit 07eef61

Please sign in to comment.