├── .classpath
├── .gitattributes
├── .gitignore
├── .project
├── Documentation
├── About.txt
├── Detailed Report with User Manual.pdf
├── Technical Document.pdf
└── User Manual.pdf
├── LICENSE
├── README.md
├── resources
├── appIcon.ico
├── icon16.png
└── logo.png
├── src
├── codeBeautifier
│ ├── BlankLineRemover.java
│ ├── CmdExecutor.java
│ ├── CodeBeautifier.java
│ ├── CommentRemover.java
│ ├── LineRemover.java
│ └── package-info.java
├── controlFlowGraphBuilder
│ ├── CFGBuilder.java
│ ├── Node.java
│ └── package-info.java
├── database
│ ├── DatabaseLoader.java
│ └── package-info.java
├── io
│ ├── CustomFileReader.java
│ ├── CustomFileWriter.java
│ ├── InputFileCopyMachine.java
│ └── package-info.java
├── main
│ ├── MainController.java
│ ├── MainView.fxml
│ ├── Start.java
│ ├── application.css
│ └── package-info.java
├── parser
│ ├── CParser.java
│ ├── ComponentSeparator.java
│ ├── MethodParser.java
│ ├── components
│ │ ├── Component.java
│ │ ├── Directive.java
│ │ ├── Method.java
│ │ ├── ObjectFile.java
│ │ ├── UserDefinedData.java
│ │ ├── Variable.java
│ │ └── package-info.java
│ └── package-info.java
├── result
│ ├── FileResult.java
│ └── package-info.java
└── symbolicSolver
│ ├── SMTSolver.java
│ ├── SymbolicSolver.java
│ └── package-info.java
├── test
├── 1.c
├── Mini Project in C Bank Management System
│ ├── Readme.docx
│ └── bank management system.c
├── Mini Project in C Library Management System
│ ├── Readme.docx
│ └── library management system.c
├── custom.c
├── darknet
│ └── src
│ │ ├── activation_kernels.cu
│ │ ├── activation_layer.c
│ │ ├── activation_layer.h
│ │ ├── activations.c
│ │ ├── activations.h
│ │ ├── avgpool_layer.c
│ │ ├── avgpool_layer.h
│ │ ├── avgpool_layer_kernels.cu
│ │ ├── batchnorm_layer.c
│ │ ├── batchnorm_layer.h
│ │ ├── blas.c
│ │ ├── blas.h
│ │ ├── blas_kernels.cu
│ │ ├── box.c
│ │ ├── box.h
│ │ ├── classifier.h
│ │ ├── col2im.c
│ │ ├── col2im.h
│ │ ├── col2im_kernels.cu
│ │ ├── compare.c
│ │ ├── connected_layer.c
│ │ ├── connected_layer.h
│ │ ├── convolutional_kernels.cu
│ │ ├── convolutional_layer.c
│ │ ├── convolutional_layer.h
│ │ ├── cost_layer.c
│ │ ├── cost_layer.h
│ │ ├── crnn_layer.c
│ │ ├── crnn_layer.h
│ │ ├── crop_layer.c
│ │ ├── crop_layer.h
│ │ ├── crop_layer_kernels.cu
│ │ ├── cuda.c
│ │ ├── cuda.h
│ │ ├── data.c
│ │ ├── data.h
│ │ ├── deconvolutional_kernels.cu
│ │ ├── deconvolutional_layer.c
│ │ ├── deconvolutional_layer.h
│ │ ├── demo.c
│ │ ├── demo.h
│ │ ├── detection_layer.c
│ │ ├── detection_layer.h
│ │ ├── dropout_layer.c
│ │ ├── dropout_layer.h
│ │ ├── dropout_layer_kernels.cu
│ │ ├── gemm.c
│ │ ├── gemm.h
│ │ ├── gru_layer.c
│ │ ├── gru_layer.h
│ │ ├── im2col.c
│ │ ├── im2col.h
│ │ ├── im2col_kernels.cu
│ │ ├── image.c
│ │ ├── image.h
│ │ ├── image_opencv.cpp
│ │ ├── iseg_layer.c
│ │ ├── iseg_layer.h
│ │ ├── l2norm_layer.c
│ │ ├── l2norm_layer.h
│ │ ├── layer.c
│ │ ├── layer.h
│ │ ├── list.c
│ │ ├── list.h
│ │ ├── local_layer.c
│ │ ├── local_layer.h
│ │ ├── logistic_layer.c
│ │ ├── logistic_layer.h
│ │ ├── lstm_layer.c
│ │ ├── lstm_layer.h
│ │ ├── matrix.c
│ │ ├── matrix.h
│ │ ├── maxpool_layer.c
│ │ ├── maxpool_layer.h
│ │ ├── maxpool_layer_kernels.cu
│ │ ├── network.c
│ │ ├── network.h
│ │ ├── normalization_layer.c
│ │ ├── normalization_layer.h
│ │ ├── option_list.c
│ │ ├── option_list.h
│ │ ├── parser.c
│ │ ├── parser.h
│ │ ├── region_layer.c
│ │ ├── region_layer.h
│ │ ├── reorg_layer.c
│ │ ├── reorg_layer.h
│ │ ├── rnn_layer.c
│ │ ├── rnn_layer.h
│ │ ├── route_layer.c
│ │ ├── route_layer.h
│ │ ├── shortcut_layer.c
│ │ ├── shortcut_layer.h
│ │ ├── softmax_layer.c
│ │ ├── softmax_layer.h
│ │ ├── stb_image.h
│ │ ├── stb_image_write.h
│ │ ├── tree.c
│ │ ├── tree.h
│ │ ├── upsample_layer.c
│ │ ├── upsample_layer.h
│ │ ├── utils.c
│ │ ├── utils.h
│ │ ├── yolo_layer.c
│ │ └── yolo_layer.h
└── test
│ └── me.c
└── z3
├── LICENSE.txt
├── bin
├── Microsoft.Z3.dll
├── Microsoft.Z3.xml
├── com.microsoft.z3.jar
├── libz3.dll
├── libz3.lib
├── libz3java.dll
├── libz3java.lib
├── python
│ ├── example.py
│ └── z3
│ │ ├── __init__.py
│ │ ├── __init__.pyc
│ │ ├── z3.py
│ │ ├── z3.pyc
│ │ ├── z3consts.py
│ │ ├── z3consts.pyc
│ │ ├── z3core.py
│ │ ├── z3core.pyc
│ │ ├── z3num.py
│ │ ├── z3num.pyc
│ │ ├── z3poly.py
│ │ ├── z3poly.pyc
│ │ ├── z3printer.py
│ │ ├── z3printer.pyc
│ │ ├── z3rcf.py
│ │ ├── z3rcf.pyc
│ │ ├── z3types.py
│ │ ├── z3types.pyc
│ │ ├── z3util.py
│ │ └── z3util.pyc
├── z3++.h
├── z3.exe
├── z3.h
├── z3_algebraic.h
├── z3_api.h
├── z3_ast_containers.h
├── z3_fixedpoint.h
├── z3_fpa.h
├── z3_interp.h
├── z3_macros.h
├── z3_optimization.h
├── z3_polynomial.h
├── z3_rcf.h
├── z3_spacer.h
└── z3_v1.h
└── include
├── z3++.h
├── z3.h
├── z3_algebraic.h
├── z3_api.h
├── z3_ast_containers.h
├── z3_fixedpoint.h
├── z3_fpa.h
├── z3_interp.h
├── z3_macros.h
├── z3_optimization.h
├── z3_polynomial.h
├── z3_rcf.h
├── z3_spacer.h
└── z3_v1.h
/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/.gitattributes:
--------------------------------------------------------------------------------
1 | # Auto detect text files and perform LF normalization
2 | * text=auto
3 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | /.metadata/
2 | /.recommenders/
3 | /bin/
4 |
--------------------------------------------------------------------------------
/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | C Path Finder
4 |
5 |
6 |
7 |
8 |
9 | org.eclipse.jdt.core.javabuilder
10 |
11 |
12 |
13 |
14 |
15 | org.eclipse.jdt.core.javanature
16 |
17 |
18 |
--------------------------------------------------------------------------------
/Documentation/About.txt:
--------------------------------------------------------------------------------
1 | C Path Finder v1.0.1
2 |
3 | Developer: Sajed Jalil
4 | Developer Mail: bsse0714@iit.du.ac.bd
5 |
6 | **************************************************************
7 |
8 | About
9 |
10 | C Path Finder is an automatic test case generator for C projects.
11 |
12 | For more, please visit us at https://github.com/Sajed49/C-Path-Finder
13 |
--------------------------------------------------------------------------------
/Documentation/Detailed Report with User Manual.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sajedjalil/C-Path-Finder/ee748c939fbad4fd0d8aa2647abca411f320e734/Documentation/Detailed Report with User Manual.pdf
--------------------------------------------------------------------------------
/Documentation/Technical Document.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sajedjalil/C-Path-Finder/ee748c939fbad4fd0d8aa2647abca411f320e734/Documentation/Technical Document.pdf
--------------------------------------------------------------------------------
/Documentation/User Manual.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sajedjalil/C-Path-Finder/ee748c939fbad4fd0d8aa2647abca411f320e734/Documentation/User Manual.pdf
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2018 Sajed Jalil
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # C-Path-Finder
2 |
3 | An automatic unit test case generator for C source code using Memorized Symbolic Execution & z3 solver
4 |
--------------------------------------------------------------------------------
/resources/appIcon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sajedjalil/C-Path-Finder/ee748c939fbad4fd0d8aa2647abca411f320e734/resources/appIcon.ico
--------------------------------------------------------------------------------
/resources/icon16.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sajedjalil/C-Path-Finder/ee748c939fbad4fd0d8aa2647abca411f320e734/resources/icon16.png
--------------------------------------------------------------------------------
/resources/logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sajedjalil/C-Path-Finder/ee748c939fbad4fd0d8aa2647abca411f320e734/resources/logo.png
--------------------------------------------------------------------------------
/src/codeBeautifier/BlankLineRemover.java:
--------------------------------------------------------------------------------
1 | package codeBeautifier;
2 |
3 | import java.util.ArrayList;
4 |
5 | public class BlankLineRemover {
6 |
7 | public static ArrayList removeBlankLines( ArrayList fileText){
8 |
9 | ArrayList temp = new ArrayList();
10 |
11 | for(String s: fileText) {
12 | if( s.trim().length() > 0 ) {
13 | temp.add(s);
14 | }
15 | }
16 |
17 | return temp;
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/src/codeBeautifier/CmdExecutor.java:
--------------------------------------------------------------------------------
1 | package codeBeautifier;
2 |
3 | import java.io.BufferedReader;
4 | import java.io.BufferedWriter;
5 | import java.io.File;
6 | import java.io.FileWriter;
7 | import java.io.IOException;
8 | import java.io.InputStreamReader;
9 | import java.util.ArrayList;
10 |
11 | public class CmdExecutor {
12 |
13 | public CmdExecutor(String directory, String inputFileName, String outputFileName) {
14 |
15 |
16 | removeCommentsGCC( new File(directory), inputFileName, outputFileName);
17 | }
18 |
19 | public CmdExecutor(String directory, String inputFilePath) {
20 | this(directory, inputFilePath, inputFilePath);
21 | }
22 |
23 | private void removeCommentsGCC(File directory, String inputFileName, String outputFileName) {
24 |
25 | inputFileName = "\"" +inputFileName + "\"";
26 |
27 | //System.out.println(directory.getPath() + " "+ inputFileName);
28 | try {
29 |
30 | Process p = Runtime.getRuntime().exec("cmd /C gcc -fpreprocessed -dD -E "
31 | + inputFileName, null, directory);
32 |
33 | BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream()));
34 |
35 | ArrayList temp = new ArrayList();
36 |
37 | String line = null;
38 | while ((line = in.readLine()) != null) temp.add(line);
39 | in.close();
40 |
41 | BufferedWriter out = new BufferedWriter(new FileWriter(directory+"\\"+outputFileName));
42 |
43 | for(String s: temp) {
44 | out.write(s);
45 | out.newLine();
46 | }
47 |
48 | temp.clear();
49 | out.close();
50 |
51 | } catch (IOException e ) {
52 | e.printStackTrace();
53 | }
54 |
55 | }
56 |
57 | }
58 |
--------------------------------------------------------------------------------
/src/codeBeautifier/CodeBeautifier.java:
--------------------------------------------------------------------------------
1 | package codeBeautifier;
2 |
3 | import java.io.File;
4 | import java.util.ArrayList;
5 |
6 | import io.CustomFileReader;
7 | import io.CustomFileWriter;
8 |
9 | public class CodeBeautifier {
10 |
11 | public CodeBeautifier(File sourceFilesDirectory) {
12 |
13 | directorySearcher(sourceFilesDirectory);
14 | }
15 |
16 | public void beautify(File currentFile) {
17 |
18 | ArrayList lines = CustomFileReader.readAfile(currentFile);
19 |
20 | /**Faster Approach
21 | * Manual parsing
22 | */
23 | lines = CommentRemover.removeComments(lines);
24 | lines = BlankLineRemover.removeBlankLines(lines);
25 |
26 | CustomFileWriter.writeAFile(currentFile, lines);
27 |
28 | /**
29 | * Slower almost 15 times
30 | * GCC implementation invoke
31 | */
32 | //LineRemover.removeIncludeStatementLine(a);
33 | //new CmdExecutor(currentDirectory.getPath(), a.getName(), a.getName());
34 | //LineRemover.removeUnnecessaryLine(a);
35 | }
36 |
37 | private void directorySearcher(File currentDirectory) {
38 |
39 | for(File file: currentDirectory.listFiles()) {
40 |
41 | if(file.isDirectory()) {
42 | directorySearcher(file);
43 | }
44 | else if(file.isFile()) {
45 |
46 | beautify(file);
47 | }
48 | }
49 | }
50 |
51 |
52 |
53 | }
54 |
--------------------------------------------------------------------------------
/src/codeBeautifier/CommentRemover.java:
--------------------------------------------------------------------------------
1 | package codeBeautifier;
2 |
3 | import java.util.ArrayList;
4 |
5 | public class CommentRemover {
6 |
7 | public CommentRemover() {
8 |
9 | }
10 |
11 | public static ArrayList removeComments( ArrayList fileText){
12 |
13 | ArrayList temp = new ArrayList();
14 |
15 | int multipleLineCommentFlag = 0;
16 | int doubleQuoteFlag = 0;
17 | int multipleCommentLineStart = 0;
18 |
19 |
20 | for(int line=0; line 0 && (int)s.charAt( s.length()-1 ) == 34 ) doubleQuoteFlag = (doubleQuoteFlag+1)%2;
65 |
66 | temp.add(s);
67 | }
68 |
69 | return temp;
70 | }
71 | }
72 |
--------------------------------------------------------------------------------
/src/codeBeautifier/LineRemover.java:
--------------------------------------------------------------------------------
1 | package codeBeautifier;
2 |
3 | import java.io.File;
4 | import java.io.IOException;
5 | import java.nio.file.Files;
6 | import java.nio.file.StandardOpenOption;
7 | import java.util.List;
8 | import java.util.stream.Collectors;
9 |
10 | class LineRemover {
11 |
12 |
13 | public static void removeIncludeStatementLine(File inputFile) {
14 |
15 | List out;
16 | try {
17 | out = Files.lines(inputFile.toPath())
18 | .filter(line -> ifIncludeStatementJunk(line) )
19 | .collect(Collectors.toList());
20 |
21 |
22 |
23 | Files.write(inputFile.toPath(), out, StandardOpenOption.WRITE, StandardOpenOption.TRUNCATE_EXISTING);
24 | } catch (IOException e) {
25 | // TODO Auto-generated catch block
26 | e.printStackTrace();
27 | }
28 |
29 | }
30 |
31 | private static Boolean ifIncludeStatementJunk(String line) {
32 |
33 | if( line.trim().length() == 0) return false;
34 |
35 | String [] temp = line.split(" ");
36 |
37 | if( temp.length > 0 ) {
38 | if( temp[0].startsWith("#include")) return false; //removes #include lines
39 | }
40 |
41 | return true;
42 | }
43 |
44 |
45 |
46 | public static void removeUnnecessaryLine(File inputFile) {
47 |
48 | List out;
49 | try {
50 | out = Files.lines(inputFile.toPath())
51 | .filter(line -> ifOtherJunk(line) )
52 | .collect(Collectors.toList());
53 |
54 |
55 |
56 | Files.write(inputFile.toPath(), out, StandardOpenOption.WRITE, StandardOpenOption.TRUNCATE_EXISTING);
57 | } catch (IOException e) {
58 | // TODO Auto-generated catch block
59 | e.printStackTrace();
60 | }
61 |
62 | }
63 |
64 | private static Boolean ifOtherJunk(String line) {
65 |
66 | if( line.trim().length() == 0) return false;
67 |
68 | String [] temp = line.split(" ");
69 |
70 | if( temp.length > 0 ) {
71 | if( temp[0].startsWith("#") && !temp[0].startsWith("#define")) return false; //removes #include lines
72 | else if( temp[0].startsWith("#") && !temp[0].startsWith("#typedef")) return false;
73 | }
74 |
75 | return true;
76 | }
77 | }
78 |
--------------------------------------------------------------------------------
/src/codeBeautifier/package-info.java:
--------------------------------------------------------------------------------
1 | /**
2 | * @author Sajed Jalil
3 | * @email bsse0714@iit.du.ac.bd
4 | * @year 2018
5 | * @location Dhaka
6 | *
7 | */
8 | package codeBeautifier;
--------------------------------------------------------------------------------
/src/controlFlowGraphBuilder/Node.java:
--------------------------------------------------------------------------------
1 | package controlFlowGraphBuilder;
2 |
3 | public class Node {
4 |
5 | public int leftChildID = -1; //null initially
6 | public int rightChildID = -1; //null initially
7 |
8 | public Node leftChild;
9 | public Node rightChild;
10 |
11 | public int id, level;
12 | public String content;
13 | public String conditions = "";
14 | public Boolean ifAssignmentStatement = false;
15 |
16 | private void setIfAssignmentStatement() {
17 | if( content.contains(" = ") ) ifAssignmentStatement = true;
18 | }
19 |
20 | public Node(int id, String content, int level) {
21 | this.id = id;
22 | this.content = content;
23 | this.level = level;
24 | //System.out.println(content+" "+id);
25 | getConditions();
26 | setIfAssignmentStatement();
27 | }
28 |
29 |
30 | private void getConditions() {
31 |
32 | String temp = "";
33 | int flag = 0;
34 | int len = content.length();
35 |
36 | if( content.startsWith("if") || content.startsWith("else if") ) {
37 |
38 | for(int i=0; i 0 ) temp += content.charAt(i);
50 | }
51 | }
52 |
53 | //there exists a condition
54 | if( temp.trim().isEmpty() == false) {
55 | conditions = temp.trim();
56 | //System.out.println(conditions);
57 | }
58 | }
59 |
60 |
61 | }
62 |
--------------------------------------------------------------------------------
/src/controlFlowGraphBuilder/package-info.java:
--------------------------------------------------------------------------------
1 | /**
2 | * @author Sajed Jalil
3 | * @email bsse0714@iit.du.ac.bd
4 | * @year 2018
5 | * @location Dhaka
6 | *
7 | */
8 | package controlFlowGraphBuilder;
--------------------------------------------------------------------------------
/src/database/DatabaseLoader.java:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sajedjalil/C-Path-Finder/ee748c939fbad4fd0d8aa2647abca411f320e734/src/database/DatabaseLoader.java
--------------------------------------------------------------------------------
/src/database/package-info.java:
--------------------------------------------------------------------------------
1 | /**
2 | * @author Sajed Jalil
3 | * @email bsse0714@iit.du.ac.bd
4 | * @year 2018
5 | * @location Dhaka
6 | *
7 | */
8 | package database;
--------------------------------------------------------------------------------
/src/io/CustomFileReader.java:
--------------------------------------------------------------------------------
1 | package io;
2 |
3 | import java.io.BufferedReader;
4 | import java.io.File;
5 | import java.io.FileNotFoundException;
6 | import java.io.FileReader;
7 | import java.io.IOException;
8 | import java.util.ArrayList;
9 |
10 | public class CustomFileReader {
11 |
12 | public static ArrayList readAfile( File currentFile){
13 |
14 | ArrayList temp = new ArrayList();
15 |
16 | BufferedReader br = null;
17 | FileReader fr = null;
18 |
19 | try {
20 |
21 |
22 | fr = new FileReader(currentFile);
23 | br = new BufferedReader(fr);
24 |
25 | String line;
26 |
27 | while ((line = br.readLine()) != null) {
28 | temp.add(line);
29 | }
30 |
31 | } catch (FileNotFoundException e) {
32 |
33 | System.out.println("Could not found "+currentFile.getName()+" in "+currentFile.getPath());
34 |
35 | }
36 | catch (IOException e) {
37 |
38 | System.out.println("Error in reading file in "+currentFile.getName()+" in "+currentFile.getPath());
39 |
40 | } finally {
41 |
42 | try {
43 |
44 | if (br != null)
45 | br.close();
46 |
47 | if (fr != null)
48 | fr.close();
49 |
50 | } catch (IOException ex) {
51 |
52 | ex.printStackTrace();
53 |
54 | }
55 |
56 | }
57 |
58 | return temp;
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/src/io/CustomFileWriter.java:
--------------------------------------------------------------------------------
1 | package io;
2 |
3 | import java.io.BufferedWriter;
4 | import java.io.File;
5 | import java.io.FileWriter;
6 | import java.io.IOException;
7 | import java.util.ArrayList;
8 |
9 | public class CustomFileWriter {
10 |
11 | public static void writeAFile(File currentFile ,ArrayList lines) {
12 |
13 | BufferedWriter bw = null;
14 | FileWriter fw = null;
15 |
16 | try {
17 |
18 |
19 | fw = new FileWriter(currentFile);
20 | bw = new BufferedWriter(fw);
21 |
22 | for(String s: lines) {
23 | bw.write(s);
24 | bw.newLine();
25 | }
26 |
27 | } catch (IOException e) {
28 |
29 | e.printStackTrace();
30 |
31 | } finally {
32 |
33 | try {
34 |
35 | if (bw != null)
36 | bw.close();
37 |
38 | if (fw != null)
39 | fw.close();
40 |
41 | } catch (IOException ex) {
42 |
43 | ex.printStackTrace();
44 |
45 | }
46 | }
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/src/io/InputFileCopyMachine.java:
--------------------------------------------------------------------------------
1 |
2 | package io;
3 |
4 | import java.io.File;
5 | import java.io.IOException;
6 | import java.nio.file.Files;
7 | import java.nio.file.Path;
8 | import java.nio.file.Paths;
9 | import java.nio.file.StandardCopyOption;
10 |
11 | public class InputFileCopyMachine {
12 |
13 | public InputFileCopyMachine(String sourcePath, String destinationPath) {
14 |
15 | makeMainOutputDirectory(destinationPath);
16 | copyDirectory(sourcePath, destinationPath);
17 | }
18 |
19 |
20 |
21 | private void makeMainOutputDirectory(String destinationPath) {
22 |
23 | File dir = new File(destinationPath);
24 | dir.mkdirs();
25 | }
26 |
27 |
28 |
29 |
30 | private void copyDirectory(String sourcePath, String destinationPath) {
31 |
32 |
33 | File source = new File(sourcePath);
34 |
35 |
36 | for(File a : source.listFiles()) {
37 |
38 | Path s = Paths.get(a.getPath());
39 | Path d = Paths.get(destinationPath+"\\"+a.getName());
40 |
41 |
42 | if( a.isDirectory() ) {
43 |
44 | try {
45 |
46 | if(!Files.exists(d))
47 | Files.copy(s, d, StandardCopyOption.REPLACE_EXISTING );
48 |
49 | copyDirectory(a.getPath(), destinationPath+"\\"+a.getName());
50 |
51 | } catch (IOException e) { e.printStackTrace(); }
52 |
53 |
54 | }
55 | else if( a.isFile() && (a.getName().endsWith(".c") || a.getName().endsWith(".h")) ) {
56 |
57 | try {
58 | Files.copy(s, d, StandardCopyOption.REPLACE_EXISTING );
59 | } catch (IOException e) {
60 | // TODO Auto-generated catch block
61 | e.printStackTrace();
62 | }
63 | }
64 | }
65 |
66 | }
67 |
68 |
69 | }
70 |
--------------------------------------------------------------------------------
/src/io/package-info.java:
--------------------------------------------------------------------------------
1 | /**
2 | * @author Sajed Jalil
3 | * @email bsse0714@iit.du.ac.bd
4 | * @year 2018
5 | * @location Dhaka
6 | *
7 | */
8 | package io;
--------------------------------------------------------------------------------
/src/main/MainController.java:
--------------------------------------------------------------------------------
1 | package main;
2 |
3 | import java.awt.Desktop;
4 | import java.io.File;
5 | import java.io.IOException;
6 | import java.util.ArrayList;
7 | import java.util.concurrent.ExecutorService;
8 | import java.util.concurrent.Executors;
9 | import java.util.concurrent.Future;
10 | import java.util.concurrent.TimeUnit;
11 | import java.util.concurrent.TimeoutException;
12 |
13 | import javafx.application.Platform;
14 | import javafx.fxml.FXML;
15 | import javafx.scene.control.Button;
16 | import javafx.scene.control.ProgressBar;
17 | import javafx.scene.text.Text;
18 | import javafx.stage.DirectoryChooser;
19 | import parser.CParser;
20 |
21 | public class MainController {
22 |
23 | @FXML Button openFileButton;
24 | @FXML Button runButton;
25 | @FXML Button openResultButton;
26 |
27 | @FXML Text openFilePath;
28 | @FXML ProgressBar runProgress;
29 | @FXML Text status;
30 | @FXML Text resultDirectory;
31 | @FXML Text copyright;
32 |
33 | @FXML
34 | private void selectFiles() {
35 |
36 | DirectoryChooser directoryChooser = new DirectoryChooser();
37 | File selectedDirectory = directoryChooser.showDialog(Start.primaryStage);
38 |
39 | if(selectedDirectory == null){
40 | System.out.println("null");
41 | }else{
42 |
43 | openFilePath.setText(selectedDirectory.getAbsolutePath());
44 |
45 | openFileButton.setText("Change");
46 | runButton.setText("Run");
47 |
48 | Start.inputPath = selectedDirectory.getAbsolutePath();
49 |
50 | runButton.setVisible(true);
51 |
52 | }
53 | }
54 |
55 |
56 | @FXML
57 | private void runFiles() {
58 |
59 | runProgress.setProgress(0.00);
60 | status.setText("Processing Source Files");
61 |
62 | runProgress.setVisible(true);
63 | status.setVisible(true);
64 |
65 |
66 |
67 |
68 |
69 |
70 | new Thread(){
71 | public void run() {
72 |
73 | ArrayList changedFiles = Start.runInit();
74 | Platform.runLater(() -> runProgress.setProgress( 0.1));
75 |
76 |
77 | final double step = 0.9 / changedFiles.size();
78 |
79 | for(int i=0; i f = service.submit(() -> {
87 | new CParser(changedFiles.get(temp));
88 | Thread.sleep(100); // Simulate some delay
89 | return "42";
90 | });
91 |
92 | System.out.println(f.get(10, TimeUnit.SECONDS));
93 | } catch (final TimeoutException e) {
94 | System.err.println("Calculation took to long");
95 | } catch (final Exception e) {
96 | throw new RuntimeException(e);
97 | } finally {
98 | service.shutdown();
99 | }
100 |
101 |
102 | final double adder = (i+1)*step;
103 |
104 | Platform.runLater(() -> runProgress.setProgress( 0.1 + adder ));
105 | status.setText("Analyzing: "+changedFiles.get(i));
106 |
107 | }
108 |
109 | Platform.runLater(() -> runProgress.setProgress( 1.0 ));
110 | status.setText("Done");
111 | Start.deleteTempFiles();
112 | Platform.runLater(() -> runButton.setText("Re-Run") );
113 |
114 | openResultButton.setVisible(true);
115 | resultDirectory.setVisible(true);
116 |
117 | }
118 | }.start();
119 |
120 |
121 |
122 |
123 | }
124 |
125 |
126 | @FXML
127 | private void changeOutputDirectory() {
128 |
129 | DirectoryChooser directoryChooser = new DirectoryChooser();
130 | File selectedDirectory = directoryChooser.showDialog(Start.primaryStage);
131 |
132 | if(selectedDirectory == null){
133 | System.out.println("null");
134 | }else{
135 |
136 | System.out.println(selectedDirectory.getAbsolutePath());
137 | CParser.testCaseOutputDirectory = selectedDirectory.getAbsolutePath();
138 |
139 | resultDirectory.setText(CParser.testCaseOutputDirectory);
140 | }
141 |
142 | }
143 |
144 |
145 | @FXML
146 | private void openOutputDirectory() {
147 |
148 | Desktop desktop = Desktop.getDesktop();
149 | try {
150 | desktop.open( new File(CParser.testCaseOutputDirectory) );
151 | } catch (IOException e) {
152 | // TODO Auto-generated catch block
153 | e.printStackTrace();
154 | }
155 |
156 | }
157 |
158 | @FXML
159 | private void exitProgram() {
160 |
161 | System.exit(0);
162 |
163 | }
164 |
165 | @FXML
166 | private void openAbout() {
167 |
168 | if (Desktop.isDesktopSupported()) {
169 | try {
170 | File myFile = new File("Documentation\\About.txt");
171 | Desktop.getDesktop().open(myFile);
172 | } catch (IOException ex) {
173 | // no application registered for PDFs
174 | }
175 | }
176 | }
177 |
178 |
179 | @FXML
180 | private void openTutorial() {
181 |
182 | if (Desktop.isDesktopSupported()) {
183 | try {
184 | File myFile = new File("Documentation\\User Manual.pdf");
185 | Desktop.getDesktop().open(myFile);
186 | } catch (IOException ex) {
187 | // no application registered for PDFs
188 | }
189 | }
190 | }
191 | }
192 |
--------------------------------------------------------------------------------
/src/main/MainView.fxml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
23 |
28 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
--------------------------------------------------------------------------------
/src/main/Start.java:
--------------------------------------------------------------------------------
1 | package main;
2 |
3 | import javafx.application.Application;
4 | import javafx.fxml.FXMLLoader;
5 | import javafx.scene.Scene;
6 | import javafx.scene.image.Image;
7 | import javafx.scene.layout.AnchorPane;
8 | import javafx.stage.Stage;
9 |
10 | import java.io.File;
11 | import java.io.IOException;
12 | import java.nio.file.Files;
13 | import java.nio.file.Path;
14 | import java.nio.file.Paths;
15 | import java.util.ArrayList;
16 | import java.util.Comparator;
17 |
18 | import javax.swing.filechooser.FileSystemView;
19 |
20 | import codeBeautifier.CodeBeautifier;
21 | import database.DatabaseLoader;
22 | import io.InputFileCopyMachine;
23 |
24 | public class Start extends Application{
25 |
26 |
27 | public static Stage primaryStage;
28 |
29 |
30 | public static String inputPath;
31 | public static String outputPath = "//C Path Finder//results";
32 |
33 | private static DatabaseLoader dbloader = new DatabaseLoader();
34 | public static int currentProjectId;
35 |
36 | public static void main(String[] args) {
37 |
38 | loadNecessaryStuffs();
39 |
40 | launch(args);
41 | }
42 |
43 | private static void loadNecessaryStuffs() {
44 |
45 | String myDocuments = FileSystemView.getFileSystemView().getDefaultDirectory().getPath();
46 | outputPath = myDocuments + outputPath;
47 |
48 |
49 |
50 | try {
51 | Class.forName("org.sqlite.JDBC");
52 | } catch (ClassNotFoundException e1) {
53 | e1.printStackTrace();
54 | }
55 | }
56 |
57 | @Override
58 | public void start(Stage primaryStage) throws IOException{
59 |
60 | Start.primaryStage = primaryStage;
61 | Start.primaryStage.setTitle("C Path Finder");
62 | Start.primaryStage.getIcons().add( new Image("file:resources//icon16.png") );
63 |
64 | showMainView();
65 | }
66 |
67 |
68 | private void showMainView() {
69 |
70 | try {
71 | AnchorPane root = FXMLLoader.load(getClass().getResource("MainView.fxml"));
72 | Scene scene = new Scene(root,550,400);
73 | scene.getStylesheets().add(getClass().getResource("application.css").toExternalForm());
74 | primaryStage.setScene(scene);
75 | primaryStage.show();
76 | } catch(Exception e) {
77 | e.printStackTrace();
78 | }
79 | }
80 |
81 | public static String openSystemPathChooser() {
82 |
83 | return null;
84 | }
85 |
86 | public static ArrayList runInit(){
87 |
88 | dbloader.changedFiles = new ArrayList();
89 |
90 | database();
91 |
92 | new InputFileCopyMachine(inputPath, outputPath);
93 |
94 | //for memorized execution
95 | dbloader.directorySearcher( new File(outputPath) );
96 |
97 | new CodeBeautifier( new File(outputPath));
98 |
99 | dbloader.loadIntoFileTable();
100 |
101 | return dbloader.getChangedFiles();
102 | }
103 |
104 | public static void deleteTempFiles() {
105 | try {
106 | Files.walk( Paths.get(outputPath) ).sorted(Comparator.reverseOrder())
107 | .map(Path::toFile)
108 | .forEach(File::delete);
109 | }catch (IOException e) {
110 | e.printStackTrace();
111 | }
112 | }
113 |
114 | private static void database() {
115 |
116 | dbloader.insertINtoProjectTable(inputPath);
117 | currentProjectId = dbloader.getProjectId(inputPath);
118 | //dbloader.ifFileToBeRun(new File("E:\\GitHub\\C-Path-Finder\\test\\1.c"), "Wed Nov 21 13:17:12 BDT 2018");
119 | //dbloader.insertINtoFileTable("1.c", "results\\1.c", "Wed Nov 21 13:17:12 BDT 2018", "1");
120 | //dbloader.insertINtoFileTable("2.c", "results\\2.c", "Wed Nov 21 13:17:12 BDT 2018", "1");
121 | //dbloader.insertINtoFileTable("3.c", "results\\3.c", "Wed Nov 21 13:17:12 BDT 2018", "1");
122 | //dbloader.selectAllFile();
123 |
124 | //System.out.println( dbloader.getLastRunFromDB( new File("results\\1.c") ) );;
125 |
126 |
127 |
128 | }
129 | }
130 |
--------------------------------------------------------------------------------
/src/main/application.css:
--------------------------------------------------------------------------------
1 | /* JavaFX CSS - Leave this comment until you have at least create one rule which uses -fx-Property */
--------------------------------------------------------------------------------
/src/main/package-info.java:
--------------------------------------------------------------------------------
1 | /**
2 | * @author Sajed Jalil
3 | * @email bsse0714@iit.du.ac.bd
4 | * @year 2018
5 | * @location Dhaka
6 | *
7 | */
8 |
9 | package main;
--------------------------------------------------------------------------------
/src/parser/CParser.java:
--------------------------------------------------------------------------------
1 | package parser;
2 |
3 | import java.io.File;
4 | import java.util.ArrayList;
5 |
6 | import javax.swing.filechooser.FileSystemView;
7 |
8 | import io.CustomFileWriter;
9 | import parser.components.*;
10 |
11 | public class CParser {
12 |
13 | public static String testCaseOutputDirectory =
14 | FileSystemView.getFileSystemView().getDefaultDirectory().getPath()
15 | +"//C Path Finder//testcases";
16 |
17 | public CParser(File file) {
18 |
19 | makeMainOutputDirectory();
20 |
21 | //directorySearcher( file );
22 |
23 |
24 | }
25 |
26 | public CParser(String changedFilePath) {
27 |
28 |
29 | File file = new File(changedFilePath);
30 | ObjectFile ob = processSingleFile(file);
31 | outputTestCase(ob);
32 | }
33 |
34 |
35 | private void makeMainOutputDirectory() {
36 |
37 | File dir = new File(testCaseOutputDirectory);
38 | dir.mkdirs();
39 | }
40 | /*
41 | public static void main(String[] args) {
42 | new CParser(new File("results"));
43 | }
44 | */
45 | /*
46 | private void directorySearcher(File currentDirectory) {
47 |
48 | for(File file: currentDirectory.listFiles()) {
49 |
50 | if(file.isDirectory()) {
51 |
52 | directorySearcher(file);
53 | }
54 | else if(file.isFile()) {
55 |
56 | //parse single file
57 | ObjectFile ob = processSingleFile(file);
58 | outputTestCase(ob);
59 | }
60 | }
61 | }
62 | */
63 |
64 | private void outputTestCase(ObjectFile objectFile) {
65 |
66 | ArrayList results = new ArrayList();
67 |
68 | results.add("File Name: "+objectFile.fileName);
69 | results.add("File Path: "+objectFile.filePath);
70 | results.add("\n\n\n");
71 |
72 |
73 | int methodNumber = 0;
74 |
75 | for( ArrayList temp : objectFile.result.testcases) {
76 |
77 | //add method name
78 | results.add("Method Name: "+objectFile.result.methodNames.get(methodNumber++));
79 |
80 | for( int i=0; i parameters = new ArrayList();
17 | public ArrayList body = new ArrayList();
18 |
19 | public ArrayList nodes = new ArrayList();
20 | public Node executionTree = null;
21 | public ArrayList< ArrayList > paths = new ArrayList< ArrayList >();
22 |
23 |
24 | public Method( int startLine, int finishLine, List temp ) {
25 |
26 | this.startLine = startLine;
27 | this.finishLine = finishLine;
28 |
29 | for(String s:temp) methodData += s;
30 | }
31 |
32 |
33 |
34 | private int sequence[];
35 |
36 |
37 | public void findPaths() {
38 | sequence = new int[nodes.size()];
39 |
40 | for(int i=0; i temp = new ArrayList();
65 | for(int i=0; i directives = new ArrayList();
16 | public ArrayList methods = new ArrayList();
17 | public ArrayList userDefinedData = new ArrayList();
18 |
19 | public String fileName = "";
20 | public String filePath = "";
21 |
22 | public ArrayList fileData = new ArrayList();
23 |
24 | public FileResult result;
25 |
26 |
27 |
28 | public ObjectFile(File file) {
29 |
30 | init(file);
31 |
32 | separateMainComponents();
33 | parseMethods();
34 | }
35 |
36 |
37 | private void init(File file) {
38 | //read file contents
39 | fileData = CustomFileReader.readAfile( file );
40 |
41 | fileName = file.getName();
42 | filePath = file.getPath();
43 |
44 | result = new FileResult(file);
45 | }
46 |
47 | private void separateMainComponents() {
48 | ComponentSeparator cs = new ComponentSeparator(this);
49 | cs.getComponent(this);
50 |
51 | }
52 |
53 |
54 | private void parseMethods() {
55 |
56 | for(Method m: methods) {
57 |
58 | new MethodParser(m); //parse method
59 | new CFGBuilder(m); // build control flow graph
60 |
61 | m.findPaths();
62 |
63 | SymbolicSolver ss = new SymbolicSolver(m);
64 | result.methodNames.add(m.methodName);
65 | result.testcases.add( ss.testcases );
66 |
67 | }
68 | }
69 |
70 |
71 | }
72 |
--------------------------------------------------------------------------------
/src/parser/components/UserDefinedData.java:
--------------------------------------------------------------------------------
1 | package parser.components;
2 |
3 | public class UserDefinedData extends Component {
4 |
5 | int startLine;
6 | int finishLine;
7 |
8 | public UserDefinedData( int startLine, int finishLine ) {
9 | this.startLine = startLine;
10 | this.finishLine = finishLine;
11 | }
12 |
13 | }
14 |
--------------------------------------------------------------------------------
/src/parser/components/Variable.java:
--------------------------------------------------------------------------------
1 | package parser.components;
2 |
3 | import java.util.ArrayList;
4 | import java.util.Arrays;
5 |
6 | public class Variable {
7 |
8 | private String dataType = "";
9 | private String name = "";
10 | private String actualValue = "";
11 | public String line = "";
12 |
13 | public String getDataType() {
14 | return dataType;
15 | }
16 |
17 | public String getName() {
18 | return name;
19 | }
20 |
21 | public String getActualValue() {
22 | return actualValue;
23 | }
24 |
25 | public void setActualValue(String actualValue) {
26 | this.actualValue = actualValue;
27 | }
28 |
29 | public Variable( String line ) {
30 | this.line = line;
31 | parseLine(line);
32 | }
33 |
34 |
35 | private void parseLine(String line) {
36 |
37 | /** trim to remove extra spaces from first and last
38 | * split on the basis of one or multiple space between
39 | */
40 | ArrayList words = new ArrayList<>( Arrays.asList( line.trim().split(" +") ) );
41 | int size = words.size();
42 |
43 | if( words.contains("=")) {
44 |
45 | System.out.println(line);
46 |
47 | if(line.split("=").length < 2) return;
48 | String beforeEqualSign[] = line.split("=")[0].trim().split(" +");
49 | String afterEqualSign = line.split("=")[1].trim();
50 |
51 | //System.out.println(words.size());
52 | for(int i=0; i methodNames = new ArrayList();
13 | public ArrayList< ArrayList> testcases = new ArrayList< ArrayList>();
14 |
15 | public FileResult(File file) {
16 |
17 | filePath = file.getPath();
18 | fileName = file.getName();
19 | }
20 |
21 | }
22 |
--------------------------------------------------------------------------------
/src/result/package-info.java:
--------------------------------------------------------------------------------
1 | /**
2 | * @author Sajed Jalil
3 | * @email bsse0714@iit.du.ac.bd
4 | * @year 2018
5 | * @location Dhaka
6 | *
7 | */
8 | package result;
--------------------------------------------------------------------------------
/src/symbolicSolver/package-info.java:
--------------------------------------------------------------------------------
1 | /**
2 | * @author Sajed Jalil
3 | * @email bsse0714@iit.du.ac.bd
4 | * @year 2018
5 | * @location Dhaka
6 | *
7 | */
8 | package symbolicSolver;
--------------------------------------------------------------------------------
/test/1.c:
--------------------------------------------------------------------------------
1 | #include
2 | int main()
3 | {
4 | int number1, number2;
5 | printf("Enter two integers: ");
6 | scanf("%d %d", &number1, &number2);
7 |
8 | if (number1 >= number2)
9 | {
10 | if (number1 == number2)
11 | {
12 | printf("Result: %d = %d",number1,number2);
13 | }
14 | else
15 | {
16 | printf("Result: %d > %d", number1, number2);
17 | }
18 | }
19 | else
20 | {
21 | printf("Result: %d < %d",number1, number2);
22 | }
23 |
24 | return 0;
25 | }
26 |
27 | int test(float number1, float number2)
28 | {
29 | if (number1 >= number2)
30 | {
31 | if (number1 == number2)
32 | {
33 | printf("Result: %d = %d",number1,number2);
34 | }
35 | else
36 | {
37 | printf("Result: %d > %d", number1, number2);
38 | }
39 | }
40 | else
41 | {
42 | printf("Result: %d < %d",number1, number2);
43 | }
44 | return 0;
45 | }
--------------------------------------------------------------------------------
/test/Mini Project in C Bank Management System/Readme.docx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sajedjalil/C-Path-Finder/ee748c939fbad4fd0d8aa2647abca411f320e734/test/Mini Project in C Bank Management System/Readme.docx
--------------------------------------------------------------------------------
/test/Mini Project in C Library Management System/Readme.docx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sajedjalil/C-Path-Finder/ee748c939fbad4fd0d8aa2647abca411f320e734/test/Mini Project in C Library Management System/Readme.docx
--------------------------------------------------------------------------------
/test/custom.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include/*
3 | jhjkjhjkh
4 | fd*/
5 | /**//**/
6 | #include /* */ hi
7 | #include
8 | #include //contains strcmp(),strcpy(),strlen(),etc
9 | #include //contains toupper(), tolower(),etc
10 | #include //contains _dos_getdate
11 | #include
12 |
13 | int main(void) {
14 | printf("//erer");
15 | printf("ds/*dfd*//**/");
16 | dfd;//dfsd
17 | sf;
18 | }
19 | //#include
20 |
21 | /*void loaderanim()
22 | {
23 | int loader;
24 | system("cls");
25 | gotoxy(20,10);
26 | printf("LOADING........");
27 | printf("\n\n");
28 | gotoxy(22,11);
29 | for(loader=1;loader<20;loader++)
30 | {
31 | Sleep(100);printf("%c",219);}
32 | }*/
33 | //End of program
34 | /**/
--------------------------------------------------------------------------------
/test/darknet/src/activation_layer.c:
--------------------------------------------------------------------------------
1 | #include "activation_layer.h"
2 | #include "utils.h"
3 | #include "cuda.h"
4 | #include "blas.h"
5 | #include "gemm.h"
6 |
7 | #include
8 | #include
9 | #include
10 | #include
11 |
12 | layer make_activation_layer(int batch, int inputs, ACTIVATION activation)
13 | {
14 | layer l = {0};
15 | l.type = ACTIVE;
16 |
17 | l.inputs = inputs;
18 | l.outputs = inputs;
19 | l.batch=batch;
20 |
21 | l.output = calloc(batch*inputs, sizeof(float*));
22 | l.delta = calloc(batch*inputs, sizeof(float*));
23 |
24 | l.forward = forward_activation_layer;
25 | l.backward = backward_activation_layer;
26 | #ifdef GPU
27 | l.forward_gpu = forward_activation_layer_gpu;
28 | l.backward_gpu = backward_activation_layer_gpu;
29 |
30 | l.output_gpu = cuda_make_array(l.output, inputs*batch);
31 | l.delta_gpu = cuda_make_array(l.delta, inputs*batch);
32 | #endif
33 | l.activation = activation;
34 | fprintf(stderr, "Activation Layer: %d inputs\n", inputs);
35 | return l;
36 | }
37 |
38 | void forward_activation_layer(layer l, network net)
39 | {
40 | copy_cpu(l.outputs*l.batch, net.input, 1, l.output, 1);
41 | activate_array(l.output, l.outputs*l.batch, l.activation);
42 | }
43 |
44 | void backward_activation_layer(layer l, network net)
45 | {
46 | gradient_array(l.output, l.outputs*l.batch, l.activation, l.delta);
47 | copy_cpu(l.outputs*l.batch, l.delta, 1, net.delta, 1);
48 | }
49 |
50 | #ifdef GPU
51 |
52 | void forward_activation_layer_gpu(layer l, network net)
53 | {
54 | copy_gpu(l.outputs*l.batch, net.input_gpu, 1, l.output_gpu, 1);
55 | activate_array_gpu(l.output_gpu, l.outputs*l.batch, l.activation);
56 | }
57 |
58 | void backward_activation_layer_gpu(layer l, network net)
59 | {
60 | gradient_array_gpu(l.output_gpu, l.outputs*l.batch, l.activation, l.delta_gpu);
61 | copy_gpu(l.outputs*l.batch, l.delta_gpu, 1, net.delta_gpu, 1);
62 | }
63 | #endif
64 |
--------------------------------------------------------------------------------
/test/darknet/src/activation_layer.h:
--------------------------------------------------------------------------------
1 | #ifndef ACTIVATION_LAYER_H
2 | #define ACTIVATION_LAYER_H
3 |
4 | #include "activations.h"
5 | #include "layer.h"
6 | #include "network.h"
7 |
8 | layer make_activation_layer(int batch, int inputs, ACTIVATION activation);
9 |
10 | void forward_activation_layer(layer l, network net);
11 | void backward_activation_layer(layer l, network net);
12 |
13 | #ifdef GPU
14 | void forward_activation_layer_gpu(layer l, network net);
15 | void backward_activation_layer_gpu(layer l, network net);
16 | #endif
17 |
18 | #endif
19 |
20 |
--------------------------------------------------------------------------------
/test/darknet/src/activations.c:
--------------------------------------------------------------------------------
1 | #include "activations.h"
2 |
3 | #include
4 | #include
5 | #include
6 | #include
7 |
8 | char *get_activation_string(ACTIVATION a)
9 | {
10 | switch(a){
11 | case LOGISTIC:
12 | return "logistic";
13 | case LOGGY:
14 | return "loggy";
15 | case RELU:
16 | return "relu";
17 | case ELU:
18 | return "elu";
19 | case SELU:
20 | return "selu";
21 | case RELIE:
22 | return "relie";
23 | case RAMP:
24 | return "ramp";
25 | case LINEAR:
26 | return "linear";
27 | case TANH:
28 | return "tanh";
29 | case PLSE:
30 | return "plse";
31 | case LEAKY:
32 | return "leaky";
33 | case STAIR:
34 | return "stair";
35 | case HARDTAN:
36 | return "hardtan";
37 | case LHTAN:
38 | return "lhtan";
39 | default:
40 | break;
41 | }
42 | return "relu";
43 | }
44 |
45 | ACTIVATION get_activation(char *s)
46 | {
47 | if (strcmp(s, "logistic")==0) return LOGISTIC;
48 | if (strcmp(s, "loggy")==0) return LOGGY;
49 | if (strcmp(s, "relu")==0) return RELU;
50 | if (strcmp(s, "elu")==0) return ELU;
51 | if (strcmp(s, "selu")==0) return SELU;
52 | if (strcmp(s, "relie")==0) return RELIE;
53 | if (strcmp(s, "plse")==0) return PLSE;
54 | if (strcmp(s, "hardtan")==0) return HARDTAN;
55 | if (strcmp(s, "lhtan")==0) return LHTAN;
56 | if (strcmp(s, "linear")==0) return LINEAR;
57 | if (strcmp(s, "ramp")==0) return RAMP;
58 | if (strcmp(s, "leaky")==0) return LEAKY;
59 | if (strcmp(s, "tanh")==0) return TANH;
60 | if (strcmp(s, "stair")==0) return STAIR;
61 | fprintf(stderr, "Couldn't find activation function %s, going with ReLU\n", s);
62 | return RELU;
63 | }
64 |
65 | float activate(float x, ACTIVATION a)
66 | {
67 | switch(a){
68 | case LINEAR:
69 | return linear_activate(x);
70 | case LOGISTIC:
71 | return logistic_activate(x);
72 | case LOGGY:
73 | return loggy_activate(x);
74 | case RELU:
75 | return relu_activate(x);
76 | case ELU:
77 | return elu_activate(x);
78 | case SELU:
79 | return selu_activate(x);
80 | case RELIE:
81 | return relie_activate(x);
82 | case RAMP:
83 | return ramp_activate(x);
84 | case LEAKY:
85 | return leaky_activate(x);
86 | case TANH:
87 | return tanh_activate(x);
88 | case PLSE:
89 | return plse_activate(x);
90 | case STAIR:
91 | return stair_activate(x);
92 | case HARDTAN:
93 | return hardtan_activate(x);
94 | case LHTAN:
95 | return lhtan_activate(x);
96 | }
97 | return 0;
98 | }
99 |
100 | void activate_array(float *x, const int n, const ACTIVATION a)
101 | {
102 | int i;
103 | for(i = 0; i < n; ++i){
104 | x[i] = activate(x[i], a);
105 | }
106 | }
107 |
108 | float gradient(float x, ACTIVATION a)
109 | {
110 | switch(a){
111 | case LINEAR:
112 | return linear_gradient(x);
113 | case LOGISTIC:
114 | return logistic_gradient(x);
115 | case LOGGY:
116 | return loggy_gradient(x);
117 | case RELU:
118 | return relu_gradient(x);
119 | case ELU:
120 | return elu_gradient(x);
121 | case SELU:
122 | return selu_gradient(x);
123 | case RELIE:
124 | return relie_gradient(x);
125 | case RAMP:
126 | return ramp_gradient(x);
127 | case LEAKY:
128 | return leaky_gradient(x);
129 | case TANH:
130 | return tanh_gradient(x);
131 | case PLSE:
132 | return plse_gradient(x);
133 | case STAIR:
134 | return stair_gradient(x);
135 | case HARDTAN:
136 | return hardtan_gradient(x);
137 | case LHTAN:
138 | return lhtan_gradient(x);
139 | }
140 | return 0;
141 | }
142 |
143 | void gradient_array(const float *x, const int n, const ACTIVATION a, float *delta)
144 | {
145 | int i;
146 | for(i = 0; i < n; ++i){
147 | delta[i] *= gradient(x[i], a);
148 | }
149 | }
150 |
151 |
--------------------------------------------------------------------------------
/test/darknet/src/activations.h:
--------------------------------------------------------------------------------
1 | #ifndef ACTIVATIONS_H
2 | #define ACTIVATIONS_H
3 | #include "darknet.h"
4 | #include "cuda.h"
5 | #include "math.h"
6 |
7 | ACTIVATION get_activation(char *s);
8 |
9 | char *get_activation_string(ACTIVATION a);
10 | float activate(float x, ACTIVATION a);
11 | float gradient(float x, ACTIVATION a);
12 | void gradient_array(const float *x, const int n, const ACTIVATION a, float *delta);
13 | void activate_array(float *x, const int n, const ACTIVATION a);
14 | #ifdef GPU
15 | void activate_array_gpu(float *x, int n, ACTIVATION a);
16 | void gradient_array_gpu(float *x, int n, ACTIVATION a, float *delta);
17 | #endif
18 |
19 | static inline float stair_activate(float x)
20 | {
21 | int n = floor(x);
22 | if (n%2 == 0) return floor(x/2.);
23 | else return (x - n) + floor(x/2.);
24 | }
25 | static inline float hardtan_activate(float x)
26 | {
27 | if (x < -1) return -1;
28 | if (x > 1) return 1;
29 | return x;
30 | }
31 | static inline float linear_activate(float x){return x;}
32 | static inline float logistic_activate(float x){return 1./(1. + exp(-x));}
33 | static inline float loggy_activate(float x){return 2./(1. + exp(-x)) - 1;}
34 | static inline float relu_activate(float x){return x*(x>0);}
35 | static inline float elu_activate(float x){return (x >= 0)*x + (x < 0)*(exp(x)-1);}
36 | static inline float selu_activate(float x){return (x >= 0)*1.0507*x + (x < 0)*1.0507*1.6732*(exp(x)-1);}
37 | static inline float relie_activate(float x){return (x>0) ? x : .01*x;}
38 | static inline float ramp_activate(float x){return x*(x>0)+.1*x;}
39 | static inline float leaky_activate(float x){return (x>0) ? x : .1*x;}
40 | static inline float tanh_activate(float x){return (exp(2*x)-1)/(exp(2*x)+1);}
41 | static inline float plse_activate(float x)
42 | {
43 | if(x < -4) return .01 * (x + 4);
44 | if(x > 4) return .01 * (x - 4) + 1;
45 | return .125*x + .5;
46 | }
47 |
48 | static inline float lhtan_activate(float x)
49 | {
50 | if(x < 0) return .001*x;
51 | if(x > 1) return .001*(x-1) + 1;
52 | return x;
53 | }
54 | static inline float lhtan_gradient(float x)
55 | {
56 | if(x > 0 && x < 1) return 1;
57 | return .001;
58 | }
59 |
60 | static inline float hardtan_gradient(float x)
61 | {
62 | if (x > -1 && x < 1) return 1;
63 | return 0;
64 | }
65 | static inline float linear_gradient(float x){return 1;}
66 | static inline float logistic_gradient(float x){return (1-x)*x;}
67 | static inline float loggy_gradient(float x)
68 | {
69 | float y = (x+1.)/2.;
70 | return 2*(1-y)*y;
71 | }
72 | static inline float stair_gradient(float x)
73 | {
74 | if (floor(x) == x) return 0;
75 | return 1;
76 | }
77 | static inline float relu_gradient(float x){return (x>0);}
78 | static inline float elu_gradient(float x){return (x >= 0) + (x < 0)*(x + 1);}
79 | static inline float selu_gradient(float x){return (x >= 0)*1.0507 + (x < 0)*(x + 1.0507*1.6732);}
80 | static inline float relie_gradient(float x){return (x>0) ? 1 : .01;}
81 | static inline float ramp_gradient(float x){return (x>0)+.1;}
82 | static inline float leaky_gradient(float x){return (x>0) ? 1 : .1;}
83 | static inline float tanh_gradient(float x){return 1-x*x;}
84 | static inline float plse_gradient(float x){return (x < 0 || x > 1) ? .01 : .125;}
85 |
86 | #endif
87 |
88 |
--------------------------------------------------------------------------------
/test/darknet/src/avgpool_layer.c:
--------------------------------------------------------------------------------
1 | #include "avgpool_layer.h"
2 | #include "cuda.h"
3 | #include
4 |
5 | avgpool_layer make_avgpool_layer(int batch, int w, int h, int c)
6 | {
7 | fprintf(stderr, "avg %4d x%4d x%4d -> %4d\n", w, h, c, c);
8 | avgpool_layer l = {0};
9 | l.type = AVGPOOL;
10 | l.batch = batch;
11 | l.h = h;
12 | l.w = w;
13 | l.c = c;
14 | l.out_w = 1;
15 | l.out_h = 1;
16 | l.out_c = c;
17 | l.outputs = l.out_c;
18 | l.inputs = h*w*c;
19 | int output_size = l.outputs * batch;
20 | l.output = calloc(output_size, sizeof(float));
21 | l.delta = calloc(output_size, sizeof(float));
22 | l.forward = forward_avgpool_layer;
23 | l.backward = backward_avgpool_layer;
24 | #ifdef GPU
25 | l.forward_gpu = forward_avgpool_layer_gpu;
26 | l.backward_gpu = backward_avgpool_layer_gpu;
27 | l.output_gpu = cuda_make_array(l.output, output_size);
28 | l.delta_gpu = cuda_make_array(l.delta, output_size);
29 | #endif
30 | return l;
31 | }
32 |
33 | void resize_avgpool_layer(avgpool_layer *l, int w, int h)
34 | {
35 | l->w = w;
36 | l->h = h;
37 | l->inputs = h*w*l->c;
38 | }
39 |
40 | void forward_avgpool_layer(const avgpool_layer l, network net)
41 | {
42 | int b,i,k;
43 |
44 | for(b = 0; b < l.batch; ++b){
45 | for(k = 0; k < l.c; ++k){
46 | int out_index = k + b*l.c;
47 | l.output[out_index] = 0;
48 | for(i = 0; i < l.h*l.w; ++i){
49 | int in_index = i + l.h*l.w*(k + b*l.c);
50 | l.output[out_index] += net.input[in_index];
51 | }
52 | l.output[out_index] /= l.h*l.w;
53 | }
54 | }
55 | }
56 |
57 | void backward_avgpool_layer(const avgpool_layer l, network net)
58 | {
59 | int b,i,k;
60 |
61 | for(b = 0; b < l.batch; ++b){
62 | for(k = 0; k < l.c; ++k){
63 | int out_index = k + b*l.c;
64 | for(i = 0; i < l.h*l.w; ++i){
65 | int in_index = i + l.h*l.w*(k + b*l.c);
66 | net.delta[in_index] += l.delta[out_index] / (l.h*l.w);
67 | }
68 | }
69 | }
70 | }
71 |
72 |
--------------------------------------------------------------------------------
/test/darknet/src/avgpool_layer.h:
--------------------------------------------------------------------------------
1 | #ifndef AVGPOOL_LAYER_H
2 | #define AVGPOOL_LAYER_H
3 |
4 | #include "image.h"
5 | #include "cuda.h"
6 | #include "layer.h"
7 | #include "network.h"
8 |
9 | typedef layer avgpool_layer;
10 |
11 | image get_avgpool_image(avgpool_layer l);
12 | avgpool_layer make_avgpool_layer(int batch, int w, int h, int c);
13 | void resize_avgpool_layer(avgpool_layer *l, int w, int h);
14 | void forward_avgpool_layer(const avgpool_layer l, network net);
15 | void backward_avgpool_layer(const avgpool_layer l, network net);
16 |
17 | #ifdef GPU
18 | void forward_avgpool_layer_gpu(avgpool_layer l, network net);
19 | void backward_avgpool_layer_gpu(avgpool_layer l, network net);
20 | #endif
21 |
22 | #endif
23 |
24 |
--------------------------------------------------------------------------------
/test/darknet/src/avgpool_layer_kernels.cu:
--------------------------------------------------------------------------------
1 | #include "cuda_runtime.h"
2 | #include "curand.h"
3 | #include "cublas_v2.h"
4 |
5 | extern "C" {
6 | #include "avgpool_layer.h"
7 | #include "cuda.h"
8 | }
9 |
10 | __global__ void forward_avgpool_layer_kernel(int n, int w, int h, int c, float *input, float *output)
11 | {
12 | int id = (blockIdx.x + blockIdx.y*gridDim.x) * blockDim.x + threadIdx.x;
13 | if(id >= n) return;
14 |
15 | int k = id % c;
16 | id /= c;
17 | int b = id;
18 |
19 | int i;
20 | int out_index = (k + c*b);
21 | output[out_index] = 0;
22 | for(i = 0; i < w*h; ++i){
23 | int in_index = i + h*w*(k + b*c);
24 | output[out_index] += input[in_index];
25 | }
26 | output[out_index] /= w*h;
27 | }
28 |
29 | __global__ void backward_avgpool_layer_kernel(int n, int w, int h, int c, float *in_delta, float *out_delta)
30 | {
31 | int id = (blockIdx.x + blockIdx.y*gridDim.x) * blockDim.x + threadIdx.x;
32 | if(id >= n) return;
33 |
34 | int k = id % c;
35 | id /= c;
36 | int b = id;
37 |
38 | int i;
39 | int out_index = (k + c*b);
40 | for(i = 0; i < w*h; ++i){
41 | int in_index = i + h*w*(k + b*c);
42 | in_delta[in_index] += out_delta[out_index] / (w*h);
43 | }
44 | }
45 |
46 | extern "C" void forward_avgpool_layer_gpu(avgpool_layer layer, network net)
47 | {
48 | size_t n = layer.c*layer.batch;
49 |
50 | forward_avgpool_layer_kernel<<>>(n, layer.w, layer.h, layer.c, net.input_gpu, layer.output_gpu);
51 | check_error(cudaPeekAtLastError());
52 | }
53 |
54 | extern "C" void backward_avgpool_layer_gpu(avgpool_layer layer, network net)
55 | {
56 | size_t n = layer.c*layer.batch;
57 |
58 | backward_avgpool_layer_kernel<<>>(n, layer.w, layer.h, layer.c, net.delta_gpu, layer.delta_gpu);
59 | check_error(cudaPeekAtLastError());
60 | }
61 |
62 |
--------------------------------------------------------------------------------
/test/darknet/src/batchnorm_layer.h:
--------------------------------------------------------------------------------
1 | #ifndef BATCHNORM_LAYER_H
2 | #define BATCHNORM_LAYER_H
3 |
4 | #include "image.h"
5 | #include "layer.h"
6 | #include "network.h"
7 |
8 | layer make_batchnorm_layer(int batch, int w, int h, int c);
9 | void forward_batchnorm_layer(layer l, network net);
10 | void backward_batchnorm_layer(layer l, network net);
11 |
12 | #ifdef GPU
13 | void forward_batchnorm_layer_gpu(layer l, network net);
14 | void backward_batchnorm_layer_gpu(layer l, network net);
15 | void pull_batchnorm_layer(layer l);
16 | void push_batchnorm_layer(layer l);
17 | #endif
18 |
19 | #endif
20 |
--------------------------------------------------------------------------------
/test/darknet/src/box.h:
--------------------------------------------------------------------------------
1 | #ifndef BOX_H
2 | #define BOX_H
3 | #include "darknet.h"
4 |
5 | typedef struct{
6 | float dx, dy, dw, dh;
7 | } dbox;
8 |
9 | float box_rmse(box a, box b);
10 | dbox diou(box a, box b);
11 | box decode_box(box b, box anchor);
12 | box encode_box(box b, box anchor);
13 |
14 | #endif
15 |
--------------------------------------------------------------------------------
/test/darknet/src/classifier.h:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/test/darknet/src/col2im.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | void col2im_add_pixel(float *im, int height, int width, int channels,
4 | int row, int col, int channel, int pad, float val)
5 | {
6 | row -= pad;
7 | col -= pad;
8 |
9 | if (row < 0 || col < 0 ||
10 | row >= height || col >= width) return;
11 | im[col + width*(row + height*channel)] += val;
12 | }
13 | //This one might be too, can't remember.
14 | void col2im_cpu(float* data_col,
15 | int channels, int height, int width,
16 | int ksize, int stride, int pad, float* data_im)
17 | {
18 | int c,h,w;
19 | int height_col = (height + 2*pad - ksize) / stride + 1;
20 | int width_col = (width + 2*pad - ksize) / stride + 1;
21 |
22 | int channels_col = channels * ksize * ksize;
23 | for (c = 0; c < channels_col; ++c) {
24 | int w_offset = c % ksize;
25 | int h_offset = (c / ksize) % ksize;
26 | int c_im = c / ksize / ksize;
27 | for (h = 0; h < height_col; ++h) {
28 | for (w = 0; w < width_col; ++w) {
29 | int im_row = h_offset + h * stride;
30 | int im_col = w_offset + w * stride;
31 | int col_index = (c * height_col + h) * width_col + w;
32 | double val = data_col[col_index];
33 | col2im_add_pixel(data_im, height, width, channels,
34 | im_row, im_col, c_im, pad, val);
35 | }
36 | }
37 | }
38 | }
39 |
40 |
--------------------------------------------------------------------------------
/test/darknet/src/col2im.h:
--------------------------------------------------------------------------------
1 | #ifndef COL2IM_H
2 | #define COL2IM_H
3 |
4 | void col2im_cpu(float* data_col,
5 | int channels, int height, int width,
6 | int ksize, int stride, int pad, float* data_im);
7 |
8 | #ifdef GPU
9 | void col2im_gpu(float *data_col,
10 | int channels, int height, int width,
11 | int ksize, int stride, int pad, float *data_im);
12 | #endif
13 | #endif
14 |
--------------------------------------------------------------------------------
/test/darknet/src/col2im_kernels.cu:
--------------------------------------------------------------------------------
1 | #include "cuda_runtime.h"
2 | #include "curand.h"
3 | #include "cublas_v2.h"
4 |
5 | extern "C" {
6 | #include "col2im.h"
7 | #include "cuda.h"
8 | }
9 |
10 | // src: https://github.com/BVLC/caffe/blob/master/src/caffe/util/im2col.cu
11 | // You may also want to read: https://github.com/BVLC/caffe/blob/master/LICENSE
12 |
13 | __global__ void col2im_gpu_kernel(const int n, const float* data_col,
14 | const int height, const int width, const int ksize,
15 | const int pad,
16 | const int stride,
17 | const int height_col, const int width_col,
18 | float *data_im) {
19 | int index = blockIdx.x*blockDim.x+threadIdx.x;
20 | for(; index < n; index += blockDim.x*gridDim.x){
21 | float val = 0;
22 | int w = index % width + pad;
23 | int h = (index / width) % height + pad;
24 | int c = index / (width * height);
25 | // compute the start and end of the output
26 | int w_col_start = (w < ksize) ? 0 : (w - ksize) / stride + 1;
27 | int w_col_end = min(w / stride + 1, width_col);
28 | int h_col_start = (h < ksize) ? 0 : (h - ksize) / stride + 1;
29 | int h_col_end = min(h / stride + 1, height_col);
30 | // equivalent implementation
31 | int offset =
32 | (c * ksize * ksize + h * ksize + w) * height_col * width_col;
33 | int coeff_h_col = (1 - stride * ksize * height_col) * width_col;
34 | int coeff_w_col = (1 - stride * height_col * width_col);
35 | for (int h_col = h_col_start; h_col < h_col_end; ++h_col) {
36 | for (int w_col = w_col_start; w_col < w_col_end; ++w_col) {
37 | val += data_col[offset + h_col * coeff_h_col + w_col * coeff_w_col];
38 | }
39 | }
40 | data_im[index] += val;
41 | }
42 | }
43 |
44 | void col2im_gpu(float *data_col,
45 | int channels, int height, int width,
46 | int ksize, int stride, int pad, float *data_im){
47 | // We are going to launch channels * height_col * width_col kernels, each
48 | // kernel responsible for copying a single-channel grid.
49 | int height_col = (height + 2 * pad - ksize) / stride + 1;
50 | int width_col = (width + 2 * pad - ksize) / stride + 1;
51 | int num_kernels = channels * height * width;
52 | col2im_gpu_kernel<<<(num_kernels+BLOCK-1)/BLOCK,
53 | BLOCK>>>(
54 | num_kernels, data_col, height, width, ksize, pad,
55 | stride, height_col,
56 | width_col, data_im);
57 | }
58 |
59 |
--------------------------------------------------------------------------------
/test/darknet/src/connected_layer.h:
--------------------------------------------------------------------------------
1 | #ifndef CONNECTED_LAYER_H
2 | #define CONNECTED_LAYER_H
3 |
4 | #include "activations.h"
5 | #include "layer.h"
6 | #include "network.h"
7 |
8 | layer make_connected_layer(int batch, int inputs, int outputs, ACTIVATION activation, int batch_normalize, int adam);
9 |
10 | void forward_connected_layer(layer l, network net);
11 | void backward_connected_layer(layer l, network net);
12 | void update_connected_layer(layer l, update_args a);
13 |
14 | #ifdef GPU
15 | void forward_connected_layer_gpu(layer l, network net);
16 | void backward_connected_layer_gpu(layer l, network net);
17 | void update_connected_layer_gpu(layer l, update_args a);
18 | void push_connected_layer(layer l);
19 | void pull_connected_layer(layer l);
20 | #endif
21 |
22 | #endif
23 |
24 |
--------------------------------------------------------------------------------
/test/darknet/src/convolutional_layer.h:
--------------------------------------------------------------------------------
1 | #ifndef CONVOLUTIONAL_LAYER_H
2 | #define CONVOLUTIONAL_LAYER_H
3 |
4 | #include "cuda.h"
5 | #include "image.h"
6 | #include "activations.h"
7 | #include "layer.h"
8 | #include "network.h"
9 |
10 | typedef layer convolutional_layer;
11 |
12 | #ifdef GPU
13 | void forward_convolutional_layer_gpu(convolutional_layer layer, network net);
14 | void backward_convolutional_layer_gpu(convolutional_layer layer, network net);
15 | void update_convolutional_layer_gpu(convolutional_layer layer, update_args a);
16 |
17 | void push_convolutional_layer(convolutional_layer layer);
18 | void pull_convolutional_layer(convolutional_layer layer);
19 |
20 | void add_bias_gpu(float *output, float *biases, int batch, int n, int size);
21 | void backward_bias_gpu(float *bias_updates, float *delta, int batch, int n, int size);
22 | void adam_update_gpu(float *w, float *d, float *m, float *v, float B1, float B2, float eps, float decay, float rate, int n, int batch, int t);
23 | #ifdef CUDNN
24 | void cudnn_convolutional_setup(layer *l);
25 | #endif
26 | #endif
27 |
28 | convolutional_layer make_convolutional_layer(int batch, int h, int w, int c, int n, int groups, int size, int stride, int padding, ACTIVATION activation, int batch_normalize, int binary, int xnor, int adam);
29 | void resize_convolutional_layer(convolutional_layer *layer, int w, int h);
30 | void forward_convolutional_layer(const convolutional_layer layer, network net);
31 | void update_convolutional_layer(convolutional_layer layer, update_args a);
32 | image *visualize_convolutional_layer(convolutional_layer layer, char *window, image *prev_weights);
33 | void binarize_weights(float *weights, int n, int size, float *binary);
34 | void swap_binary(convolutional_layer *l);
35 | void binarize_weights2(float *weights, int n, int size, char *binary, float *scales);
36 |
37 | void backward_convolutional_layer(convolutional_layer layer, network net);
38 |
39 | void add_bias(float *output, float *biases, int batch, int n, int size);
40 | void backward_bias(float *bias_updates, float *delta, int batch, int n, int size);
41 |
42 | image get_convolutional_image(convolutional_layer layer);
43 | image get_convolutional_delta(convolutional_layer layer);
44 | image get_convolutional_weight(convolutional_layer layer, int i);
45 |
46 | int convolutional_out_height(convolutional_layer layer);
47 | int convolutional_out_width(convolutional_layer layer);
48 |
49 | #endif
50 |
51 |
--------------------------------------------------------------------------------
/test/darknet/src/cost_layer.h:
--------------------------------------------------------------------------------
1 | #ifndef COST_LAYER_H
2 | #define COST_LAYER_H
3 | #include "layer.h"
4 | #include "network.h"
5 |
6 | typedef layer cost_layer;
7 |
8 | COST_TYPE get_cost_type(char *s);
9 | char *get_cost_string(COST_TYPE a);
10 | cost_layer make_cost_layer(int batch, int inputs, COST_TYPE type, float scale);
11 | void forward_cost_layer(const cost_layer l, network net);
12 | void backward_cost_layer(const cost_layer l, network net);
13 | void resize_cost_layer(cost_layer *l, int inputs);
14 |
15 | #ifdef GPU
16 | void forward_cost_layer_gpu(cost_layer l, network net);
17 | void backward_cost_layer_gpu(const cost_layer l, network net);
18 | #endif
19 |
20 | #endif
21 |
--------------------------------------------------------------------------------
/test/darknet/src/crnn_layer.h:
--------------------------------------------------------------------------------
1 |
2 | #ifndef CRNN_LAYER_H
3 | #define CRNN_LAYER_H
4 |
5 | #include "activations.h"
6 | #include "layer.h"
7 | #include "network.h"
8 |
9 | layer make_crnn_layer(int batch, int h, int w, int c, int hidden_filters, int output_filters, int steps, ACTIVATION activation, int batch_normalize);
10 |
11 | void forward_crnn_layer(layer l, network net);
12 | void backward_crnn_layer(layer l, network net);
13 | void update_crnn_layer(layer l, update_args a);
14 |
15 | #ifdef GPU
16 | void forward_crnn_layer_gpu(layer l, network net);
17 | void backward_crnn_layer_gpu(layer l, network net);
18 | void update_crnn_layer_gpu(layer l, update_args a);
19 | void push_crnn_layer(layer l);
20 | void pull_crnn_layer(layer l);
21 | #endif
22 |
23 | #endif
24 |
25 |
--------------------------------------------------------------------------------
/test/darknet/src/crop_layer.c:
--------------------------------------------------------------------------------
1 | #include "crop_layer.h"
2 | #include "cuda.h"
3 | #include
4 |
5 | image get_crop_image(crop_layer l)
6 | {
7 | int h = l.out_h;
8 | int w = l.out_w;
9 | int c = l.out_c;
10 | return float_to_image(w,h,c,l.output);
11 | }
12 |
13 | void backward_crop_layer(const crop_layer l, network net){}
14 | void backward_crop_layer_gpu(const crop_layer l, network net){}
15 |
16 | crop_layer make_crop_layer(int batch, int h, int w, int c, int crop_height, int crop_width, int flip, float angle, float saturation, float exposure)
17 | {
18 | fprintf(stderr, "Crop Layer: %d x %d -> %d x %d x %d image\n", h,w,crop_height,crop_width,c);
19 | crop_layer l = {0};
20 | l.type = CROP;
21 | l.batch = batch;
22 | l.h = h;
23 | l.w = w;
24 | l.c = c;
25 | l.scale = (float)crop_height / h;
26 | l.flip = flip;
27 | l.angle = angle;
28 | l.saturation = saturation;
29 | l.exposure = exposure;
30 | l.out_w = crop_width;
31 | l.out_h = crop_height;
32 | l.out_c = c;
33 | l.inputs = l.w * l.h * l.c;
34 | l.outputs = l.out_w * l.out_h * l.out_c;
35 | l.output = calloc(l.outputs*batch, sizeof(float));
36 | l.forward = forward_crop_layer;
37 | l.backward = backward_crop_layer;
38 |
39 | #ifdef GPU
40 | l.forward_gpu = forward_crop_layer_gpu;
41 | l.backward_gpu = backward_crop_layer_gpu;
42 | l.output_gpu = cuda_make_array(l.output, l.outputs*batch);
43 | l.rand_gpu = cuda_make_array(0, l.batch*8);
44 | #endif
45 | return l;
46 | }
47 |
48 | void resize_crop_layer(layer *l, int w, int h)
49 | {
50 | l->w = w;
51 | l->h = h;
52 |
53 | l->out_w = l->scale*w;
54 | l->out_h = l->scale*h;
55 |
56 | l->inputs = l->w * l->h * l->c;
57 | l->outputs = l->out_h * l->out_w * l->out_c;
58 |
59 | l->output = realloc(l->output, l->batch*l->outputs*sizeof(float));
60 | #ifdef GPU
61 | cuda_free(l->output_gpu);
62 | l->output_gpu = cuda_make_array(l->output, l->outputs*l->batch);
63 | #endif
64 | }
65 |
66 |
67 | void forward_crop_layer(const crop_layer l, network net)
68 | {
69 | int i,j,c,b,row,col;
70 | int index;
71 | int count = 0;
72 | int flip = (l.flip && rand()%2);
73 | int dh = rand()%(l.h - l.out_h + 1);
74 | int dw = rand()%(l.w - l.out_w + 1);
75 | float scale = 2;
76 | float trans = -1;
77 | if(l.noadjust){
78 | scale = 1;
79 | trans = 0;
80 | }
81 | if(!net.train){
82 | flip = 0;
83 | dh = (l.h - l.out_h)/2;
84 | dw = (l.w - l.out_w)/2;
85 | }
86 | for(b = 0; b < l.batch; ++b){
87 | for(c = 0; c < l.c; ++c){
88 | for(i = 0; i < l.out_h; ++i){
89 | for(j = 0; j < l.out_w; ++j){
90 | if(flip){
91 | col = l.w - dw - j - 1;
92 | }else{
93 | col = j + dw;
94 | }
95 | row = i + dh;
96 | index = col+l.w*(row+l.h*(c + l.c*b));
97 | l.output[count++] = net.input[index]*scale + trans;
98 | }
99 | }
100 | }
101 | }
102 | }
103 |
104 |
--------------------------------------------------------------------------------
/test/darknet/src/crop_layer.h:
--------------------------------------------------------------------------------
1 | #ifndef CROP_LAYER_H
2 | #define CROP_LAYER_H
3 |
4 | #include "image.h"
5 | #include "layer.h"
6 | #include "network.h"
7 |
8 | typedef layer crop_layer;
9 |
10 | image get_crop_image(crop_layer l);
11 | crop_layer make_crop_layer(int batch, int h, int w, int c, int crop_height, int crop_width, int flip, float angle, float saturation, float exposure);
12 | void forward_crop_layer(const crop_layer l, network net);
13 | void resize_crop_layer(layer *l, int w, int h);
14 |
15 | #ifdef GPU
16 | void forward_crop_layer_gpu(crop_layer l, network net);
17 | #endif
18 |
19 | #endif
20 |
21 |
--------------------------------------------------------------------------------
/test/darknet/src/cuda.c:
--------------------------------------------------------------------------------
1 | int gpu_index = 0;
2 |
3 | #ifdef GPU
4 |
5 | #include "cuda.h"
6 | #include "utils.h"
7 | #include "blas.h"
8 | #include
9 | #include
10 | #include
11 |
12 | void cuda_set_device(int n)
13 | {
14 | gpu_index = n;
15 | cudaError_t status = cudaSetDevice(n);
16 | check_error(status);
17 | }
18 |
19 | int cuda_get_device()
20 | {
21 | int n = 0;
22 | cudaError_t status = cudaGetDevice(&n);
23 | check_error(status);
24 | return n;
25 | }
26 |
27 | void check_error(cudaError_t status)
28 | {
29 | //cudaDeviceSynchronize();
30 | cudaError_t status2 = cudaGetLastError();
31 | if (status != cudaSuccess)
32 | {
33 | const char *s = cudaGetErrorString(status);
34 | char buffer[256];
35 | printf("CUDA Error: %s\n", s);
36 | assert(0);
37 | snprintf(buffer, 256, "CUDA Error: %s", s);
38 | error(buffer);
39 | }
40 | if (status2 != cudaSuccess)
41 | {
42 | const char *s = cudaGetErrorString(status);
43 | char buffer[256];
44 | printf("CUDA Error Prev: %s\n", s);
45 | assert(0);
46 | snprintf(buffer, 256, "CUDA Error Prev: %s", s);
47 | error(buffer);
48 | }
49 | }
50 |
51 | dim3 cuda_gridsize(size_t n){
52 | size_t k = (n-1) / BLOCK + 1;
53 | size_t x = k;
54 | size_t y = 1;
55 | if(x > 65535){
56 | x = ceil(sqrt(k));
57 | y = (n-1)/(x*BLOCK) + 1;
58 | }
59 | dim3 d = {x, y, 1};
60 | //printf("%ld %ld %ld %ld\n", n, x, y, x*y*BLOCK);
61 | return d;
62 | }
63 |
64 | #ifdef CUDNN
65 | cudnnHandle_t cudnn_handle()
66 | {
67 | static int init[16] = {0};
68 | static cudnnHandle_t handle[16];
69 | int i = cuda_get_device();
70 | if(!init[i]) {
71 | cudnnCreate(&handle[i]);
72 | init[i] = 1;
73 | }
74 | return handle[i];
75 | }
76 | #endif
77 |
78 | cublasHandle_t blas_handle()
79 | {
80 | static int init[16] = {0};
81 | static cublasHandle_t handle[16];
82 | int i = cuda_get_device();
83 | if(!init[i]) {
84 | cublasCreate(&handle[i]);
85 | init[i] = 1;
86 | }
87 | return handle[i];
88 | }
89 |
90 | float *cuda_make_array(float *x, size_t n)
91 | {
92 | float *x_gpu;
93 | size_t size = sizeof(float)*n;
94 | cudaError_t status = cudaMalloc((void **)&x_gpu, size);
95 | check_error(status);
96 | if(x){
97 | status = cudaMemcpy(x_gpu, x, size, cudaMemcpyHostToDevice);
98 | check_error(status);
99 | } else {
100 | fill_gpu(n, 0, x_gpu, 1);
101 | }
102 | if(!x_gpu) error("Cuda malloc failed\n");
103 | return x_gpu;
104 | }
105 |
106 | void cuda_random(float *x_gpu, size_t n)
107 | {
108 | static curandGenerator_t gen[16];
109 | static int init[16] = {0};
110 | int i = cuda_get_device();
111 | if(!init[i]){
112 | curandCreateGenerator(&gen[i], CURAND_RNG_PSEUDO_DEFAULT);
113 | curandSetPseudoRandomGeneratorSeed(gen[i], time(0));
114 | init[i] = 1;
115 | }
116 | curandGenerateUniform(gen[i], x_gpu, n);
117 | check_error(cudaPeekAtLastError());
118 | }
119 |
120 | float cuda_compare(float *x_gpu, float *x, size_t n, char *s)
121 | {
122 | float *tmp = calloc(n, sizeof(float));
123 | cuda_pull_array(x_gpu, tmp, n);
124 | //int i;
125 | //for(i = 0; i < n; ++i) printf("%f %f\n", tmp[i], x[i]);
126 | axpy_cpu(n, -1, x, 1, tmp, 1);
127 | float err = dot_cpu(n, tmp, 1, tmp, 1);
128 | printf("Error %s: %f\n", s, sqrt(err/n));
129 | free(tmp);
130 | return err;
131 | }
132 |
133 | int *cuda_make_int_array(int *x, size_t n)
134 | {
135 | int *x_gpu;
136 | size_t size = sizeof(int)*n;
137 | cudaError_t status = cudaMalloc((void **)&x_gpu, size);
138 | check_error(status);
139 | if(x){
140 | status = cudaMemcpy(x_gpu, x, size, cudaMemcpyHostToDevice);
141 | check_error(status);
142 | }
143 | if(!x_gpu) error("Cuda malloc failed\n");
144 | return x_gpu;
145 | }
146 |
147 | void cuda_free(float *x_gpu)
148 | {
149 | cudaError_t status = cudaFree(x_gpu);
150 | check_error(status);
151 | }
152 |
153 | void cuda_push_array(float *x_gpu, float *x, size_t n)
154 | {
155 | size_t size = sizeof(float)*n;
156 | cudaError_t status = cudaMemcpy(x_gpu, x, size, cudaMemcpyHostToDevice);
157 | check_error(status);
158 | }
159 |
160 | void cuda_pull_array(float *x_gpu, float *x, size_t n)
161 | {
162 | size_t size = sizeof(float)*n;
163 | cudaError_t status = cudaMemcpy(x, x_gpu, size, cudaMemcpyDeviceToHost);
164 | check_error(status);
165 | }
166 |
167 | float cuda_mag_array(float *x_gpu, size_t n)
168 | {
169 | float *temp = calloc(n, sizeof(float));
170 | cuda_pull_array(x_gpu, temp, n);
171 | float m = mag_array(temp, n);
172 | free(temp);
173 | return m;
174 | }
175 | #else
176 | void cuda_set_device(int n){}
177 |
178 | #endif
179 |
--------------------------------------------------------------------------------
/test/darknet/src/cuda.h:
--------------------------------------------------------------------------------
1 | #ifndef CUDA_H
2 | #define CUDA_H
3 |
4 | #include "darknet.h"
5 |
6 | #ifdef GPU
7 |
8 | void check_error(cudaError_t status);
9 | cublasHandle_t blas_handle();
10 | int *cuda_make_int_array(int *x, size_t n);
11 | void cuda_random(float *x_gpu, size_t n);
12 | float cuda_compare(float *x_gpu, float *x, size_t n, char *s);
13 | dim3 cuda_gridsize(size_t n);
14 |
15 | #ifdef CUDNN
16 | cudnnHandle_t cudnn_handle();
17 | #endif
18 |
19 | #endif
20 | #endif
21 |
--------------------------------------------------------------------------------
/test/darknet/src/data.h:
--------------------------------------------------------------------------------
1 | #ifndef DATA_H
2 | #define DATA_H
3 | #include
4 |
5 | #include "darknet.h"
6 | #include "matrix.h"
7 | #include "list.h"
8 | #include "image.h"
9 | #include "tree.h"
10 |
11 | static inline float distance_from_edge(int x, int max)
12 | {
13 | int dx = (max/2) - x;
14 | if (dx < 0) dx = -dx;
15 | dx = (max/2) + 1 - dx;
16 | dx *= 2;
17 | float dist = (float)dx/max;
18 | if (dist > 1) dist = 1;
19 | return dist;
20 | }
21 | void load_data_blocking(load_args args);
22 |
23 |
24 | void print_letters(float *pred, int n);
25 | data load_data_captcha(char **paths, int n, int m, int k, int w, int h);
26 | data load_data_captcha_encode(char **paths, int n, int m, int w, int h);
27 | data load_data_detection(int n, char **paths, int m, int w, int h, int boxes, int classes, float jitter, float hue, float saturation, float exposure);
28 | data load_data_tag(char **paths, int n, int m, int k, int min, int max, int size, float angle, float aspect, float hue, float saturation, float exposure);
29 | matrix load_image_augment_paths(char **paths, int n, int min, int max, int size, float angle, float aspect, float hue, float saturation, float exposure, int center);
30 | data load_data_super(char **paths, int n, int m, int w, int h, int scale);
31 | data load_data_augment(char **paths, int n, int m, char **labels, int k, tree *hierarchy, int min, int max, int size, float angle, float aspect, float hue, float saturation, float exposure, int center);
32 | data load_data_regression(char **paths, int n, int m, int classes, int min, int max, int size, float angle, float aspect, float hue, float saturation, float exposure);
33 | data load_go(char *filename);
34 |
35 |
36 | data load_data_writing(char **paths, int n, int m, int w, int h, int out_w, int out_h);
37 |
38 | void get_random_batch(data d, int n, float *X, float *y);
39 | data get_data_part(data d, int part, int total);
40 | data get_random_data(data d, int num);
41 | data load_categorical_data_csv(char *filename, int target, int k);
42 | void normalize_data_rows(data d);
43 | void scale_data_rows(data d, float s);
44 | void translate_data_rows(data d, float s);
45 | void randomize_data(data d);
46 | data *split_data(data d, int part, int total);
47 | data concat_datas(data *d, int n);
48 | void fill_truth(char *path, char **labels, int k, float *truth);
49 |
50 | #endif
51 |
--------------------------------------------------------------------------------
/test/darknet/src/deconvolutional_kernels.cu:
--------------------------------------------------------------------------------
1 | #include "cuda_runtime.h"
2 | #include "curand.h"
3 | #include "cublas_v2.h"
4 |
5 | extern "C" {
6 | #include "convolutional_layer.h"
7 | #include "deconvolutional_layer.h"
8 | #include "batchnorm_layer.h"
9 | #include "gemm.h"
10 | #include "blas.h"
11 | #include "im2col.h"
12 | #include "col2im.h"
13 | #include "utils.h"
14 | #include "cuda.h"
15 | }
16 |
17 | extern "C" void forward_deconvolutional_layer_gpu(layer l, network net)
18 | {
19 | int i;
20 |
21 | int m = l.size*l.size*l.n;
22 | int n = l.h*l.w;
23 | int k = l.c;
24 |
25 | fill_gpu(l.outputs*l.batch, 0, l.output_gpu, 1);
26 |
27 | for(i = 0; i < l.batch; ++i){
28 | float *a = l.weights_gpu;
29 | float *b = net.input_gpu + i*l.c*l.h*l.w;
30 | float *c = net.workspace;
31 |
32 | gemm_gpu(1,0,m,n,k,1,a,m,b,n,0,c,n);
33 |
34 | col2im_gpu(net.workspace, l.out_c, l.out_h, l.out_w, l.size, l.stride, l.pad, l.output_gpu+i*l.outputs);
35 | }
36 | if (l.batch_normalize) {
37 | forward_batchnorm_layer_gpu(l, net);
38 | } else {
39 | add_bias_gpu(l.output_gpu, l.biases_gpu, l.batch, l.n, l.out_w*l.out_h);
40 | }
41 | activate_array_gpu(l.output_gpu, l.batch*l.n*l.out_w*l.out_h, l.activation);
42 | }
43 |
44 | extern "C" void backward_deconvolutional_layer_gpu(layer l, network net)
45 | {
46 | int i;
47 |
48 | //constrain_gpu(l.outputs*l.batch, 1, l.delta_gpu, 1);
49 | gradient_array_gpu(l.output_gpu, l.outputs*l.batch, l.activation, l.delta_gpu);
50 |
51 | if(l.batch_normalize){
52 | backward_batchnorm_layer_gpu(l, net);
53 | } else {
54 | backward_bias_gpu(l.bias_updates_gpu, l.delta_gpu, l.batch, l.n, l.out_w*l.out_h);
55 | }
56 |
57 | //if(net.delta_gpu) memset(net.delta_gpu, 0, l.batch*l.h*l.w*l.c*sizeof(float));
58 |
59 | for(i = 0; i < l.batch; ++i){
60 | int m = l.c;
61 | int n = l.size*l.size*l.n;
62 | int k = l.h*l.w;
63 |
64 | float *a = net.input_gpu + i*m*k;
65 | float *b = net.workspace;
66 | float *c = l.weight_updates_gpu;
67 |
68 | im2col_gpu(l.delta_gpu + i*l.outputs, l.out_c, l.out_h, l.out_w,
69 | l.size, l.stride, l.pad, b);
70 | gemm_gpu(0,1,m,n,k,1,a,k,b,k,1,c,n);
71 |
72 | if(net.delta_gpu){
73 | int m = l.c;
74 | int n = l.h*l.w;
75 | int k = l.size*l.size*l.n;
76 |
77 | float *a = l.weights_gpu;
78 | float *b = net.workspace;
79 | float *c = net.delta_gpu + i*n*m;
80 |
81 | gemm_gpu(0,0,m,n,k,1,a,k,b,n,1,c,n);
82 | }
83 | }
84 | }
85 |
86 | extern "C" void pull_deconvolutional_layer(layer l)
87 | {
88 | cuda_pull_array(l.weights_gpu, l.weights, l.c*l.n*l.size*l.size);
89 | cuda_pull_array(l.biases_gpu, l.biases, l.n);
90 | cuda_pull_array(l.weight_updates_gpu, l.weight_updates, l.c*l.n*l.size*l.size);
91 | cuda_pull_array(l.bias_updates_gpu, l.bias_updates, l.n);
92 | if (l.batch_normalize){
93 | cuda_pull_array(l.scales_gpu, l.scales, l.n);
94 | cuda_pull_array(l.rolling_mean_gpu, l.rolling_mean, l.n);
95 | cuda_pull_array(l.rolling_variance_gpu, l.rolling_variance, l.n);
96 | }
97 | }
98 |
99 | extern "C" void push_deconvolutional_layer(layer l)
100 | {
101 | cuda_push_array(l.weights_gpu, l.weights, l.c*l.n*l.size*l.size);
102 | cuda_push_array(l.biases_gpu, l.biases, l.n);
103 | cuda_push_array(l.weight_updates_gpu, l.weight_updates, l.c*l.n*l.size*l.size);
104 | cuda_push_array(l.bias_updates_gpu, l.bias_updates, l.n);
105 | if (l.batch_normalize){
106 | cuda_push_array(l.scales_gpu, l.scales, l.n);
107 | cuda_push_array(l.rolling_mean_gpu, l.rolling_mean, l.n);
108 | cuda_push_array(l.rolling_variance_gpu, l.rolling_variance, l.n);
109 | }
110 | }
111 |
112 | void update_deconvolutional_layer_gpu(layer l, update_args a)
113 | {
114 | float learning_rate = a.learning_rate*l.learning_rate_scale;
115 | float momentum = a.momentum;
116 | float decay = a.decay;
117 | int batch = a.batch;
118 |
119 | if(a.adam){
120 | adam_update_gpu(l.weights_gpu, l.weight_updates_gpu, l.m_gpu, l.v_gpu, a.B1, a.B2, a.eps, decay, learning_rate, l.nweights, batch, a.t);
121 | adam_update_gpu(l.biases_gpu, l.bias_updates_gpu, l.bias_m_gpu, l.bias_v_gpu, a.B1, a.B2, a.eps, decay, learning_rate, l.n, batch, a.t);
122 | if(l.scales_gpu){
123 | adam_update_gpu(l.scales_gpu, l.scale_updates_gpu, l.scale_m_gpu, l.scale_v_gpu, a.B1, a.B2, a.eps, decay, learning_rate, l.n, batch, a.t);
124 | }
125 | }else{
126 | axpy_gpu(l.nweights, -decay*batch, l.weights_gpu, 1, l.weight_updates_gpu, 1);
127 | axpy_gpu(l.nweights, learning_rate/batch, l.weight_updates_gpu, 1, l.weights_gpu, 1);
128 | scal_gpu(l.nweights, momentum, l.weight_updates_gpu, 1);
129 |
130 | axpy_gpu(l.n, learning_rate/batch, l.bias_updates_gpu, 1, l.biases_gpu, 1);
131 | scal_gpu(l.n, momentum, l.bias_updates_gpu, 1);
132 |
133 | if(l.scales_gpu){
134 | axpy_gpu(l.n, learning_rate/batch, l.scale_updates_gpu, 1, l.scales_gpu, 1);
135 | scal_gpu(l.n, momentum, l.scale_updates_gpu, 1);
136 | }
137 | }
138 | }
139 |
140 |
--------------------------------------------------------------------------------
/test/darknet/src/deconvolutional_layer.h:
--------------------------------------------------------------------------------
1 | #ifndef DECONVOLUTIONAL_LAYER_H
2 | #define DECONVOLUTIONAL_LAYER_H
3 |
4 | #include "cuda.h"
5 | #include "image.h"
6 | #include "activations.h"
7 | #include "layer.h"
8 | #include "network.h"
9 |
10 | #ifdef GPU
11 | void forward_deconvolutional_layer_gpu(layer l, network net);
12 | void backward_deconvolutional_layer_gpu(layer l, network net);
13 | void update_deconvolutional_layer_gpu(layer l, update_args a);
14 | void push_deconvolutional_layer(layer l);
15 | void pull_deconvolutional_layer(layer l);
16 | #endif
17 |
18 | layer make_deconvolutional_layer(int batch, int h, int w, int c, int n, int size, int stride, int padding, ACTIVATION activation, int batch_normalize, int adam);
19 | void resize_deconvolutional_layer(layer *l, int h, int w);
20 | void forward_deconvolutional_layer(const layer l, network net);
21 | void update_deconvolutional_layer(layer l, update_args a);
22 | void backward_deconvolutional_layer(layer l, network net);
23 |
24 | #endif
25 |
26 |
--------------------------------------------------------------------------------
/test/darknet/src/demo.h:
--------------------------------------------------------------------------------
1 | #ifndef DEMO_H
2 | #define DEMO_H
3 |
4 | #include "image.h"
5 |
6 | #endif
7 |
--------------------------------------------------------------------------------
/test/darknet/src/detection_layer.h:
--------------------------------------------------------------------------------
1 | #ifndef DETECTION_LAYER_H
2 | #define DETECTION_LAYER_H
3 |
4 | #include "layer.h"
5 | #include "network.h"
6 |
7 | typedef layer detection_layer;
8 |
9 | detection_layer make_detection_layer(int batch, int inputs, int n, int size, int classes, int coords, int rescore);
10 | void forward_detection_layer(const detection_layer l, network net);
11 | void backward_detection_layer(const detection_layer l, network net);
12 |
13 | #ifdef GPU
14 | void forward_detection_layer_gpu(const detection_layer l, network net);
15 | void backward_detection_layer_gpu(detection_layer l, network net);
16 | #endif
17 |
18 | #endif
19 |
--------------------------------------------------------------------------------
/test/darknet/src/dropout_layer.c:
--------------------------------------------------------------------------------
1 | #include "dropout_layer.h"
2 | #include "utils.h"
3 | #include "cuda.h"
4 | #include
5 | #include
6 |
7 | dropout_layer make_dropout_layer(int batch, int inputs, float probability)
8 | {
9 | dropout_layer l = {0};
10 | l.type = DROPOUT;
11 | l.probability = probability;
12 | l.inputs = inputs;
13 | l.outputs = inputs;
14 | l.batch = batch;
15 | l.rand = calloc(inputs*batch, sizeof(float));
16 | l.scale = 1./(1.-probability);
17 | l.forward = forward_dropout_layer;
18 | l.backward = backward_dropout_layer;
19 | #ifdef GPU
20 | l.forward_gpu = forward_dropout_layer_gpu;
21 | l.backward_gpu = backward_dropout_layer_gpu;
22 | l.rand_gpu = cuda_make_array(l.rand, inputs*batch);
23 | #endif
24 | fprintf(stderr, "dropout p = %.2f %4d -> %4d\n", probability, inputs, inputs);
25 | return l;
26 | }
27 |
28 | void resize_dropout_layer(dropout_layer *l, int inputs)
29 | {
30 | l->rand = realloc(l->rand, l->inputs*l->batch*sizeof(float));
31 | #ifdef GPU
32 | cuda_free(l->rand_gpu);
33 |
34 | l->rand_gpu = cuda_make_array(l->rand, inputs*l->batch);
35 | #endif
36 | }
37 |
38 | void forward_dropout_layer(dropout_layer l, network net)
39 | {
40 | int i;
41 | if (!net.train) return;
42 | for(i = 0; i < l.batch * l.inputs; ++i){
43 | float r = rand_uniform(0, 1);
44 | l.rand[i] = r;
45 | if(r < l.probability) net.input[i] = 0;
46 | else net.input[i] *= l.scale;
47 | }
48 | }
49 |
50 | void backward_dropout_layer(dropout_layer l, network net)
51 | {
52 | int i;
53 | if(!net.delta) return;
54 | for(i = 0; i < l.batch * l.inputs; ++i){
55 | float r = l.rand[i];
56 | if(r < l.probability) net.delta[i] = 0;
57 | else net.delta[i] *= l.scale;
58 | }
59 | }
60 |
61 |
--------------------------------------------------------------------------------
/test/darknet/src/dropout_layer.h:
--------------------------------------------------------------------------------
1 | #ifndef DROPOUT_LAYER_H
2 | #define DROPOUT_LAYER_H
3 |
4 | #include "layer.h"
5 | #include "network.h"
6 |
7 | typedef layer dropout_layer;
8 |
9 | dropout_layer make_dropout_layer(int batch, int inputs, float probability);
10 |
11 | void forward_dropout_layer(dropout_layer l, network net);
12 | void backward_dropout_layer(dropout_layer l, network net);
13 | void resize_dropout_layer(dropout_layer *l, int inputs);
14 |
15 | #ifdef GPU
16 | void forward_dropout_layer_gpu(dropout_layer l, network net);
17 | void backward_dropout_layer_gpu(dropout_layer l, network net);
18 |
19 | #endif
20 | #endif
21 |
--------------------------------------------------------------------------------
/test/darknet/src/dropout_layer_kernels.cu:
--------------------------------------------------------------------------------
1 | #include "cuda_runtime.h"
2 | #include "curand.h"
3 | #include "cublas_v2.h"
4 |
5 | extern "C" {
6 | #include "dropout_layer.h"
7 | #include "cuda.h"
8 | #include "utils.h"
9 | }
10 |
11 | __global__ void yoloswag420blazeit360noscope(float *input, int size, float *rand, float prob, float scale)
12 | {
13 | int id = (blockIdx.x + blockIdx.y*gridDim.x) * blockDim.x + threadIdx.x;
14 | if(id < size) input[id] = (rand[id] < prob) ? 0 : input[id]*scale;
15 | }
16 |
17 | void forward_dropout_layer_gpu(dropout_layer layer, network net)
18 | {
19 | if (!net.train) return;
20 | int size = layer.inputs*layer.batch;
21 | cuda_random(layer.rand_gpu, size);
22 | /*
23 | int i;
24 | for(i = 0; i < size; ++i){
25 | layer.rand[i] = rand_uniform();
26 | }
27 | cuda_push_array(layer.rand_gpu, layer.rand, size);
28 | */
29 |
30 | yoloswag420blazeit360noscope<<>>(net.input_gpu, size, layer.rand_gpu, layer.probability, layer.scale);
31 | check_error(cudaPeekAtLastError());
32 | }
33 |
34 | void backward_dropout_layer_gpu(dropout_layer layer, network net)
35 | {
36 | if(!net.delta_gpu) return;
37 | int size = layer.inputs*layer.batch;
38 |
39 | yoloswag420blazeit360noscope<<>>(net.delta_gpu, size, layer.rand_gpu, layer.probability, layer.scale);
40 | check_error(cudaPeekAtLastError());
41 | }
42 |
--------------------------------------------------------------------------------
/test/darknet/src/gemm.h:
--------------------------------------------------------------------------------
1 | #ifndef GEMM_H
2 | #define GEMM_H
3 |
4 | void gemm_bin(int M, int N, int K, float ALPHA,
5 | char *A, int lda,
6 | float *B, int ldb,
7 | float *C, int ldc);
8 |
9 | void gemm(int TA, int TB, int M, int N, int K, float ALPHA,
10 | float *A, int lda,
11 | float *B, int ldb,
12 | float BETA,
13 | float *C, int ldc);
14 |
15 | void gemm_cpu(int TA, int TB, int M, int N, int K, float ALPHA,
16 | float *A, int lda,
17 | float *B, int ldb,
18 | float BETA,
19 | float *C, int ldc);
20 |
21 | #ifdef GPU
22 | void gemm_gpu(int TA, int TB, int M, int N, int K, float ALPHA,
23 | float *A_gpu, int lda,
24 | float *B_gpu, int ldb,
25 | float BETA,
26 | float *C_gpu, int ldc);
27 |
28 | void gemm_gpu(int TA, int TB, int M, int N, int K, float ALPHA,
29 | float *A, int lda,
30 | float *B, int ldb,
31 | float BETA,
32 | float *C, int ldc);
33 | #endif
34 | #endif
35 |
--------------------------------------------------------------------------------
/test/darknet/src/gru_layer.h:
--------------------------------------------------------------------------------
1 |
2 | #ifndef GRU_LAYER_H
3 | #define GRU_LAYER_H
4 |
5 | #include "activations.h"
6 | #include "layer.h"
7 | #include "network.h"
8 |
9 | layer make_gru_layer(int batch, int inputs, int outputs, int steps, int batch_normalize, int adam);
10 |
11 | void forward_gru_layer(layer l, network state);
12 | void backward_gru_layer(layer l, network state);
13 | void update_gru_layer(layer l, update_args a);
14 |
15 | #ifdef GPU
16 | void forward_gru_layer_gpu(layer l, network state);
17 | void backward_gru_layer_gpu(layer l, network state);
18 | void update_gru_layer_gpu(layer l, update_args a);
19 | void push_gru_layer(layer l);
20 | void pull_gru_layer(layer l);
21 | #endif
22 |
23 | #endif
24 |
25 |
--------------------------------------------------------------------------------
/test/darknet/src/im2col.c:
--------------------------------------------------------------------------------
1 | #include "im2col.h"
2 | #include
3 | float im2col_get_pixel(float *im, int height, int width, int channels,
4 | int row, int col, int channel, int pad)
5 | {
6 | row -= pad;
7 | col -= pad;
8 |
9 | if (row < 0 || col < 0 ||
10 | row >= height || col >= width) return 0;
11 | return im[col + width*(row + height*channel)];
12 | }
13 |
14 | //From Berkeley Vision's Caffe!
15 | //https://github.com/BVLC/caffe/blob/master/LICENSE
16 | void im2col_cpu(float* data_im,
17 | int channels, int height, int width,
18 | int ksize, int stride, int pad, float* data_col)
19 | {
20 | int c,h,w;
21 | int height_col = (height + 2*pad - ksize) / stride + 1;
22 | int width_col = (width + 2*pad - ksize) / stride + 1;
23 |
24 | int channels_col = channels * ksize * ksize;
25 | for (c = 0; c < channels_col; ++c) {
26 | int w_offset = c % ksize;
27 | int h_offset = (c / ksize) % ksize;
28 | int c_im = c / ksize / ksize;
29 | for (h = 0; h < height_col; ++h) {
30 | for (w = 0; w < width_col; ++w) {
31 | int im_row = h_offset + h * stride;
32 | int im_col = w_offset + w * stride;
33 | int col_index = (c * height_col + h) * width_col + w;
34 | data_col[col_index] = im2col_get_pixel(data_im, height, width, channels,
35 | im_row, im_col, c_im, pad);
36 | }
37 | }
38 | }
39 | }
40 |
41 |
--------------------------------------------------------------------------------
/test/darknet/src/im2col.h:
--------------------------------------------------------------------------------
1 | #ifndef IM2COL_H
2 | #define IM2COL_H
3 |
4 | void im2col_cpu(float* data_im,
5 | int channels, int height, int width,
6 | int ksize, int stride, int pad, float* data_col);
7 |
8 | #ifdef GPU
9 |
10 | void im2col_gpu(float *im,
11 | int channels, int height, int width,
12 | int ksize, int stride, int pad,float *data_col);
13 |
14 | #endif
15 | #endif
16 |
--------------------------------------------------------------------------------
/test/darknet/src/im2col_kernels.cu:
--------------------------------------------------------------------------------
1 | #include "cuda_runtime.h"
2 | #include "curand.h"
3 | #include "cublas_v2.h"
4 |
5 | extern "C" {
6 | #include "im2col.h"
7 | #include "cuda.h"
8 | }
9 |
10 | // src: https://github.com/BVLC/caffe/blob/master/src/caffe/util/im2col.cu
11 | // You may also want to read: https://github.com/BVLC/caffe/blob/master/LICENSE
12 |
13 | __global__ void im2col_gpu_kernel(const int n, const float* data_im,
14 | const int height, const int width, const int ksize,
15 | const int pad,
16 | const int stride,
17 | const int height_col, const int width_col,
18 | float *data_col) {
19 | int index = blockIdx.x*blockDim.x+threadIdx.x;
20 | for(; index < n; index += blockDim.x*gridDim.x){
21 | int w_out = index % width_col;
22 | int h_index = index / width_col;
23 | int h_out = h_index % height_col;
24 | int channel_in = h_index / height_col;
25 | int channel_out = channel_in * ksize * ksize;
26 | int h_in = h_out * stride - pad;
27 | int w_in = w_out * stride - pad;
28 | float* data_col_ptr = data_col;
29 | data_col_ptr += (channel_out * height_col + h_out) * width_col + w_out;
30 | const float* data_im_ptr = data_im;
31 | data_im_ptr += (channel_in * height + h_in) * width + w_in;
32 | for (int i = 0; i < ksize; ++i) {
33 | for (int j = 0; j < ksize; ++j) {
34 | int h = h_in + i;
35 | int w = w_in + j;
36 |
37 | *data_col_ptr = (h >= 0 && w >= 0 && h < height && w < width) ?
38 | data_im_ptr[i * width + j] : 0;
39 |
40 | //*data_col_ptr = data_im_ptr[ii * width + jj];
41 |
42 | data_col_ptr += height_col * width_col;
43 | }
44 | }
45 | }
46 | }
47 |
48 | void im2col_gpu(float *im,
49 | int channels, int height, int width,
50 | int ksize, int stride, int pad, float *data_col){
51 | // We are going to launch channels * height_col * width_col kernels, each
52 | // kernel responsible for copying a single-channel grid.
53 | int height_col = (height + 2 * pad - ksize) / stride + 1;
54 | int width_col = (width + 2 * pad - ksize) / stride + 1;
55 | int num_kernels = channels * height_col * width_col;
56 | im2col_gpu_kernel<<<(num_kernels+BLOCK-1)/BLOCK,
57 | BLOCK>>>(
58 | num_kernels, im, height, width, ksize, pad,
59 | stride, height_col,
60 | width_col, data_col);
61 | }
62 |
--------------------------------------------------------------------------------
/test/darknet/src/image.h:
--------------------------------------------------------------------------------
1 | #ifndef IMAGE_H
2 | #define IMAGE_H
3 |
4 | #include
5 | #include
6 | #include
7 | #include
8 | #include
9 | #include "box.h"
10 | #include "darknet.h"
11 |
12 | #ifdef __cplusplus
13 | extern "C" {
14 | #endif
15 |
16 | #ifdef OPENCV
17 | void *open_video_stream(const char *f, int c, int w, int h, int fps);
18 | image get_image_from_stream(void *p);
19 | image load_image_cv(char *filename, int channels);
20 | int show_image_cv(image im, const char* name, int ms);
21 | #endif
22 |
23 | float get_color(int c, int x, int max);
24 | void draw_box(image a, int x1, int y1, int x2, int y2, float r, float g, float b);
25 | void draw_bbox(image a, box bbox, int w, float r, float g, float b);
26 | void write_label(image a, int r, int c, image *characters, char *string, float *rgb);
27 | image image_distance(image a, image b);
28 | void scale_image(image m, float s);
29 | image rotate_crop_image(image im, float rad, float s, int w, int h, float dx, float dy, float aspect);
30 | image random_crop_image(image im, int w, int h);
31 | image random_augment_image(image im, float angle, float aspect, int low, int high, int w, int h);
32 | augment_args random_augment_args(image im, float angle, float aspect, int low, int high, int w, int h);
33 | void letterbox_image_into(image im, int w, int h, image boxed);
34 | image resize_max(image im, int max);
35 | void translate_image(image m, float s);
36 | void embed_image(image source, image dest, int dx, int dy);
37 | void place_image(image im, int w, int h, int dx, int dy, image canvas);
38 | void saturate_image(image im, float sat);
39 | void exposure_image(image im, float sat);
40 | void distort_image(image im, float hue, float sat, float val);
41 | void saturate_exposure_image(image im, float sat, float exposure);
42 | void rgb_to_hsv(image im);
43 | void hsv_to_rgb(image im);
44 | void yuv_to_rgb(image im);
45 | void rgb_to_yuv(image im);
46 |
47 |
48 | image collapse_image_layers(image source, int border);
49 | image collapse_images_horz(image *ims, int n);
50 | image collapse_images_vert(image *ims, int n);
51 |
52 | void show_image_normalized(image im, const char *name);
53 | void show_images(image *ims, int n, char *window);
54 | void show_image_layers(image p, char *name);
55 | void show_image_collapsed(image p, char *name);
56 |
57 | void print_image(image m);
58 |
59 | image make_empty_image(int w, int h, int c);
60 | void copy_image_into(image src, image dest);
61 |
62 | image get_image_layer(image m, int l);
63 |
64 | #ifdef __cplusplus
65 | }
66 | #endif
67 |
68 | #endif
69 |
70 |
--------------------------------------------------------------------------------
/test/darknet/src/image_opencv.cpp:
--------------------------------------------------------------------------------
1 | #ifdef OPENCV
2 |
3 | #include "stdio.h"
4 | #include "stdlib.h"
5 | #include "opencv2/opencv.hpp"
6 | #include "image.h"
7 |
8 | using namespace cv;
9 |
10 | extern "C" {
11 |
12 | IplImage *image_to_ipl(image im)
13 | {
14 | int x,y,c;
15 | IplImage *disp = cvCreateImage(cvSize(im.w,im.h), IPL_DEPTH_8U, im.c);
16 | int step = disp->widthStep;
17 | for(y = 0; y < im.h; ++y){
18 | for(x = 0; x < im.w; ++x){
19 | for(c= 0; c < im.c; ++c){
20 | float val = im.data[c*im.h*im.w + y*im.w + x];
21 | disp->imageData[y*step + x*im.c + c] = (unsigned char)(val*255);
22 | }
23 | }
24 | }
25 | return disp;
26 | }
27 |
28 | image ipl_to_image(IplImage* src)
29 | {
30 | int h = src->height;
31 | int w = src->width;
32 | int c = src->nChannels;
33 | image im = make_image(w, h, c);
34 | unsigned char *data = (unsigned char *)src->imageData;
35 | int step = src->widthStep;
36 | int i, j, k;
37 |
38 | for(i = 0; i < h; ++i){
39 | for(k= 0; k < c; ++k){
40 | for(j = 0; j < w; ++j){
41 | im.data[k*w*h + i*w + j] = data[i*step + j*c + k]/255.;
42 | }
43 | }
44 | }
45 | return im;
46 | }
47 |
48 | Mat image_to_mat(image im)
49 | {
50 | image copy = copy_image(im);
51 | constrain_image(copy);
52 | if(im.c == 3) rgbgr_image(copy);
53 |
54 | IplImage *ipl = image_to_ipl(copy);
55 | Mat m = cvarrToMat(ipl, true);
56 | cvReleaseImage(&ipl);
57 | free_image(copy);
58 | return m;
59 | }
60 |
61 | image mat_to_image(Mat m)
62 | {
63 | IplImage ipl = m;
64 | image im = ipl_to_image(&ipl);
65 | rgbgr_image(im);
66 | return im;
67 | }
68 |
69 | void *open_video_stream(const char *f, int c, int w, int h, int fps)
70 | {
71 | VideoCapture *cap;
72 | if(f) cap = new VideoCapture(f);
73 | else cap = new VideoCapture(c);
74 | if(!cap->isOpened()) return 0;
75 | if(w) cap->set(CV_CAP_PROP_FRAME_WIDTH, w);
76 | if(h) cap->set(CV_CAP_PROP_FRAME_HEIGHT, w);
77 | if(fps) cap->set(CV_CAP_PROP_FPS, w);
78 | return (void *) cap;
79 | }
80 |
81 | image get_image_from_stream(void *p)
82 | {
83 | VideoCapture *cap = (VideoCapture *)p;
84 | Mat m;
85 | *cap >> m;
86 | if(m.empty()) return make_empty_image(0,0,0);
87 | return mat_to_image(m);
88 | }
89 |
90 | image load_image_cv(char *filename, int channels)
91 | {
92 | int flag = -1;
93 | if (channels == 0) flag = -1;
94 | else if (channels == 1) flag = 0;
95 | else if (channels == 3) flag = 1;
96 | else {
97 | fprintf(stderr, "OpenCV can't force load with %d channels\n", channels);
98 | }
99 | Mat m;
100 | m = imread(filename, flag);
101 | if(!m.data){
102 | fprintf(stderr, "Cannot load image \"%s\"\n", filename);
103 | char buff[256];
104 | sprintf(buff, "echo %s >> bad.list", filename);
105 | system(buff);
106 | return make_image(10,10,3);
107 | //exit(0);
108 | }
109 | image im = mat_to_image(m);
110 | return im;
111 | }
112 |
113 | int show_image_cv(image im, const char* name, int ms)
114 | {
115 | Mat m = image_to_mat(im);
116 | imshow(name, m);
117 | int c = waitKey(ms);
118 | if (c != -1) c = c%256;
119 | return c;
120 | }
121 |
122 | void make_window(char *name, int w, int h, int fullscreen)
123 | {
124 | namedWindow(name, WINDOW_NORMAL);
125 | if (fullscreen) {
126 | setWindowProperty(name, CV_WND_PROP_FULLSCREEN, CV_WINDOW_FULLSCREEN);
127 | } else {
128 | resizeWindow(name, w, h);
129 | if(strcmp(name, "Demo") == 0) moveWindow(name, 0, 0);
130 | }
131 | }
132 |
133 | }
134 |
135 | #endif
136 |
--------------------------------------------------------------------------------
/test/darknet/src/iseg_layer.h:
--------------------------------------------------------------------------------
1 | #ifndef ISEG_LAYER_H
2 | #define ISEG_LAYER_H
3 |
4 | #include "darknet.h"
5 | #include "layer.h"
6 | #include "network.h"
7 |
8 | layer make_iseg_layer(int batch, int w, int h, int classes, int ids);
9 | void forward_iseg_layer(const layer l, network net);
10 | void backward_iseg_layer(const layer l, network net);
11 | void resize_iseg_layer(layer *l, int w, int h);
12 | int iseg_num_detections(layer l, float thresh);
13 |
14 | #ifdef GPU
15 | void forward_iseg_layer_gpu(const layer l, network net);
16 | void backward_iseg_layer_gpu(layer l, network net);
17 | #endif
18 |
19 | #endif
20 |
--------------------------------------------------------------------------------
/test/darknet/src/l2norm_layer.c:
--------------------------------------------------------------------------------
1 | #include "l2norm_layer.h"
2 | #include "activations.h"
3 | #include "blas.h"
4 | #include "cuda.h"
5 |
6 | #include
7 | #include
8 | #include
9 | #include
10 | #include
11 |
12 | layer make_l2norm_layer(int batch, int inputs)
13 | {
14 | fprintf(stderr, "l2norm %4d\n", inputs);
15 | layer l = {0};
16 | l.type = L2NORM;
17 | l.batch = batch;
18 | l.inputs = inputs;
19 | l.outputs = inputs;
20 | l.output = calloc(inputs*batch, sizeof(float));
21 | l.scales = calloc(inputs*batch, sizeof(float));
22 | l.delta = calloc(inputs*batch, sizeof(float));
23 |
24 | l.forward = forward_l2norm_layer;
25 | l.backward = backward_l2norm_layer;
26 | #ifdef GPU
27 | l.forward_gpu = forward_l2norm_layer_gpu;
28 | l.backward_gpu = backward_l2norm_layer_gpu;
29 |
30 | l.output_gpu = cuda_make_array(l.output, inputs*batch);
31 | l.scales_gpu = cuda_make_array(l.output, inputs*batch);
32 | l.delta_gpu = cuda_make_array(l.delta, inputs*batch);
33 | #endif
34 | return l;
35 | }
36 |
37 | void forward_l2norm_layer(const layer l, network net)
38 | {
39 | copy_cpu(l.outputs*l.batch, net.input, 1, l.output, 1);
40 | l2normalize_cpu(l.output, l.scales, l.batch, l.out_c, l.out_w*l.out_h);
41 | }
42 |
43 | void backward_l2norm_layer(const layer l, network net)
44 | {
45 | //axpy_cpu(l.inputs*l.batch, 1, l.scales, 1, l.delta, 1);
46 | axpy_cpu(l.inputs*l.batch, 1, l.delta, 1, net.delta, 1);
47 | }
48 |
49 | #ifdef GPU
50 |
51 | void forward_l2norm_layer_gpu(const layer l, network net)
52 | {
53 | copy_gpu(l.outputs*l.batch, net.input_gpu, 1, l.output_gpu, 1);
54 | l2normalize_gpu(l.output_gpu, l.scales_gpu, l.batch, l.out_c, l.out_w*l.out_h);
55 | }
56 |
57 | void backward_l2norm_layer_gpu(const layer l, network net)
58 | {
59 | axpy_gpu(l.batch*l.inputs, 1, l.scales_gpu, 1, l.delta_gpu, 1);
60 | axpy_gpu(l.batch*l.inputs, 1, l.delta_gpu, 1, net.delta_gpu, 1);
61 | }
62 |
63 | #endif
64 |
--------------------------------------------------------------------------------
/test/darknet/src/l2norm_layer.h:
--------------------------------------------------------------------------------
1 | #ifndef L2NORM_LAYER_H
2 | #define L2NORM_LAYER_H
3 | #include "layer.h"
4 | #include "network.h"
5 |
6 | layer make_l2norm_layer(int batch, int inputs);
7 | void forward_l2norm_layer(const layer l, network net);
8 | void backward_l2norm_layer(const layer l, network net);
9 |
10 | #ifdef GPU
11 | void forward_l2norm_layer_gpu(const layer l, network net);
12 | void backward_l2norm_layer_gpu(const layer l, network net);
13 | #endif
14 |
15 | #endif
16 |
--------------------------------------------------------------------------------
/test/darknet/src/layer.c:
--------------------------------------------------------------------------------
1 | #include "layer.h"
2 | #include "cuda.h"
3 |
4 | #include
5 |
6 | void free_layer(layer l)
7 | {
8 | if(l.type == DROPOUT){
9 | if(l.rand) free(l.rand);
10 | #ifdef GPU
11 | if(l.rand_gpu) cuda_free(l.rand_gpu);
12 | #endif
13 | return;
14 | }
15 | if(l.cweights) free(l.cweights);
16 | if(l.indexes) free(l.indexes);
17 | if(l.input_layers) free(l.input_layers);
18 | if(l.input_sizes) free(l.input_sizes);
19 | if(l.map) free(l.map);
20 | if(l.rand) free(l.rand);
21 | if(l.cost) free(l.cost);
22 | if(l.state) free(l.state);
23 | if(l.prev_state) free(l.prev_state);
24 | if(l.forgot_state) free(l.forgot_state);
25 | if(l.forgot_delta) free(l.forgot_delta);
26 | if(l.state_delta) free(l.state_delta);
27 | if(l.concat) free(l.concat);
28 | if(l.concat_delta) free(l.concat_delta);
29 | if(l.binary_weights) free(l.binary_weights);
30 | if(l.biases) free(l.biases);
31 | if(l.bias_updates) free(l.bias_updates);
32 | if(l.scales) free(l.scales);
33 | if(l.scale_updates) free(l.scale_updates);
34 | if(l.weights) free(l.weights);
35 | if(l.weight_updates) free(l.weight_updates);
36 | if(l.delta) free(l.delta);
37 | if(l.output) free(l.output);
38 | if(l.squared) free(l.squared);
39 | if(l.norms) free(l.norms);
40 | if(l.spatial_mean) free(l.spatial_mean);
41 | if(l.mean) free(l.mean);
42 | if(l.variance) free(l.variance);
43 | if(l.mean_delta) free(l.mean_delta);
44 | if(l.variance_delta) free(l.variance_delta);
45 | if(l.rolling_mean) free(l.rolling_mean);
46 | if(l.rolling_variance) free(l.rolling_variance);
47 | if(l.x) free(l.x);
48 | if(l.x_norm) free(l.x_norm);
49 | if(l.m) free(l.m);
50 | if(l.v) free(l.v);
51 | if(l.z_cpu) free(l.z_cpu);
52 | if(l.r_cpu) free(l.r_cpu);
53 | if(l.h_cpu) free(l.h_cpu);
54 | if(l.binary_input) free(l.binary_input);
55 |
56 | #ifdef GPU
57 | if(l.indexes_gpu) cuda_free((float *)l.indexes_gpu);
58 |
59 | if(l.z_gpu) cuda_free(l.z_gpu);
60 | if(l.r_gpu) cuda_free(l.r_gpu);
61 | if(l.h_gpu) cuda_free(l.h_gpu);
62 | if(l.m_gpu) cuda_free(l.m_gpu);
63 | if(l.v_gpu) cuda_free(l.v_gpu);
64 | if(l.prev_state_gpu) cuda_free(l.prev_state_gpu);
65 | if(l.forgot_state_gpu) cuda_free(l.forgot_state_gpu);
66 | if(l.forgot_delta_gpu) cuda_free(l.forgot_delta_gpu);
67 | if(l.state_gpu) cuda_free(l.state_gpu);
68 | if(l.state_delta_gpu) cuda_free(l.state_delta_gpu);
69 | if(l.gate_gpu) cuda_free(l.gate_gpu);
70 | if(l.gate_delta_gpu) cuda_free(l.gate_delta_gpu);
71 | if(l.save_gpu) cuda_free(l.save_gpu);
72 | if(l.save_delta_gpu) cuda_free(l.save_delta_gpu);
73 | if(l.concat_gpu) cuda_free(l.concat_gpu);
74 | if(l.concat_delta_gpu) cuda_free(l.concat_delta_gpu);
75 | if(l.binary_input_gpu) cuda_free(l.binary_input_gpu);
76 | if(l.binary_weights_gpu) cuda_free(l.binary_weights_gpu);
77 | if(l.mean_gpu) cuda_free(l.mean_gpu);
78 | if(l.variance_gpu) cuda_free(l.variance_gpu);
79 | if(l.rolling_mean_gpu) cuda_free(l.rolling_mean_gpu);
80 | if(l.rolling_variance_gpu) cuda_free(l.rolling_variance_gpu);
81 | if(l.variance_delta_gpu) cuda_free(l.variance_delta_gpu);
82 | if(l.mean_delta_gpu) cuda_free(l.mean_delta_gpu);
83 | if(l.x_gpu) cuda_free(l.x_gpu);
84 | if(l.x_norm_gpu) cuda_free(l.x_norm_gpu);
85 | if(l.weights_gpu) cuda_free(l.weights_gpu);
86 | if(l.weight_updates_gpu) cuda_free(l.weight_updates_gpu);
87 | if(l.biases_gpu) cuda_free(l.biases_gpu);
88 | if(l.bias_updates_gpu) cuda_free(l.bias_updates_gpu);
89 | if(l.scales_gpu) cuda_free(l.scales_gpu);
90 | if(l.scale_updates_gpu) cuda_free(l.scale_updates_gpu);
91 | if(l.output_gpu) cuda_free(l.output_gpu);
92 | if(l.delta_gpu) cuda_free(l.delta_gpu);
93 | if(l.rand_gpu) cuda_free(l.rand_gpu);
94 | if(l.squared_gpu) cuda_free(l.squared_gpu);
95 | if(l.norms_gpu) cuda_free(l.norms_gpu);
96 | #endif
97 | }
98 |
--------------------------------------------------------------------------------
/test/darknet/src/layer.h:
--------------------------------------------------------------------------------
1 | #include "darknet.h"
2 |
--------------------------------------------------------------------------------
/test/darknet/src/list.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include "list.h"
4 |
5 | list *make_list()
6 | {
7 | list *l = malloc(sizeof(list));
8 | l->size = 0;
9 | l->front = 0;
10 | l->back = 0;
11 | return l;
12 | }
13 |
14 | /*
15 | void transfer_node(list *s, list *d, node *n)
16 | {
17 | node *prev, *next;
18 | prev = n->prev;
19 | next = n->next;
20 | if(prev) prev->next = next;
21 | if(next) next->prev = prev;
22 | --s->size;
23 | if(s->front == n) s->front = next;
24 | if(s->back == n) s->back = prev;
25 | }
26 | */
27 |
28 | void *list_pop(list *l){
29 | if(!l->back) return 0;
30 | node *b = l->back;
31 | void *val = b->val;
32 | l->back = b->prev;
33 | if(l->back) l->back->next = 0;
34 | free(b);
35 | --l->size;
36 |
37 | return val;
38 | }
39 |
40 | void list_insert(list *l, void *val)
41 | {
42 | node *new = malloc(sizeof(node));
43 | new->val = val;
44 | new->next = 0;
45 |
46 | if(!l->back){
47 | l->front = new;
48 | new->prev = 0;
49 | }else{
50 | l->back->next = new;
51 | new->prev = l->back;
52 | }
53 | l->back = new;
54 | ++l->size;
55 | }
56 |
57 | void free_node(node *n)
58 | {
59 | node *next;
60 | while(n) {
61 | next = n->next;
62 | free(n);
63 | n = next;
64 | }
65 | }
66 |
67 | void free_list(list *l)
68 | {
69 | free_node(l->front);
70 | free(l);
71 | }
72 |
73 | void free_list_contents(list *l)
74 | {
75 | node *n = l->front;
76 | while(n){
77 | free(n->val);
78 | n = n->next;
79 | }
80 | }
81 |
82 | void **list_to_array(list *l)
83 | {
84 | void **a = calloc(l->size, sizeof(void*));
85 | int count = 0;
86 | node *n = l->front;
87 | while(n){
88 | a[count++] = n->val;
89 | n = n->next;
90 | }
91 | return a;
92 | }
93 |
--------------------------------------------------------------------------------
/test/darknet/src/list.h:
--------------------------------------------------------------------------------
1 | #ifndef LIST_H
2 | #define LIST_H
3 | #include "darknet.h"
4 |
5 | list *make_list();
6 | int list_find(list *l, void *val);
7 |
8 | void list_insert(list *, void *);
9 |
10 |
11 | void free_list_contents(list *l);
12 |
13 | #endif
14 |
--------------------------------------------------------------------------------
/test/darknet/src/local_layer.h:
--------------------------------------------------------------------------------
1 | #ifndef LOCAL_LAYER_H
2 | #define LOCAL_LAYER_H
3 |
4 | #include "cuda.h"
5 | #include "image.h"
6 | #include "activations.h"
7 | #include "layer.h"
8 | #include "network.h"
9 |
10 | typedef layer local_layer;
11 |
12 | #ifdef GPU
13 | void forward_local_layer_gpu(local_layer layer, network net);
14 | void backward_local_layer_gpu(local_layer layer, network net);
15 | void update_local_layer_gpu(local_layer layer, update_args a);
16 |
17 | void push_local_layer(local_layer layer);
18 | void pull_local_layer(local_layer layer);
19 | #endif
20 |
21 | local_layer make_local_layer(int batch, int h, int w, int c, int n, int size, int stride, int pad, ACTIVATION activation);
22 |
23 | void forward_local_layer(const local_layer layer, network net);
24 | void backward_local_layer(local_layer layer, network net);
25 | void update_local_layer(local_layer layer, update_args a);
26 |
27 | void bias_output(float *output, float *biases, int batch, int n, int size);
28 | void backward_bias(float *bias_updates, float *delta, int batch, int n, int size);
29 |
30 | #endif
31 |
32 |
--------------------------------------------------------------------------------
/test/darknet/src/logistic_layer.c:
--------------------------------------------------------------------------------
1 | #include "logistic_layer.h"
2 | #include "activations.h"
3 | #include "blas.h"
4 | #include "cuda.h"
5 |
6 | #include
7 | #include
8 | #include
9 | #include
10 | #include
11 |
12 | layer make_logistic_layer(int batch, int inputs)
13 | {
14 | fprintf(stderr, "logistic x entropy %4d\n", inputs);
15 | layer l = {0};
16 | l.type = LOGXENT;
17 | l.batch = batch;
18 | l.inputs = inputs;
19 | l.outputs = inputs;
20 | l.loss = calloc(inputs*batch, sizeof(float));
21 | l.output = calloc(inputs*batch, sizeof(float));
22 | l.delta = calloc(inputs*batch, sizeof(float));
23 | l.cost = calloc(1, sizeof(float));
24 |
25 | l.forward = forward_logistic_layer;
26 | l.backward = backward_logistic_layer;
27 | #ifdef GPU
28 | l.forward_gpu = forward_logistic_layer_gpu;
29 | l.backward_gpu = backward_logistic_layer_gpu;
30 |
31 | l.output_gpu = cuda_make_array(l.output, inputs*batch);
32 | l.loss_gpu = cuda_make_array(l.loss, inputs*batch);
33 | l.delta_gpu = cuda_make_array(l.delta, inputs*batch);
34 | #endif
35 | return l;
36 | }
37 |
38 | void forward_logistic_layer(const layer l, network net)
39 | {
40 | copy_cpu(l.outputs*l.batch, net.input, 1, l.output, 1);
41 | activate_array(l.output, l.outputs*l.batch, LOGISTIC);
42 | if(net.truth){
43 | logistic_x_ent_cpu(l.batch*l.inputs, l.output, net.truth, l.delta, l.loss);
44 | l.cost[0] = sum_array(l.loss, l.batch*l.inputs);
45 | }
46 | }
47 |
48 | void backward_logistic_layer(const layer l, network net)
49 | {
50 | axpy_cpu(l.inputs*l.batch, 1, l.delta, 1, net.delta, 1);
51 | }
52 |
53 | #ifdef GPU
54 |
55 | void forward_logistic_layer_gpu(const layer l, network net)
56 | {
57 | copy_gpu(l.outputs*l.batch, net.input_gpu, 1, l.output_gpu, 1);
58 | activate_array_gpu(l.output_gpu, l.outputs*l.batch, LOGISTIC);
59 | if(net.truth){
60 | logistic_x_ent_gpu(l.batch*l.inputs, l.output_gpu, net.truth_gpu, l.delta_gpu, l.loss_gpu);
61 | cuda_pull_array(l.loss_gpu, l.loss, l.batch*l.inputs);
62 | l.cost[0] = sum_array(l.loss, l.batch*l.inputs);
63 | }
64 | }
65 |
66 | void backward_logistic_layer_gpu(const layer l, network net)
67 | {
68 | axpy_gpu(l.batch*l.inputs, 1, l.delta_gpu, 1, net.delta_gpu, 1);
69 | }
70 |
71 | #endif
72 |
--------------------------------------------------------------------------------
/test/darknet/src/logistic_layer.h:
--------------------------------------------------------------------------------
1 | #ifndef LOGISTIC_LAYER_H
2 | #define LOGISTIC_LAYER_H
3 | #include "layer.h"
4 | #include "network.h"
5 |
6 | layer make_logistic_layer(int batch, int inputs);
7 | void forward_logistic_layer(const layer l, network net);
8 | void backward_logistic_layer(const layer l, network net);
9 |
10 | #ifdef GPU
11 | void forward_logistic_layer_gpu(const layer l, network net);
12 | void backward_logistic_layer_gpu(const layer l, network net);
13 | #endif
14 |
15 | #endif
16 |
--------------------------------------------------------------------------------
/test/darknet/src/lstm_layer.h:
--------------------------------------------------------------------------------
1 | #ifndef LSTM_LAYER_H
2 | #define LSTM_LAYER_H
3 |
4 | #include "activations.h"
5 | #include "layer.h"
6 | #include "network.h"
7 | #define USET
8 |
9 | layer make_lstm_layer(int batch, int inputs, int outputs, int steps, int batch_normalize, int adam);
10 |
11 | void forward_lstm_layer(layer l, network net);
12 | void update_lstm_layer(layer l, update_args a);
13 |
14 | #ifdef GPU
15 | void forward_lstm_layer_gpu(layer l, network net);
16 | void backward_lstm_layer_gpu(layer l, network net);
17 | void update_lstm_layer_gpu(layer l, update_args a);
18 |
19 | #endif
20 | #endif
21 |
--------------------------------------------------------------------------------
/test/darknet/src/matrix.c:
--------------------------------------------------------------------------------
1 | #include "matrix.h"
2 | #include "utils.h"
3 | #include "blas.h"
4 | #include
5 | #include
6 | #include
7 | #include
8 | #include
9 |
10 | void free_matrix(matrix m)
11 | {
12 | int i;
13 | for(i = 0; i < m.rows; ++i) free(m.vals[i]);
14 | free(m.vals);
15 | }
16 |
17 | float matrix_topk_accuracy(matrix truth, matrix guess, int k)
18 | {
19 | int *indexes = calloc(k, sizeof(int));
20 | int n = truth.cols;
21 | int i,j;
22 | int correct = 0;
23 | for(i = 0; i < truth.rows; ++i){
24 | top_k(guess.vals[i], n, k, indexes);
25 | for(j = 0; j < k; ++j){
26 | int class = indexes[j];
27 | if(truth.vals[i][class]){
28 | ++correct;
29 | break;
30 | }
31 | }
32 | }
33 | free(indexes);
34 | return (float)correct/truth.rows;
35 | }
36 |
37 | void scale_matrix(matrix m, float scale)
38 | {
39 | int i,j;
40 | for(i = 0; i < m.rows; ++i){
41 | for(j = 0; j < m.cols; ++j){
42 | m.vals[i][j] *= scale;
43 | }
44 | }
45 | }
46 |
47 | matrix resize_matrix(matrix m, int size)
48 | {
49 | int i;
50 | if (m.rows == size) return m;
51 | if (m.rows < size) {
52 | m.vals = realloc(m.vals, size*sizeof(float*));
53 | for (i = m.rows; i < size; ++i) {
54 | m.vals[i] = calloc(m.cols, sizeof(float));
55 | }
56 | } else if (m.rows > size) {
57 | for (i = size; i < m.rows; ++i) {
58 | free(m.vals[i]);
59 | }
60 | m.vals = realloc(m.vals, size*sizeof(float*));
61 | }
62 | m.rows = size;
63 | return m;
64 | }
65 |
66 | void matrix_add_matrix(matrix from, matrix to)
67 | {
68 | assert(from.rows == to.rows && from.cols == to.cols);
69 | int i,j;
70 | for(i = 0; i < from.rows; ++i){
71 | for(j = 0; j < from.cols; ++j){
72 | to.vals[i][j] += from.vals[i][j];
73 | }
74 | }
75 | }
76 |
77 | matrix copy_matrix(matrix m)
78 | {
79 | matrix c = {0};
80 | c.rows = m.rows;
81 | c.cols = m.cols;
82 | c.vals = calloc(c.rows, sizeof(float *));
83 | int i;
84 | for(i = 0; i < c.rows; ++i){
85 | c.vals[i] = calloc(c.cols, sizeof(float));
86 | copy_cpu(c.cols, m.vals[i], 1, c.vals[i], 1);
87 | }
88 | return c;
89 | }
90 |
91 | matrix make_matrix(int rows, int cols)
92 | {
93 | int i;
94 | matrix m;
95 | m.rows = rows;
96 | m.cols = cols;
97 | m.vals = calloc(m.rows, sizeof(float *));
98 | for(i = 0; i < m.rows; ++i){
99 | m.vals[i] = calloc(m.cols, sizeof(float));
100 | }
101 | return m;
102 | }
103 |
104 | matrix hold_out_matrix(matrix *m, int n)
105 | {
106 | int i;
107 | matrix h;
108 | h.rows = n;
109 | h.cols = m->cols;
110 | h.vals = calloc(h.rows, sizeof(float *));
111 | for(i = 0; i < n; ++i){
112 | int index = rand()%m->rows;
113 | h.vals[i] = m->vals[index];
114 | m->vals[index] = m->vals[--(m->rows)];
115 | }
116 | return h;
117 | }
118 |
119 | float *pop_column(matrix *m, int c)
120 | {
121 | float *col = calloc(m->rows, sizeof(float));
122 | int i, j;
123 | for(i = 0; i < m->rows; ++i){
124 | col[i] = m->vals[i][c];
125 | for(j = c; j < m->cols-1; ++j){
126 | m->vals[i][j] = m->vals[i][j+1];
127 | }
128 | }
129 | --m->cols;
130 | return col;
131 | }
132 |
133 | matrix csv_to_matrix(char *filename)
134 | {
135 | FILE *fp = fopen(filename, "r");
136 | if(!fp) file_error(filename);
137 |
138 | matrix m;
139 | m.cols = -1;
140 |
141 | char *line;
142 |
143 | int n = 0;
144 | int size = 1024;
145 | m.vals = calloc(size, sizeof(float*));
146 | while((line = fgetl(fp))){
147 | if(m.cols == -1) m.cols = count_fields(line);
148 | if(n == size){
149 | size *= 2;
150 | m.vals = realloc(m.vals, size*sizeof(float*));
151 | }
152 | m.vals[n] = parse_fields(line, m.cols);
153 | free(line);
154 | ++n;
155 | }
156 | m.vals = realloc(m.vals, n*sizeof(float*));
157 | m.rows = n;
158 | return m;
159 | }
160 |
161 | void matrix_to_csv(matrix m)
162 | {
163 | int i, j;
164 |
165 | for(i = 0; i < m.rows; ++i){
166 | for(j = 0; j < m.cols; ++j){
167 | if(j > 0) printf(",");
168 | printf("%.17g", m.vals[i][j]);
169 | }
170 | printf("\n");
171 | }
172 | }
173 |
174 | void print_matrix(matrix m)
175 | {
176 | int i, j;
177 | printf("%d X %d Matrix:\n",m.rows, m.cols);
178 | printf(" __");
179 | for(j = 0; j < 16*m.cols-1; ++j) printf(" ");
180 | printf("__ \n");
181 |
182 | printf("| ");
183 | for(j = 0; j < 16*m.cols-1; ++j) printf(" ");
184 | printf(" |\n");
185 |
186 | for(i = 0; i < m.rows; ++i){
187 | printf("| ");
188 | for(j = 0; j < m.cols; ++j){
189 | printf("%15.7f ", m.vals[i][j]);
190 | }
191 | printf(" |\n");
192 | }
193 | printf("|__");
194 | for(j = 0; j < 16*m.cols-1; ++j) printf(" ");
195 | printf("__|\n");
196 | }
197 |
--------------------------------------------------------------------------------
/test/darknet/src/matrix.h:
--------------------------------------------------------------------------------
1 | #ifndef MATRIX_H
2 | #define MATRIX_H
3 | #include "darknet.h"
4 |
5 | matrix copy_matrix(matrix m);
6 | void print_matrix(matrix m);
7 |
8 | matrix hold_out_matrix(matrix *m, int n);
9 | matrix resize_matrix(matrix m, int size);
10 |
11 | float *pop_column(matrix *m, int c);
12 |
13 | #endif
14 |
--------------------------------------------------------------------------------
/test/darknet/src/maxpool_layer.c:
--------------------------------------------------------------------------------
1 | #include "maxpool_layer.h"
2 | #include "cuda.h"
3 | #include
4 |
5 | image get_maxpool_image(maxpool_layer l)
6 | {
7 | int h = l.out_h;
8 | int w = l.out_w;
9 | int c = l.c;
10 | return float_to_image(w,h,c,l.output);
11 | }
12 |
13 | image get_maxpool_delta(maxpool_layer l)
14 | {
15 | int h = l.out_h;
16 | int w = l.out_w;
17 | int c = l.c;
18 | return float_to_image(w,h,c,l.delta);
19 | }
20 |
21 | maxpool_layer make_maxpool_layer(int batch, int h, int w, int c, int size, int stride, int padding)
22 | {
23 | maxpool_layer l = {0};
24 | l.type = MAXPOOL;
25 | l.batch = batch;
26 | l.h = h;
27 | l.w = w;
28 | l.c = c;
29 | l.pad = padding;
30 | l.out_w = (w + padding - size)/stride + 1;
31 | l.out_h = (h + padding - size)/stride + 1;
32 | l.out_c = c;
33 | l.outputs = l.out_h * l.out_w * l.out_c;
34 | l.inputs = h*w*c;
35 | l.size = size;
36 | l.stride = stride;
37 | int output_size = l.out_h * l.out_w * l.out_c * batch;
38 | l.indexes = calloc(output_size, sizeof(int));
39 | l.output = calloc(output_size, sizeof(float));
40 | l.delta = calloc(output_size, sizeof(float));
41 | l.forward = forward_maxpool_layer;
42 | l.backward = backward_maxpool_layer;
43 | #ifdef GPU
44 | l.forward_gpu = forward_maxpool_layer_gpu;
45 | l.backward_gpu = backward_maxpool_layer_gpu;
46 | l.indexes_gpu = cuda_make_int_array(0, output_size);
47 | l.output_gpu = cuda_make_array(l.output, output_size);
48 | l.delta_gpu = cuda_make_array(l.delta, output_size);
49 | #endif
50 | fprintf(stderr, "max %d x %d / %d %4d x%4d x%4d -> %4d x%4d x%4d\n", size, size, stride, w, h, c, l.out_w, l.out_h, l.out_c);
51 | return l;
52 | }
53 |
54 | void resize_maxpool_layer(maxpool_layer *l, int w, int h)
55 | {
56 | l->h = h;
57 | l->w = w;
58 | l->inputs = h*w*l->c;
59 |
60 | l->out_w = (w + l->pad - l->size)/l->stride + 1;
61 | l->out_h = (h + l->pad - l->size)/l->stride + 1;
62 | l->outputs = l->out_w * l->out_h * l->c;
63 | int output_size = l->outputs * l->batch;
64 |
65 | l->indexes = realloc(l->indexes, output_size * sizeof(int));
66 | l->output = realloc(l->output, output_size * sizeof(float));
67 | l->delta = realloc(l->delta, output_size * sizeof(float));
68 |
69 | #ifdef GPU
70 | cuda_free((float *)l->indexes_gpu);
71 | cuda_free(l->output_gpu);
72 | cuda_free(l->delta_gpu);
73 | l->indexes_gpu = cuda_make_int_array(0, output_size);
74 | l->output_gpu = cuda_make_array(l->output, output_size);
75 | l->delta_gpu = cuda_make_array(l->delta, output_size);
76 | #endif
77 | }
78 |
79 | void forward_maxpool_layer(const maxpool_layer l, network net)
80 | {
81 | int b,i,j,k,m,n;
82 | int w_offset = -l.pad/2;
83 | int h_offset = -l.pad/2;
84 |
85 | int h = l.out_h;
86 | int w = l.out_w;
87 | int c = l.c;
88 |
89 | for(b = 0; b < l.batch; ++b){
90 | for(k = 0; k < c; ++k){
91 | for(i = 0; i < h; ++i){
92 | for(j = 0; j < w; ++j){
93 | int out_index = j + w*(i + h*(k + c*b));
94 | float max = -FLT_MAX;
95 | int max_i = -1;
96 | for(n = 0; n < l.size; ++n){
97 | for(m = 0; m < l.size; ++m){
98 | int cur_h = h_offset + i*l.stride + n;
99 | int cur_w = w_offset + j*l.stride + m;
100 | int index = cur_w + l.w*(cur_h + l.h*(k + b*l.c));
101 | int valid = (cur_h >= 0 && cur_h < l.h &&
102 | cur_w >= 0 && cur_w < l.w);
103 | float val = (valid != 0) ? net.input[index] : -FLT_MAX;
104 | max_i = (val > max) ? index : max_i;
105 | max = (val > max) ? val : max;
106 | }
107 | }
108 | l.output[out_index] = max;
109 | l.indexes[out_index] = max_i;
110 | }
111 | }
112 | }
113 | }
114 | }
115 |
116 | void backward_maxpool_layer(const maxpool_layer l, network net)
117 | {
118 | int i;
119 | int h = l.out_h;
120 | int w = l.out_w;
121 | int c = l.c;
122 | for(i = 0; i < h*w*c*l.batch; ++i){
123 | int index = l.indexes[i];
124 | net.delta[index] += l.delta[i];
125 | }
126 | }
127 |
128 |
--------------------------------------------------------------------------------
/test/darknet/src/maxpool_layer.h:
--------------------------------------------------------------------------------
1 | #ifndef MAXPOOL_LAYER_H
2 | #define MAXPOOL_LAYER_H
3 |
4 | #include "image.h"
5 | #include "cuda.h"
6 | #include "layer.h"
7 | #include "network.h"
8 |
9 | typedef layer maxpool_layer;
10 |
11 | image get_maxpool_image(maxpool_layer l);
12 | maxpool_layer make_maxpool_layer(int batch, int h, int w, int c, int size, int stride, int padding);
13 | void resize_maxpool_layer(maxpool_layer *l, int w, int h);
14 | void forward_maxpool_layer(const maxpool_layer l, network net);
15 | void backward_maxpool_layer(const maxpool_layer l, network net);
16 |
17 | #ifdef GPU
18 | void forward_maxpool_layer_gpu(maxpool_layer l, network net);
19 | void backward_maxpool_layer_gpu(maxpool_layer l, network net);
20 | #endif
21 |
22 | #endif
23 |
24 |
--------------------------------------------------------------------------------
/test/darknet/src/maxpool_layer_kernels.cu:
--------------------------------------------------------------------------------
1 | #include "cuda_runtime.h"
2 | #include "curand.h"
3 | #include "cublas_v2.h"
4 |
5 | extern "C" {
6 | #include "maxpool_layer.h"
7 | #include "cuda.h"
8 | }
9 |
10 | __global__ void forward_maxpool_layer_kernel(int n, int in_h, int in_w, int in_c, int stride, int size, int pad, float *input, float *output, int *indexes)
11 | {
12 | int h = (in_h + pad - size)/stride + 1;
13 | int w = (in_w + pad - size)/stride + 1;
14 | int c = in_c;
15 |
16 | int id = (blockIdx.x + blockIdx.y*gridDim.x) * blockDim.x + threadIdx.x;
17 | if(id >= n) return;
18 |
19 | int j = id % w;
20 | id /= w;
21 | int i = id % h;
22 | id /= h;
23 | int k = id % c;
24 | id /= c;
25 | int b = id;
26 |
27 | int w_offset = -pad/2;
28 | int h_offset = -pad/2;
29 |
30 | int out_index = j + w*(i + h*(k + c*b));
31 | float max = -INFINITY;
32 | int max_i = -1;
33 | int l, m;
34 | for(l = 0; l < size; ++l){
35 | for(m = 0; m < size; ++m){
36 | int cur_h = h_offset + i*stride + l;
37 | int cur_w = w_offset + j*stride + m;
38 | int index = cur_w + in_w*(cur_h + in_h*(k + b*in_c));
39 | int valid = (cur_h >= 0 && cur_h < in_h &&
40 | cur_w >= 0 && cur_w < in_w);
41 | float val = (valid != 0) ? input[index] : -INFINITY;
42 | max_i = (val > max) ? index : max_i;
43 | max = (val > max) ? val : max;
44 | }
45 | }
46 | output[out_index] = max;
47 | indexes[out_index] = max_i;
48 | }
49 |
50 | __global__ void backward_maxpool_layer_kernel(int n, int in_h, int in_w, int in_c, int stride, int size, int pad, float *delta, float *prev_delta, int *indexes)
51 | {
52 | int h = (in_h + pad - size)/stride + 1;
53 | int w = (in_w + pad - size)/stride + 1;
54 | int c = in_c;
55 | int area = (size-1)/stride;
56 |
57 | int id = (blockIdx.x + blockIdx.y*gridDim.x) * blockDim.x + threadIdx.x;
58 | if(id >= n) return;
59 |
60 | int index = id;
61 | int j = id % in_w;
62 | id /= in_w;
63 | int i = id % in_h;
64 | id /= in_h;
65 | int k = id % in_c;
66 | id /= in_c;
67 | int b = id;
68 |
69 | int w_offset = -pad/2;
70 | int h_offset = -pad/2;
71 |
72 | float d = 0;
73 | int l, m;
74 | for(l = -area; l < area+1; ++l){
75 | for(m = -area; m < area+1; ++m){
76 | int out_w = (j-w_offset)/stride + m;
77 | int out_h = (i-h_offset)/stride + l;
78 | int out_index = out_w + w*(out_h + h*(k + c*b));
79 | int valid = (out_w >= 0 && out_w < w &&
80 | out_h >= 0 && out_h < h);
81 | d += (valid && indexes[out_index] == index) ? delta[out_index] : 0;
82 | }
83 | }
84 | prev_delta[index] += d;
85 | }
86 |
87 | extern "C" void forward_maxpool_layer_gpu(maxpool_layer layer, network net)
88 | {
89 | int h = layer.out_h;
90 | int w = layer.out_w;
91 | int c = layer.c;
92 |
93 | size_t n = h*w*c*layer.batch;
94 |
95 | forward_maxpool_layer_kernel<<>>(n, layer.h, layer.w, layer.c, layer.stride, layer.size, layer.pad, net.input_gpu, layer.output_gpu, layer.indexes_gpu);
96 | check_error(cudaPeekAtLastError());
97 | }
98 |
99 | extern "C" void backward_maxpool_layer_gpu(maxpool_layer layer, network net)
100 | {
101 | size_t n = layer.h*layer.w*layer.c*layer.batch;
102 |
103 | backward_maxpool_layer_kernel<<>>(n, layer.h, layer.w, layer.c, layer.stride, layer.size, layer.pad, layer.delta_gpu, net.delta_gpu, layer.indexes_gpu);
104 | check_error(cudaPeekAtLastError());
105 | }
106 |
107 |
--------------------------------------------------------------------------------
/test/darknet/src/network.h:
--------------------------------------------------------------------------------
1 | // Oh boy, why am I about to do this....
2 | #ifndef NETWORK_H
3 | #define NETWORK_H
4 | #include "darknet.h"
5 |
6 | #include "image.h"
7 | #include "layer.h"
8 | #include "data.h"
9 | #include "tree.h"
10 |
11 |
12 | #ifdef GPU
13 | void pull_network_output(network *net);
14 | #endif
15 |
16 | void compare_networks(network *n1, network *n2, data d);
17 | char *get_layer_string(LAYER_TYPE a);
18 |
19 | network *make_network(int n);
20 |
21 |
22 | float network_accuracy_multi(network *net, data d, int n);
23 | int get_predicted_class_network(network *net);
24 | void print_network(network *net);
25 | int resize_network(network *net, int w, int h);
26 | void calc_network_cost(network *net);
27 |
28 | #endif
29 |
30 |
--------------------------------------------------------------------------------
/test/darknet/src/normalization_layer.h:
--------------------------------------------------------------------------------
1 | #ifndef NORMALIZATION_LAYER_H
2 | #define NORMALIZATION_LAYER_H
3 |
4 | #include "image.h"
5 | #include "layer.h"
6 | #include "network.h"
7 |
8 | layer make_normalization_layer(int batch, int w, int h, int c, int size, float alpha, float beta, float kappa);
9 | void resize_normalization_layer(layer *layer, int h, int w);
10 | void forward_normalization_layer(const layer layer, network net);
11 | void backward_normalization_layer(const layer layer, network net);
12 | void visualize_normalization_layer(layer layer, char *window);
13 |
14 | #ifdef GPU
15 | void forward_normalization_layer_gpu(const layer layer, network net);
16 | void backward_normalization_layer_gpu(const layer layer, network net);
17 | #endif
18 |
19 | #endif
20 |
--------------------------------------------------------------------------------
/test/darknet/src/option_list.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | #include "option_list.h"
5 | #include "utils.h"
6 |
7 | list *read_data_cfg(char *filename)
8 | {
9 | FILE *file = fopen(filename, "r");
10 | if(file == 0) file_error(filename);
11 | char *line;
12 | int nu = 0;
13 | list *options = make_list();
14 | while((line=fgetl(file)) != 0){
15 | ++ nu;
16 | strip(line);
17 | switch(line[0]){
18 | case '\0':
19 | case '#':
20 | case ';':
21 | free(line);
22 | break;
23 | default:
24 | if(!read_option(line, options)){
25 | fprintf(stderr, "Config file error line %d, could parse: %s\n", nu, line);
26 | free(line);
27 | }
28 | break;
29 | }
30 | }
31 | fclose(file);
32 | return options;
33 | }
34 |
35 | metadata get_metadata(char *file)
36 | {
37 | metadata m = {0};
38 | list *options = read_data_cfg(file);
39 |
40 | char *name_list = option_find_str(options, "names", 0);
41 | if(!name_list) name_list = option_find_str(options, "labels", 0);
42 | if(!name_list) {
43 | fprintf(stderr, "No names or labels found\n");
44 | } else {
45 | m.names = get_labels(name_list);
46 | }
47 | m.classes = option_find_int(options, "classes", 2);
48 | free_list(options);
49 | return m;
50 | }
51 |
52 | int read_option(char *s, list *options)
53 | {
54 | size_t i;
55 | size_t len = strlen(s);
56 | char *val = 0;
57 | for(i = 0; i < len; ++i){
58 | if(s[i] == '='){
59 | s[i] = '\0';
60 | val = s+i+1;
61 | break;
62 | }
63 | }
64 | if(i == len-1) return 0;
65 | char *key = s;
66 | option_insert(options, key, val);
67 | return 1;
68 | }
69 |
70 | void option_insert(list *l, char *key, char *val)
71 | {
72 | kvp *p = malloc(sizeof(kvp));
73 | p->key = key;
74 | p->val = val;
75 | p->used = 0;
76 | list_insert(l, p);
77 | }
78 |
79 | void option_unused(list *l)
80 | {
81 | node *n = l->front;
82 | while(n){
83 | kvp *p = (kvp *)n->val;
84 | if(!p->used){
85 | fprintf(stderr, "Unused field: '%s = %s'\n", p->key, p->val);
86 | }
87 | n = n->next;
88 | }
89 | }
90 |
91 | char *option_find(list *l, char *key)
92 | {
93 | node *n = l->front;
94 | while(n){
95 | kvp *p = (kvp *)n->val;
96 | if(strcmp(p->key, key) == 0){
97 | p->used = 1;
98 | return p->val;
99 | }
100 | n = n->next;
101 | }
102 | return 0;
103 | }
104 | char *option_find_str(list *l, char *key, char *def)
105 | {
106 | char *v = option_find(l, key);
107 | if(v) return v;
108 | if(def) fprintf(stderr, "%s: Using default '%s'\n", key, def);
109 | return def;
110 | }
111 |
112 | int option_find_int(list *l, char *key, int def)
113 | {
114 | char *v = option_find(l, key);
115 | if(v) return atoi(v);
116 | fprintf(stderr, "%s: Using default '%d'\n", key, def);
117 | return def;
118 | }
119 |
120 | int option_find_int_quiet(list *l, char *key, int def)
121 | {
122 | char *v = option_find(l, key);
123 | if(v) return atoi(v);
124 | return def;
125 | }
126 |
127 | float option_find_float_quiet(list *l, char *key, float def)
128 | {
129 | char *v = option_find(l, key);
130 | if(v) return atof(v);
131 | return def;
132 | }
133 |
134 | float option_find_float(list *l, char *key, float def)
135 | {
136 | char *v = option_find(l, key);
137 | if(v) return atof(v);
138 | fprintf(stderr, "%s: Using default '%lf'\n", key, def);
139 | return def;
140 | }
141 |
--------------------------------------------------------------------------------
/test/darknet/src/option_list.h:
--------------------------------------------------------------------------------
1 | #ifndef OPTION_LIST_H
2 | #define OPTION_LIST_H
3 | #include "list.h"
4 |
5 | typedef struct{
6 | char *key;
7 | char *val;
8 | int used;
9 | } kvp;
10 |
11 |
12 | int read_option(char *s, list *options);
13 | void option_insert(list *l, char *key, char *val);
14 | char *option_find(list *l, char *key);
15 | float option_find_float(list *l, char *key, float def);
16 | float option_find_float_quiet(list *l, char *key, float def);
17 | void option_unused(list *l);
18 |
19 | #endif
20 |
--------------------------------------------------------------------------------
/test/darknet/src/parser.h:
--------------------------------------------------------------------------------
1 | #ifndef PARSER_H
2 | #define PARSER_H
3 | #include "darknet.h"
4 | #include "network.h"
5 |
6 | void save_network(network net, char *filename);
7 | void save_weights_double(network net, char *filename);
8 |
9 | #endif
10 |
--------------------------------------------------------------------------------
/test/darknet/src/region_layer.h:
--------------------------------------------------------------------------------
1 | #ifndef REGION_LAYER_H
2 | #define REGION_LAYER_H
3 |
4 | #include "darknet.h"
5 | #include "layer.h"
6 | #include "network.h"
7 |
8 | layer make_region_layer(int batch, int w, int h, int n, int classes, int coords);
9 | void forward_region_layer(const layer l, network net);
10 | void backward_region_layer(const layer l, network net);
11 | void resize_region_layer(layer *l, int w, int h);
12 |
13 | #ifdef GPU
14 | void forward_region_layer_gpu(const layer l, network net);
15 | void backward_region_layer_gpu(layer l, network net);
16 | #endif
17 |
18 | #endif
19 |
--------------------------------------------------------------------------------
/test/darknet/src/reorg_layer.c:
--------------------------------------------------------------------------------
1 | #include "reorg_layer.h"
2 | #include "cuda.h"
3 | #include "blas.h"
4 |
5 | #include
6 |
7 |
8 | layer make_reorg_layer(int batch, int w, int h, int c, int stride, int reverse, int flatten, int extra)
9 | {
10 | layer l = {0};
11 | l.type = REORG;
12 | l.batch = batch;
13 | l.stride = stride;
14 | l.extra = extra;
15 | l.h = h;
16 | l.w = w;
17 | l.c = c;
18 | l.flatten = flatten;
19 | if(reverse){
20 | l.out_w = w*stride;
21 | l.out_h = h*stride;
22 | l.out_c = c/(stride*stride);
23 | }else{
24 | l.out_w = w/stride;
25 | l.out_h = h/stride;
26 | l.out_c = c*(stride*stride);
27 | }
28 | l.reverse = reverse;
29 |
30 | l.outputs = l.out_h * l.out_w * l.out_c;
31 | l.inputs = h*w*c;
32 | if(l.extra){
33 | l.out_w = l.out_h = l.out_c = 0;
34 | l.outputs = l.inputs + l.extra;
35 | }
36 |
37 | if(extra){
38 | fprintf(stderr, "reorg %4d -> %4d\n", l.inputs, l.outputs);
39 | } else {
40 | fprintf(stderr, "reorg /%2d %4d x%4d x%4d -> %4d x%4d x%4d\n", stride, w, h, c, l.out_w, l.out_h, l.out_c);
41 | }
42 | int output_size = l.outputs * batch;
43 | l.output = calloc(output_size, sizeof(float));
44 | l.delta = calloc(output_size, sizeof(float));
45 |
46 | l.forward = forward_reorg_layer;
47 | l.backward = backward_reorg_layer;
48 | #ifdef GPU
49 | l.forward_gpu = forward_reorg_layer_gpu;
50 | l.backward_gpu = backward_reorg_layer_gpu;
51 |
52 | l.output_gpu = cuda_make_array(l.output, output_size);
53 | l.delta_gpu = cuda_make_array(l.delta, output_size);
54 | #endif
55 | return l;
56 | }
57 |
58 | void resize_reorg_layer(layer *l, int w, int h)
59 | {
60 | int stride = l->stride;
61 | int c = l->c;
62 |
63 | l->h = h;
64 | l->w = w;
65 |
66 | if(l->reverse){
67 | l->out_w = w*stride;
68 | l->out_h = h*stride;
69 | l->out_c = c/(stride*stride);
70 | }else{
71 | l->out_w = w/stride;
72 | l->out_h = h/stride;
73 | l->out_c = c*(stride*stride);
74 | }
75 |
76 | l->outputs = l->out_h * l->out_w * l->out_c;
77 | l->inputs = l->outputs;
78 | int output_size = l->outputs * l->batch;
79 |
80 | l->output = realloc(l->output, output_size * sizeof(float));
81 | l->delta = realloc(l->delta, output_size * sizeof(float));
82 |
83 | #ifdef GPU
84 | cuda_free(l->output_gpu);
85 | cuda_free(l->delta_gpu);
86 | l->output_gpu = cuda_make_array(l->output, output_size);
87 | l->delta_gpu = cuda_make_array(l->delta, output_size);
88 | #endif
89 | }
90 |
91 | void forward_reorg_layer(const layer l, network net)
92 | {
93 | int i;
94 | if(l.flatten){
95 | memcpy(l.output, net.input, l.outputs*l.batch*sizeof(float));
96 | if(l.reverse){
97 | flatten(l.output, l.w*l.h, l.c, l.batch, 0);
98 | }else{
99 | flatten(l.output, l.w*l.h, l.c, l.batch, 1);
100 | }
101 | } else if (l.extra) {
102 | for(i = 0; i < l.batch; ++i){
103 | copy_cpu(l.inputs, net.input + i*l.inputs, 1, l.output + i*l.outputs, 1);
104 | }
105 | } else if (l.reverse){
106 | reorg_cpu(net.input, l.w, l.h, l.c, l.batch, l.stride, 1, l.output);
107 | } else {
108 | reorg_cpu(net.input, l.w, l.h, l.c, l.batch, l.stride, 0, l.output);
109 | }
110 | }
111 |
112 | void backward_reorg_layer(const layer l, network net)
113 | {
114 | int i;
115 | if(l.flatten){
116 | memcpy(net.delta, l.delta, l.outputs*l.batch*sizeof(float));
117 | if(l.reverse){
118 | flatten(net.delta, l.w*l.h, l.c, l.batch, 1);
119 | }else{
120 | flatten(net.delta, l.w*l.h, l.c, l.batch, 0);
121 | }
122 | } else if(l.reverse){
123 | reorg_cpu(l.delta, l.w, l.h, l.c, l.batch, l.stride, 0, net.delta);
124 | } else if (l.extra) {
125 | for(i = 0; i < l.batch; ++i){
126 | copy_cpu(l.inputs, l.delta + i*l.outputs, 1, net.delta + i*l.inputs, 1);
127 | }
128 | }else{
129 | reorg_cpu(l.delta, l.w, l.h, l.c, l.batch, l.stride, 1, net.delta);
130 | }
131 | }
132 |
133 | #ifdef GPU
134 | void forward_reorg_layer_gpu(layer l, network net)
135 | {
136 | int i;
137 | if(l.flatten){
138 | if(l.reverse){
139 | flatten_gpu(net.input_gpu, l.w*l.h, l.c, l.batch, 0, l.output_gpu);
140 | }else{
141 | flatten_gpu(net.input_gpu, l.w*l.h, l.c, l.batch, 1, l.output_gpu);
142 | }
143 | } else if (l.extra) {
144 | for(i = 0; i < l.batch; ++i){
145 | copy_gpu(l.inputs, net.input_gpu + i*l.inputs, 1, l.output_gpu + i*l.outputs, 1);
146 | }
147 | } else if (l.reverse) {
148 | reorg_gpu(net.input_gpu, l.w, l.h, l.c, l.batch, l.stride, 1, l.output_gpu);
149 | }else {
150 | reorg_gpu(net.input_gpu, l.w, l.h, l.c, l.batch, l.stride, 0, l.output_gpu);
151 | }
152 | }
153 |
154 | void backward_reorg_layer_gpu(layer l, network net)
155 | {
156 | if(l.flatten){
157 | if(l.reverse){
158 | flatten_gpu(l.delta_gpu, l.w*l.h, l.c, l.batch, 1, net.delta_gpu);
159 | }else{
160 | flatten_gpu(l.delta_gpu, l.w*l.h, l.c, l.batch, 0, net.delta_gpu);
161 | }
162 | } else if (l.extra) {
163 | int i;
164 | for(i = 0; i < l.batch; ++i){
165 | copy_gpu(l.inputs, l.delta_gpu + i*l.outputs, 1, net.delta_gpu + i*l.inputs, 1);
166 | }
167 | } else if(l.reverse){
168 | reorg_gpu(l.delta_gpu, l.w, l.h, l.c, l.batch, l.stride, 0, net.delta_gpu);
169 | } else {
170 | reorg_gpu(l.delta_gpu, l.w, l.h, l.c, l.batch, l.stride, 1, net.delta_gpu);
171 | }
172 | }
173 | #endif
174 |
--------------------------------------------------------------------------------
/test/darknet/src/reorg_layer.h:
--------------------------------------------------------------------------------
1 | #ifndef REORG_LAYER_H
2 | #define REORG_LAYER_H
3 |
4 | #include "image.h"
5 | #include "cuda.h"
6 | #include "layer.h"
7 | #include "network.h"
8 |
9 | layer make_reorg_layer(int batch, int w, int h, int c, int stride, int reverse, int flatten, int extra);
10 | void resize_reorg_layer(layer *l, int w, int h);
11 | void forward_reorg_layer(const layer l, network net);
12 | void backward_reorg_layer(const layer l, network net);
13 |
14 | #ifdef GPU
15 | void forward_reorg_layer_gpu(layer l, network net);
16 | void backward_reorg_layer_gpu(layer l, network net);
17 | #endif
18 |
19 | #endif
20 |
21 |
--------------------------------------------------------------------------------
/test/darknet/src/rnn_layer.h:
--------------------------------------------------------------------------------
1 |
2 | #ifndef RNN_LAYER_H
3 | #define RNN_LAYER_H
4 |
5 | #include "activations.h"
6 | #include "layer.h"
7 | #include "network.h"
8 | #define USET
9 |
10 | layer make_rnn_layer(int batch, int inputs, int outputs, int steps, ACTIVATION activation, int batch_normalize, int adam);
11 |
12 | void forward_rnn_layer(layer l, network net);
13 | void backward_rnn_layer(layer l, network net);
14 | void update_rnn_layer(layer l, update_args a);
15 |
16 | #ifdef GPU
17 | void forward_rnn_layer_gpu(layer l, network net);
18 | void backward_rnn_layer_gpu(layer l, network net);
19 | void update_rnn_layer_gpu(layer l, update_args a);
20 | void push_rnn_layer(layer l);
21 | void pull_rnn_layer(layer l);
22 | #endif
23 |
24 | #endif
25 |
26 |
--------------------------------------------------------------------------------
/test/darknet/src/route_layer.c:
--------------------------------------------------------------------------------
1 | #include "route_layer.h"
2 | #include "cuda.h"
3 | #include "blas.h"
4 |
5 | #include
6 |
7 | route_layer make_route_layer(int batch, int n, int *input_layers, int *input_sizes)
8 | {
9 | fprintf(stderr,"route ");
10 | route_layer l = {0};
11 | l.type = ROUTE;
12 | l.batch = batch;
13 | l.n = n;
14 | l.input_layers = input_layers;
15 | l.input_sizes = input_sizes;
16 | int i;
17 | int outputs = 0;
18 | for(i = 0; i < n; ++i){
19 | fprintf(stderr," %d", input_layers[i]);
20 | outputs += input_sizes[i];
21 | }
22 | fprintf(stderr, "\n");
23 | l.outputs = outputs;
24 | l.inputs = outputs;
25 | l.delta = calloc(outputs*batch, sizeof(float));
26 | l.output = calloc(outputs*batch, sizeof(float));;
27 |
28 | l.forward = forward_route_layer;
29 | l.backward = backward_route_layer;
30 | #ifdef GPU
31 | l.forward_gpu = forward_route_layer_gpu;
32 | l.backward_gpu = backward_route_layer_gpu;
33 |
34 | l.delta_gpu = cuda_make_array(l.delta, outputs*batch);
35 | l.output_gpu = cuda_make_array(l.output, outputs*batch);
36 | #endif
37 | return l;
38 | }
39 |
40 | void resize_route_layer(route_layer *l, network *net)
41 | {
42 | int i;
43 | layer first = net->layers[l->input_layers[0]];
44 | l->out_w = first.out_w;
45 | l->out_h = first.out_h;
46 | l->out_c = first.out_c;
47 | l->outputs = first.outputs;
48 | l->input_sizes[0] = first.outputs;
49 | for(i = 1; i < l->n; ++i){
50 | int index = l->input_layers[i];
51 | layer next = net->layers[index];
52 | l->outputs += next.outputs;
53 | l->input_sizes[i] = next.outputs;
54 | if(next.out_w == first.out_w && next.out_h == first.out_h){
55 | l->out_c += next.out_c;
56 | }else{
57 | printf("%d %d, %d %d\n", next.out_w, next.out_h, first.out_w, first.out_h);
58 | l->out_h = l->out_w = l->out_c = 0;
59 | }
60 | }
61 | l->inputs = l->outputs;
62 | l->delta = realloc(l->delta, l->outputs*l->batch*sizeof(float));
63 | l->output = realloc(l->output, l->outputs*l->batch*sizeof(float));
64 |
65 | #ifdef GPU
66 | cuda_free(l->output_gpu);
67 | cuda_free(l->delta_gpu);
68 | l->output_gpu = cuda_make_array(l->output, l->outputs*l->batch);
69 | l->delta_gpu = cuda_make_array(l->delta, l->outputs*l->batch);
70 | #endif
71 |
72 | }
73 |
74 | void forward_route_layer(const route_layer l, network net)
75 | {
76 | int i, j;
77 | int offset = 0;
78 | for(i = 0; i < l.n; ++i){
79 | int index = l.input_layers[i];
80 | float *input = net.layers[index].output;
81 | int input_size = l.input_sizes[i];
82 | for(j = 0; j < l.batch; ++j){
83 | copy_cpu(input_size, input + j*input_size, 1, l.output + offset + j*l.outputs, 1);
84 | }
85 | offset += input_size;
86 | }
87 | }
88 |
89 | void backward_route_layer(const route_layer l, network net)
90 | {
91 | int i, j;
92 | int offset = 0;
93 | for(i = 0; i < l.n; ++i){
94 | int index = l.input_layers[i];
95 | float *delta = net.layers[index].delta;
96 | int input_size = l.input_sizes[i];
97 | for(j = 0; j < l.batch; ++j){
98 | axpy_cpu(input_size, 1, l.delta + offset + j*l.outputs, 1, delta + j*input_size, 1);
99 | }
100 | offset += input_size;
101 | }
102 | }
103 |
104 | #ifdef GPU
105 | void forward_route_layer_gpu(const route_layer l, network net)
106 | {
107 | int i, j;
108 | int offset = 0;
109 | for(i = 0; i < l.n; ++i){
110 | int index = l.input_layers[i];
111 | float *input = net.layers[index].output_gpu;
112 | int input_size = l.input_sizes[i];
113 | for(j = 0; j < l.batch; ++j){
114 | copy_gpu(input_size, input + j*input_size, 1, l.output_gpu + offset + j*l.outputs, 1);
115 | }
116 | offset += input_size;
117 | }
118 | }
119 |
120 | void backward_route_layer_gpu(const route_layer l, network net)
121 | {
122 | int i, j;
123 | int offset = 0;
124 | for(i = 0; i < l.n; ++i){
125 | int index = l.input_layers[i];
126 | float *delta = net.layers[index].delta_gpu;
127 | int input_size = l.input_sizes[i];
128 | for(j = 0; j < l.batch; ++j){
129 | axpy_gpu(input_size, 1, l.delta_gpu + offset + j*l.outputs, 1, delta + j*input_size, 1);
130 | }
131 | offset += input_size;
132 | }
133 | }
134 | #endif
135 |
--------------------------------------------------------------------------------
/test/darknet/src/route_layer.h:
--------------------------------------------------------------------------------
1 | #ifndef ROUTE_LAYER_H
2 | #define ROUTE_LAYER_H
3 | #include "network.h"
4 | #include "layer.h"
5 |
6 | typedef layer route_layer;
7 |
8 | route_layer make_route_layer(int batch, int n, int *input_layers, int *input_size);
9 | void forward_route_layer(const route_layer l, network net);
10 | void backward_route_layer(const route_layer l, network net);
11 | void resize_route_layer(route_layer *l, network *net);
12 |
13 | #ifdef GPU
14 | void forward_route_layer_gpu(const route_layer l, network net);
15 | void backward_route_layer_gpu(const route_layer l, network net);
16 | #endif
17 |
18 | #endif
19 |
--------------------------------------------------------------------------------
/test/darknet/src/shortcut_layer.c:
--------------------------------------------------------------------------------
1 | #include "shortcut_layer.h"
2 | #include "cuda.h"
3 | #include "blas.h"
4 | #include "activations.h"
5 |
6 | #include
7 | #include
8 |
9 | layer make_shortcut_layer(int batch, int index, int w, int h, int c, int w2, int h2, int c2)
10 | {
11 | fprintf(stderr, "res %3d %4d x%4d x%4d -> %4d x%4d x%4d\n",index, w2,h2,c2, w,h,c);
12 | layer l = {0};
13 | l.type = SHORTCUT;
14 | l.batch = batch;
15 | l.w = w2;
16 | l.h = h2;
17 | l.c = c2;
18 | l.out_w = w;
19 | l.out_h = h;
20 | l.out_c = c;
21 | l.outputs = w*h*c;
22 | l.inputs = l.outputs;
23 |
24 | l.index = index;
25 |
26 | l.delta = calloc(l.outputs*batch, sizeof(float));
27 | l.output = calloc(l.outputs*batch, sizeof(float));;
28 |
29 | l.forward = forward_shortcut_layer;
30 | l.backward = backward_shortcut_layer;
31 | #ifdef GPU
32 | l.forward_gpu = forward_shortcut_layer_gpu;
33 | l.backward_gpu = backward_shortcut_layer_gpu;
34 |
35 | l.delta_gpu = cuda_make_array(l.delta, l.outputs*batch);
36 | l.output_gpu = cuda_make_array(l.output, l.outputs*batch);
37 | #endif
38 | return l;
39 | }
40 |
41 | void resize_shortcut_layer(layer *l, int w, int h)
42 | {
43 | assert(l->w == l->out_w);
44 | assert(l->h == l->out_h);
45 | l->w = l->out_w = w;
46 | l->h = l->out_h = h;
47 | l->outputs = w*h*l->out_c;
48 | l->inputs = l->outputs;
49 | l->delta = realloc(l->delta, l->outputs*l->batch*sizeof(float));
50 | l->output = realloc(l->output, l->outputs*l->batch*sizeof(float));
51 |
52 | #ifdef GPU
53 | cuda_free(l->output_gpu);
54 | cuda_free(l->delta_gpu);
55 | l->output_gpu = cuda_make_array(l->output, l->outputs*l->batch);
56 | l->delta_gpu = cuda_make_array(l->delta, l->outputs*l->batch);
57 | #endif
58 |
59 | }
60 |
61 |
62 | void forward_shortcut_layer(const layer l, network net)
63 | {
64 | copy_cpu(l.outputs*l.batch, net.input, 1, l.output, 1);
65 | shortcut_cpu(l.batch, l.w, l.h, l.c, net.layers[l.index].output, l.out_w, l.out_h, l.out_c, l.alpha, l.beta, l.output);
66 | activate_array(l.output, l.outputs*l.batch, l.activation);
67 | }
68 |
69 | void backward_shortcut_layer(const layer l, network net)
70 | {
71 | gradient_array(l.output, l.outputs*l.batch, l.activation, l.delta);
72 | axpy_cpu(l.outputs*l.batch, l.alpha, l.delta, 1, net.delta, 1);
73 | shortcut_cpu(l.batch, l.out_w, l.out_h, l.out_c, l.delta, l.w, l.h, l.c, 1, l.beta, net.layers[l.index].delta);
74 | }
75 |
76 | #ifdef GPU
77 | void forward_shortcut_layer_gpu(const layer l, network net)
78 | {
79 | copy_gpu(l.outputs*l.batch, net.input_gpu, 1, l.output_gpu, 1);
80 | shortcut_gpu(l.batch, l.w, l.h, l.c, net.layers[l.index].output_gpu, l.out_w, l.out_h, l.out_c, l.alpha, l.beta, l.output_gpu);
81 | activate_array_gpu(l.output_gpu, l.outputs*l.batch, l.activation);
82 | }
83 |
84 | void backward_shortcut_layer_gpu(const layer l, network net)
85 | {
86 | gradient_array_gpu(l.output_gpu, l.outputs*l.batch, l.activation, l.delta_gpu);
87 | axpy_gpu(l.outputs*l.batch, l.alpha, l.delta_gpu, 1, net.delta_gpu, 1);
88 | shortcut_gpu(l.batch, l.out_w, l.out_h, l.out_c, l.delta_gpu, l.w, l.h, l.c, 1, l.beta, net.layers[l.index].delta_gpu);
89 | }
90 | #endif
91 |
--------------------------------------------------------------------------------
/test/darknet/src/shortcut_layer.h:
--------------------------------------------------------------------------------
1 | #ifndef SHORTCUT_LAYER_H
2 | #define SHORTCUT_LAYER_H
3 |
4 | #include "layer.h"
5 | #include "network.h"
6 |
7 | layer make_shortcut_layer(int batch, int index, int w, int h, int c, int w2, int h2, int c2);
8 | void forward_shortcut_layer(const layer l, network net);
9 | void backward_shortcut_layer(const layer l, network net);
10 | void resize_shortcut_layer(layer *l, int w, int h);
11 |
12 | #ifdef GPU
13 | void forward_shortcut_layer_gpu(const layer l, network net);
14 | void backward_shortcut_layer_gpu(const layer l, network net);
15 | #endif
16 |
17 | #endif
18 |
--------------------------------------------------------------------------------
/test/darknet/src/softmax_layer.c:
--------------------------------------------------------------------------------
1 | #include "softmax_layer.h"
2 | #include "blas.h"
3 | #include "cuda.h"
4 |
5 | #include
6 | #include
7 | #include
8 | #include
9 | #include
10 |
11 | softmax_layer make_softmax_layer(int batch, int inputs, int groups)
12 | {
13 | assert(inputs%groups == 0);
14 | fprintf(stderr, "softmax %4d\n", inputs);
15 | softmax_layer l = {0};
16 | l.type = SOFTMAX;
17 | l.batch = batch;
18 | l.groups = groups;
19 | l.inputs = inputs;
20 | l.outputs = inputs;
21 | l.loss = calloc(inputs*batch, sizeof(float));
22 | l.output = calloc(inputs*batch, sizeof(float));
23 | l.delta = calloc(inputs*batch, sizeof(float));
24 | l.cost = calloc(1, sizeof(float));
25 |
26 | l.forward = forward_softmax_layer;
27 | l.backward = backward_softmax_layer;
28 | #ifdef GPU
29 | l.forward_gpu = forward_softmax_layer_gpu;
30 | l.backward_gpu = backward_softmax_layer_gpu;
31 |
32 | l.output_gpu = cuda_make_array(l.output, inputs*batch);
33 | l.loss_gpu = cuda_make_array(l.loss, inputs*batch);
34 | l.delta_gpu = cuda_make_array(l.delta, inputs*batch);
35 | #endif
36 | return l;
37 | }
38 |
39 | void forward_softmax_layer(const softmax_layer l, network net)
40 | {
41 | if(l.softmax_tree){
42 | int i;
43 | int count = 0;
44 | for (i = 0; i < l.softmax_tree->groups; ++i) {
45 | int group_size = l.softmax_tree->group_size[i];
46 | softmax_cpu(net.input + count, group_size, l.batch, l.inputs, 1, 0, 1, l.temperature, l.output + count);
47 | count += group_size;
48 | }
49 | } else {
50 | softmax_cpu(net.input, l.inputs/l.groups, l.batch, l.inputs, l.groups, l.inputs/l.groups, 1, l.temperature, l.output);
51 | }
52 |
53 | if(net.truth && !l.noloss){
54 | softmax_x_ent_cpu(l.batch*l.inputs, l.output, net.truth, l.delta, l.loss);
55 | l.cost[0] = sum_array(l.loss, l.batch*l.inputs);
56 | }
57 | }
58 |
59 | void backward_softmax_layer(const softmax_layer l, network net)
60 | {
61 | axpy_cpu(l.inputs*l.batch, 1, l.delta, 1, net.delta, 1);
62 | }
63 |
64 | #ifdef GPU
65 |
66 | void pull_softmax_layer_output(const softmax_layer layer)
67 | {
68 | cuda_pull_array(layer.output_gpu, layer.output, layer.inputs*layer.batch);
69 | }
70 |
71 | void forward_softmax_layer_gpu(const softmax_layer l, network net)
72 | {
73 | if(l.softmax_tree){
74 | softmax_tree(net.input_gpu, 1, l.batch, l.inputs, l.temperature, l.output_gpu, *l.softmax_tree);
75 | /*
76 | int i;
77 | int count = 0;
78 | for (i = 0; i < l.softmax_tree->groups; ++i) {
79 | int group_size = l.softmax_tree->group_size[i];
80 | softmax_gpu(net.input_gpu + count, group_size, l.batch, l.inputs, 1, 0, 1, l.temperature, l.output_gpu + count);
81 | count += group_size;
82 | }
83 | */
84 | } else {
85 | if(l.spatial){
86 | softmax_gpu(net.input_gpu, l.c, l.batch*l.c, l.inputs/l.c, l.w*l.h, 1, l.w*l.h, 1, l.output_gpu);
87 | }else{
88 | softmax_gpu(net.input_gpu, l.inputs/l.groups, l.batch, l.inputs, l.groups, l.inputs/l.groups, 1, l.temperature, l.output_gpu);
89 | }
90 | }
91 | if(net.truth && !l.noloss){
92 | softmax_x_ent_gpu(l.batch*l.inputs, l.output_gpu, net.truth_gpu, l.delta_gpu, l.loss_gpu);
93 | if(l.softmax_tree){
94 | mask_gpu(l.batch*l.inputs, l.delta_gpu, SECRET_NUM, net.truth_gpu, 0);
95 | mask_gpu(l.batch*l.inputs, l.loss_gpu, SECRET_NUM, net.truth_gpu, 0);
96 | }
97 | cuda_pull_array(l.loss_gpu, l.loss, l.batch*l.inputs);
98 | l.cost[0] = sum_array(l.loss, l.batch*l.inputs);
99 | }
100 | }
101 |
102 | void backward_softmax_layer_gpu(const softmax_layer layer, network net)
103 | {
104 | axpy_gpu(layer.batch*layer.inputs, 1, layer.delta_gpu, 1, net.delta_gpu, 1);
105 | }
106 |
107 | #endif
108 |
--------------------------------------------------------------------------------
/test/darknet/src/softmax_layer.h:
--------------------------------------------------------------------------------
1 | #ifndef SOFTMAX_LAYER_H
2 | #define SOFTMAX_LAYER_H
3 | #include "layer.h"
4 | #include "network.h"
5 |
6 | typedef layer softmax_layer;
7 |
8 | void softmax_array(float *input, int n, float temp, float *output);
9 | softmax_layer make_softmax_layer(int batch, int inputs, int groups);
10 | void forward_softmax_layer(const softmax_layer l, network net);
11 | void backward_softmax_layer(const softmax_layer l, network net);
12 |
13 | #ifdef GPU
14 | void pull_softmax_layer_output(const softmax_layer l);
15 | void forward_softmax_layer_gpu(const softmax_layer l, network net);
16 | void backward_softmax_layer_gpu(const softmax_layer l, network net);
17 | #endif
18 |
19 | #endif
20 |
--------------------------------------------------------------------------------
/test/darknet/src/tree.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include "tree.h"
4 | #include "utils.h"
5 | #include "data.h"
6 |
7 | void change_leaves(tree *t, char *leaf_list)
8 | {
9 | list *llist = get_paths(leaf_list);
10 | char **leaves = (char **)list_to_array(llist);
11 | int n = llist->size;
12 | int i,j;
13 | int found = 0;
14 | for(i = 0; i < t->n; ++i){
15 | t->leaf[i] = 0;
16 | for(j = 0; j < n; ++j){
17 | if (0==strcmp(t->name[i], leaves[j])){
18 | t->leaf[i] = 1;
19 | ++found;
20 | break;
21 | }
22 | }
23 | }
24 | fprintf(stderr, "Found %d leaves.\n", found);
25 | }
26 |
27 | float get_hierarchy_probability(float *x, tree *hier, int c, int stride)
28 | {
29 | float p = 1;
30 | while(c >= 0){
31 | p = p * x[c*stride];
32 | c = hier->parent[c];
33 | }
34 | return p;
35 | }
36 |
37 | void hierarchy_predictions(float *predictions, int n, tree *hier, int only_leaves, int stride)
38 | {
39 | int j;
40 | for(j = 0; j < n; ++j){
41 | int parent = hier->parent[j];
42 | if(parent >= 0){
43 | predictions[j*stride] *= predictions[parent*stride];
44 | }
45 | }
46 | if(only_leaves){
47 | for(j = 0; j < n; ++j){
48 | if(!hier->leaf[j]) predictions[j*stride] = 0;
49 | }
50 | }
51 | }
52 |
53 | int hierarchy_top_prediction(float *predictions, tree *hier, float thresh, int stride)
54 | {
55 | float p = 1;
56 | int group = 0;
57 | int i;
58 | while(1){
59 | float max = 0;
60 | int max_i = 0;
61 |
62 | for(i = 0; i < hier->group_size[group]; ++i){
63 | int index = i + hier->group_offset[group];
64 | float val = predictions[(i + hier->group_offset[group])*stride];
65 | if(val > max){
66 | max_i = index;
67 | max = val;
68 | }
69 | }
70 | if(p*max > thresh){
71 | p = p*max;
72 | group = hier->child[max_i];
73 | if(hier->child[max_i] < 0) return max_i;
74 | } else if (group == 0){
75 | return max_i;
76 | } else {
77 | return hier->parent[hier->group_offset[group]];
78 | }
79 | }
80 | return 0;
81 | }
82 |
83 | tree *read_tree(char *filename)
84 | {
85 | tree t = {0};
86 | FILE *fp = fopen(filename, "r");
87 |
88 | char *line;
89 | int last_parent = -1;
90 | int group_size = 0;
91 | int groups = 0;
92 | int n = 0;
93 | while((line=fgetl(fp)) != 0){
94 | char *id = calloc(256, sizeof(char));
95 | int parent = -1;
96 | sscanf(line, "%s %d", id, &parent);
97 | t.parent = realloc(t.parent, (n+1)*sizeof(int));
98 | t.parent[n] = parent;
99 |
100 | t.child = realloc(t.child, (n+1)*sizeof(int));
101 | t.child[n] = -1;
102 |
103 | t.name = realloc(t.name, (n+1)*sizeof(char *));
104 | t.name[n] = id;
105 | if(parent != last_parent){
106 | ++groups;
107 | t.group_offset = realloc(t.group_offset, groups * sizeof(int));
108 | t.group_offset[groups - 1] = n - group_size;
109 | t.group_size = realloc(t.group_size, groups * sizeof(int));
110 | t.group_size[groups - 1] = group_size;
111 | group_size = 0;
112 | last_parent = parent;
113 | }
114 | t.group = realloc(t.group, (n+1)*sizeof(int));
115 | t.group[n] = groups;
116 | if (parent >= 0) {
117 | t.child[parent] = groups;
118 | }
119 | ++n;
120 | ++group_size;
121 | }
122 | ++groups;
123 | t.group_offset = realloc(t.group_offset, groups * sizeof(int));
124 | t.group_offset[groups - 1] = n - group_size;
125 | t.group_size = realloc(t.group_size, groups * sizeof(int));
126 | t.group_size[groups - 1] = group_size;
127 | t.n = n;
128 | t.groups = groups;
129 | t.leaf = calloc(n, sizeof(int));
130 | int i;
131 | for(i = 0; i < n; ++i) t.leaf[i] = 1;
132 | for(i = 0; i < n; ++i) if(t.parent[i] >= 0) t.leaf[t.parent[i]] = 0;
133 |
134 | fclose(fp);
135 | tree *tree_ptr = calloc(1, sizeof(tree));
136 | *tree_ptr = t;
137 | //error(0);
138 | return tree_ptr;
139 | }
140 |
--------------------------------------------------------------------------------
/test/darknet/src/tree.h:
--------------------------------------------------------------------------------
1 | #ifndef TREE_H
2 | #define TREE_H
3 | #include "darknet.h"
4 |
5 | int hierarchy_top_prediction(float *predictions, tree *hier, float thresh, int stride);
6 | float get_hierarchy_probability(float *x, tree *hier, int c, int stride);
7 |
8 | #endif
9 |
--------------------------------------------------------------------------------
/test/darknet/src/upsample_layer.c:
--------------------------------------------------------------------------------
1 | #include "upsample_layer.h"
2 | #include "cuda.h"
3 | #include "blas.h"
4 |
5 | #include
6 |
7 | layer make_upsample_layer(int batch, int w, int h, int c, int stride)
8 | {
9 | layer l = {0};
10 | l.type = UPSAMPLE;
11 | l.batch = batch;
12 | l.w = w;
13 | l.h = h;
14 | l.c = c;
15 | l.out_w = w*stride;
16 | l.out_h = h*stride;
17 | l.out_c = c;
18 | if(stride < 0){
19 | stride = -stride;
20 | l.reverse=1;
21 | l.out_w = w/stride;
22 | l.out_h = h/stride;
23 | }
24 | l.stride = stride;
25 | l.outputs = l.out_w*l.out_h*l.out_c;
26 | l.inputs = l.w*l.h*l.c;
27 | l.delta = calloc(l.outputs*batch, sizeof(float));
28 | l.output = calloc(l.outputs*batch, sizeof(float));;
29 |
30 | l.forward = forward_upsample_layer;
31 | l.backward = backward_upsample_layer;
32 | #ifdef GPU
33 | l.forward_gpu = forward_upsample_layer_gpu;
34 | l.backward_gpu = backward_upsample_layer_gpu;
35 |
36 | l.delta_gpu = cuda_make_array(l.delta, l.outputs*batch);
37 | l.output_gpu = cuda_make_array(l.output, l.outputs*batch);
38 | #endif
39 | if(l.reverse) fprintf(stderr, "downsample %2dx %4d x%4d x%4d -> %4d x%4d x%4d\n", stride, w, h, c, l.out_w, l.out_h, l.out_c);
40 | else fprintf(stderr, "upsample %2dx %4d x%4d x%4d -> %4d x%4d x%4d\n", stride, w, h, c, l.out_w, l.out_h, l.out_c);
41 | return l;
42 | }
43 |
44 | void resize_upsample_layer(layer *l, int w, int h)
45 | {
46 | l->w = w;
47 | l->h = h;
48 | l->out_w = w*l->stride;
49 | l->out_h = h*l->stride;
50 | if(l->reverse){
51 | l->out_w = w/l->stride;
52 | l->out_h = h/l->stride;
53 | }
54 | l->outputs = l->out_w*l->out_h*l->out_c;
55 | l->inputs = l->h*l->w*l->c;
56 | l->delta = realloc(l->delta, l->outputs*l->batch*sizeof(float));
57 | l->output = realloc(l->output, l->outputs*l->batch*sizeof(float));
58 |
59 | #ifdef GPU
60 | cuda_free(l->output_gpu);
61 | cuda_free(l->delta_gpu);
62 | l->output_gpu = cuda_make_array(l->output, l->outputs*l->batch);
63 | l->delta_gpu = cuda_make_array(l->delta, l->outputs*l->batch);
64 | #endif
65 |
66 | }
67 |
68 | void forward_upsample_layer(const layer l, network net)
69 | {
70 | fill_cpu(l.outputs*l.batch, 0, l.output, 1);
71 | if(l.reverse){
72 | upsample_cpu(l.output, l.out_w, l.out_h, l.c, l.batch, l.stride, 0, l.scale, net.input);
73 | }else{
74 | upsample_cpu(net.input, l.w, l.h, l.c, l.batch, l.stride, 1, l.scale, l.output);
75 | }
76 | }
77 |
78 | void backward_upsample_layer(const layer l, network net)
79 | {
80 | if(l.reverse){
81 | upsample_cpu(l.delta, l.out_w, l.out_h, l.c, l.batch, l.stride, 1, l.scale, net.delta);
82 | }else{
83 | upsample_cpu(net.delta, l.w, l.h, l.c, l.batch, l.stride, 0, l.scale, l.delta);
84 | }
85 | }
86 |
87 | #ifdef GPU
88 | void forward_upsample_layer_gpu(const layer l, network net)
89 | {
90 | fill_gpu(l.outputs*l.batch, 0, l.output_gpu, 1);
91 | if(l.reverse){
92 | upsample_gpu(l.output_gpu, l.out_w, l.out_h, l.c, l.batch, l.stride, 0, l.scale, net.input_gpu);
93 | }else{
94 | upsample_gpu(net.input_gpu, l.w, l.h, l.c, l.batch, l.stride, 1, l.scale, l.output_gpu);
95 | }
96 | }
97 |
98 | void backward_upsample_layer_gpu(const layer l, network net)
99 | {
100 | if(l.reverse){
101 | upsample_gpu(l.delta_gpu, l.out_w, l.out_h, l.c, l.batch, l.stride, 1, l.scale, net.delta_gpu);
102 | }else{
103 | upsample_gpu(net.delta_gpu, l.w, l.h, l.c, l.batch, l.stride, 0, l.scale, l.delta_gpu);
104 | }
105 | }
106 | #endif
107 |
--------------------------------------------------------------------------------
/test/darknet/src/upsample_layer.h:
--------------------------------------------------------------------------------
1 | #ifndef UPSAMPLE_LAYER_H
2 | #define UPSAMPLE_LAYER_H
3 | #include "darknet.h"
4 |
5 | layer make_upsample_layer(int batch, int w, int h, int c, int stride);
6 | void forward_upsample_layer(const layer l, network net);
7 | void backward_upsample_layer(const layer l, network net);
8 | void resize_upsample_layer(layer *l, int w, int h);
9 |
10 | #ifdef GPU
11 | void forward_upsample_layer_gpu(const layer l, network net);
12 | void backward_upsample_layer_gpu(const layer l, network net);
13 | #endif
14 |
15 | #endif
16 |
--------------------------------------------------------------------------------
/test/darknet/src/utils.h:
--------------------------------------------------------------------------------
1 | #ifndef UTILS_H
2 | #define UTILS_H
3 | #include
4 | #include
5 | #include "darknet.h"
6 | #include "list.h"
7 |
8 | #define TIME(a) \
9 | do { \
10 | double start = what_time_is_it_now(); \
11 | a; \
12 | printf("%s took: %f seconds\n", #a, what_time_is_it_now() - start); \
13 | } while (0)
14 |
15 | #define TWO_PI 6.2831853071795864769252866f
16 |
17 | double what_time_is_it_now();
18 | void shuffle(void *arr, size_t n, size_t size);
19 | void sorta_shuffle(void *arr, size_t n, size_t size, size_t sections);
20 | void free_ptrs(void **ptrs, int n);
21 | int alphanum_to_int(char c);
22 | char int_to_alphanum(int i);
23 | int read_int(int fd);
24 | void write_int(int fd, int n);
25 | void read_all(int fd, char *buffer, size_t bytes);
26 | void write_all(int fd, char *buffer, size_t bytes);
27 | int read_all_fail(int fd, char *buffer, size_t bytes);
28 | int write_all_fail(int fd, char *buffer, size_t bytes);
29 | void find_replace(char *str, char *orig, char *rep, char *output);
30 | void malloc_error();
31 | void file_error(char *s);
32 | void strip(char *s);
33 | void strip_char(char *s, char bad);
34 | list *split_str(char *s, char delim);
35 | char *fgetl(FILE *fp);
36 | list *parse_csv_line(char *line);
37 | char *copy_string(char *s);
38 | int count_fields(char *line);
39 | float *parse_fields(char *line, int n);
40 | void translate_array(float *a, int n, float s);
41 | float constrain(float min, float max, float a);
42 | int constrain_int(int a, int min, int max);
43 | float rand_scale(float s);
44 | int rand_int(int min, int max);
45 | void mean_arrays(float **a, int n, int els, float *avg);
46 | float dist_array(float *a, float *b, int n, int sub);
47 | float **one_hot_encode(float *a, int n, int k);
48 | float sec(clock_t clocks);
49 | void print_statistics(float *a, int n);
50 | int int_index(int *a, int val, int n);
51 |
52 | #endif
53 |
54 |
--------------------------------------------------------------------------------
/test/darknet/src/yolo_layer.h:
--------------------------------------------------------------------------------
1 | #ifndef YOLO_LAYER_H
2 | #define YOLO_LAYER_H
3 |
4 | #include "darknet.h"
5 | #include "layer.h"
6 | #include "network.h"
7 |
8 | layer make_yolo_layer(int batch, int w, int h, int n, int total, int *mask, int classes);
9 | void forward_yolo_layer(const layer l, network net);
10 | void backward_yolo_layer(const layer l, network net);
11 | void resize_yolo_layer(layer *l, int w, int h);
12 | int yolo_num_detections(layer l, float thresh);
13 |
14 | #ifdef GPU
15 | void forward_yolo_layer_gpu(const layer l, network net);
16 | void backward_yolo_layer_gpu(layer l, network net);
17 | #endif
18 |
19 | #endif
20 |
--------------------------------------------------------------------------------
/test/test/me.c:
--------------------------------------------------------------------------------
1 | #include
2 | #define endl "\n"
3 |
4 | int main (){
5 |
6 | int a, b;
7 | scanf("%d %d", &a, &b);
8 | int c = getSum( a, b);
9 |
10 | printf("%d\n", c);
11 | return 0;
12 | }
13 |
14 | int getSum(int a, int b) {
15 |
16 |
17 | if( a + b > 0) {
18 | a = a+b;
19 | }
20 | else b = b +b;
21 |
22 | if( (b < 0) && a > 0 ) {
23 | a = a*b;
24 |
25 | if( b < -2) {
26 | b = b -a;
27 | }
28 | }
29 |
30 | for(int i=0; i<6; i++) {
31 | if(a+b < 5) {
32 | a = 5;
33 | }
34 | }
35 |
36 | return a;
37 | }
--------------------------------------------------------------------------------
/z3/LICENSE.txt:
--------------------------------------------------------------------------------
1 | Z3
2 | Copyright (c) Microsoft Corporation
3 | All rights reserved.
4 | MIT License
5 |
6 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
7 |
8 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
9 |
10 | THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
--------------------------------------------------------------------------------
/z3/bin/Microsoft.Z3.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sajedjalil/C-Path-Finder/ee748c939fbad4fd0d8aa2647abca411f320e734/z3/bin/Microsoft.Z3.dll
--------------------------------------------------------------------------------
/z3/bin/com.microsoft.z3.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sajedjalil/C-Path-Finder/ee748c939fbad4fd0d8aa2647abca411f320e734/z3/bin/com.microsoft.z3.jar
--------------------------------------------------------------------------------
/z3/bin/libz3.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sajedjalil/C-Path-Finder/ee748c939fbad4fd0d8aa2647abca411f320e734/z3/bin/libz3.dll
--------------------------------------------------------------------------------
/z3/bin/libz3.lib:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sajedjalil/C-Path-Finder/ee748c939fbad4fd0d8aa2647abca411f320e734/z3/bin/libz3.lib
--------------------------------------------------------------------------------
/z3/bin/libz3java.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sajedjalil/C-Path-Finder/ee748c939fbad4fd0d8aa2647abca411f320e734/z3/bin/libz3java.dll
--------------------------------------------------------------------------------
/z3/bin/libz3java.lib:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sajedjalil/C-Path-Finder/ee748c939fbad4fd0d8aa2647abca411f320e734/z3/bin/libz3java.lib
--------------------------------------------------------------------------------
/z3/bin/python/example.py:
--------------------------------------------------------------------------------
1 | # Copyright (c) Microsoft Corporation 2015, 2016
2 |
3 | # The Z3 Python API requires libz3.dll/.so/.dylib in the
4 | # PATH/LD_LIBRARY_PATH/DYLD_LIBRARY_PATH
5 | # environment variable and the PYTHON_PATH environment variable
6 | # needs to point to the `python' directory that contains `z3/z3.py'
7 | # (which is at bin/python in our binary releases).
8 |
9 | # If you obtained example.py as part of our binary release zip files,
10 | # which you unzipped into a directory called `MYZ3', then follow these
11 | # instructions to run the example:
12 |
13 | # Running this example on Windows:
14 | # set PATH=%PATH%;MYZ3\bin
15 | # set PYTHONPATH=MYZ3\bin\python
16 | # python example.py
17 |
18 | # Running this example on Linux:
19 | # export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:MYZ3/bin
20 | # export PYTHONPATH=MYZ3/bin/python
21 | # python example.py
22 |
23 | # Running this example on OSX:
24 | # export DYLD_LIBRARY_PATH=$DYLD_LIBRARY_PATH:MYZ3/bin
25 | # export PYTHONPATH=MYZ3/bin/python
26 | # python example.py
27 |
28 |
29 | from z3 import *
30 |
31 | x = Real('x')
32 | y = Real('y')
33 | s = Solver()
34 | s.add(x + y > 5, x > 1, y > 1)
35 | print(s.check())
36 | print(s.model())
37 |
--------------------------------------------------------------------------------
/z3/bin/python/z3/__init__.py:
--------------------------------------------------------------------------------
1 | from .z3 import *
2 |
3 | from . import z3num
4 | from . import z3poly
5 | from . import z3printer
6 | from . import z3rcf
7 | from . import z3types
8 | from . import z3util
9 |
10 | # generated files
11 | from . import z3core
12 | from . import z3consts
13 |
--------------------------------------------------------------------------------
/z3/bin/python/z3/__init__.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sajedjalil/C-Path-Finder/ee748c939fbad4fd0d8aa2647abca411f320e734/z3/bin/python/z3/__init__.pyc
--------------------------------------------------------------------------------
/z3/bin/python/z3/z3.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sajedjalil/C-Path-Finder/ee748c939fbad4fd0d8aa2647abca411f320e734/z3/bin/python/z3/z3.pyc
--------------------------------------------------------------------------------
/z3/bin/python/z3/z3consts.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sajedjalil/C-Path-Finder/ee748c939fbad4fd0d8aa2647abca411f320e734/z3/bin/python/z3/z3consts.pyc
--------------------------------------------------------------------------------
/z3/bin/python/z3/z3core.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sajedjalil/C-Path-Finder/ee748c939fbad4fd0d8aa2647abca411f320e734/z3/bin/python/z3/z3core.pyc
--------------------------------------------------------------------------------
/z3/bin/python/z3/z3num.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sajedjalil/C-Path-Finder/ee748c939fbad4fd0d8aa2647abca411f320e734/z3/bin/python/z3/z3num.pyc
--------------------------------------------------------------------------------
/z3/bin/python/z3/z3poly.py:
--------------------------------------------------------------------------------
1 | ############################################
2 | # Copyright (c) 2012 Microsoft Corporation
3 | #
4 | # Z3 Python interface for Z3 polynomials
5 | #
6 | # Author: Leonardo de Moura (leonardo)
7 | ############################################
8 |
9 | from .z3 import *
10 |
11 | def subresultants(p, q, x):
12 | """
13 | Return the non-constant subresultants of 'p' and 'q' with respect to the "variable" 'x'.
14 |
15 | 'p', 'q' and 'x' are Z3 expressions where 'p' and 'q' are arithmetic terms.
16 | Note that, any subterm that cannot be viewed as a polynomial is assumed to be a variable.
17 | Example: f(a) is a considered to be a variable b in the polynomial
18 |
19 | f(a)*f(a) + 2*f(a) + 1
20 |
21 | >>> x, y = Reals('x y')
22 | >>> subresultants(2*x + y, 3*x - 2*y + 2, x)
23 | [-7*y + 4]
24 | >>> r = subresultants(3*y*x**2 + y**3 + 1, 2*x**3 + y + 3, x)
25 | >>> r[0]
26 | 4*y**9 + 12*y**6 + 27*y**5 + 162*y**4 + 255*y**3 + 4
27 | >>> r[1]
28 | -6*y**4 + -6*y
29 | """
30 | return AstVector(Z3_polynomial_subresultants(p.ctx_ref(), p.as_ast(), q.as_ast(), x.as_ast()), p.ctx)
31 |
32 | if __name__ == "__main__":
33 | import doctest
34 | if doctest.testmod().failed:
35 | exit(1)
36 |
--------------------------------------------------------------------------------
/z3/bin/python/z3/z3poly.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sajedjalil/C-Path-Finder/ee748c939fbad4fd0d8aa2647abca411f320e734/z3/bin/python/z3/z3poly.pyc
--------------------------------------------------------------------------------
/z3/bin/python/z3/z3printer.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sajedjalil/C-Path-Finder/ee748c939fbad4fd0d8aa2647abca411f320e734/z3/bin/python/z3/z3printer.pyc
--------------------------------------------------------------------------------
/z3/bin/python/z3/z3rcf.py:
--------------------------------------------------------------------------------
1 | ############################################
2 | # Copyright (c) 2013 Microsoft Corporation
3 | #
4 | # Z3 Python interface for Z3 Real Closed Fields
5 | # that may contain
6 | # - computable transcendentals
7 | # - infinitesimals
8 | # - algebraic extensions
9 | #
10 | # Author: Leonardo de Moura (leonardo)
11 | ############################################
12 | from .z3 import *
13 | from .z3core import *
14 | from .z3printer import *
15 | from fractions import Fraction
16 |
17 | def _to_rcfnum(num, ctx=None):
18 | if isinstance(num, RCFNum):
19 | return num
20 | else:
21 | return RCFNum(num, ctx)
22 |
23 | def Pi(ctx=None):
24 | ctx = z3._get_ctx(ctx)
25 | return RCFNum(Z3_rcf_mk_pi(ctx.ref()), ctx)
26 |
27 | def E(ctx=None):
28 | ctx = z3._get_ctx(ctx)
29 | return RCFNum(Z3_rcf_mk_e(ctx.ref()), ctx)
30 |
31 | def MkInfinitesimal(name="eps", ctx=None):
32 | # Todo: remove parameter name.
33 | # For now, we keep it for backward compatibility.
34 | ctx = z3._get_ctx(ctx)
35 | return RCFNum(Z3_rcf_mk_infinitesimal(ctx.ref()), ctx)
36 |
37 | def MkRoots(p, ctx=None):
38 | ctx = z3._get_ctx(ctx)
39 | num = len(p)
40 | _tmp = []
41 | _as = (RCFNumObj * num)()
42 | _rs = (RCFNumObj * num)()
43 | for i in range(num):
44 | _a = _to_rcfnum(p[i], ctx)
45 | _tmp.append(_a) # prevent GC
46 | _as[i] = _a.num
47 | nr = Z3_rcf_mk_roots(ctx.ref(), num, _as, _rs)
48 | r = []
49 | for i in range(nr):
50 | r.append(RCFNum(_rs[i], ctx))
51 | return r
52 |
53 | class RCFNum:
54 | def __init__(self, num, ctx=None):
55 | # TODO: add support for converting AST numeral values into RCFNum
56 | if isinstance(num, RCFNumObj):
57 | self.num = num
58 | self.ctx = z3._get_ctx(ctx)
59 | else:
60 | self.ctx = z3._get_ctx(ctx)
61 | self.num = Z3_rcf_mk_rational(self.ctx_ref(), str(num))
62 |
63 | def __del__(self):
64 | Z3_rcf_del(self.ctx_ref(), self.num)
65 |
66 | def ctx_ref(self):
67 | return self.ctx.ref()
68 |
69 | def __repr__(self):
70 | return Z3_rcf_num_to_string(self.ctx_ref(), self.num, False, in_html_mode())
71 |
72 | def compact_str(self):
73 | return Z3_rcf_num_to_string(self.ctx_ref(), self.num, True, in_html_mode())
74 |
75 | def __add__(self, other):
76 | v = _to_rcfnum(other, self.ctx)
77 | return RCFNum(Z3_rcf_add(self.ctx_ref(), self.num, v.num), self.ctx)
78 |
79 | def __radd__(self, other):
80 | v = _to_rcfnum(other, self.ctx)
81 | return RCFNum(Z3_rcf_add(self.ctx_ref(), v.num, self.num), self.ctx)
82 |
83 | def __mul__(self, other):
84 | v = _to_rcfnum(other, self.ctx)
85 | return RCFNum(Z3_rcf_mul(self.ctx_ref(), self.num, v.num), self.ctx)
86 |
87 | def __rmul__(self, other):
88 | v = _to_rcfnum(other, self.ctx)
89 | return RCFNum(Z3_rcf_mul(self.ctx_ref(), v.num, self.num), self.ctx)
90 |
91 | def __sub__(self, other):
92 | v = _to_rcfnum(other, self.ctx)
93 | return RCFNum(Z3_rcf_sub(self.ctx_ref(), self.num, v.num), self.ctx)
94 |
95 | def __rsub__(self, other):
96 | v = _to_rcfnum(other, self.ctx)
97 | return RCFNum(Z3_rcf_sub(self.ctx_ref(), v.num, self.num), self.ctx)
98 |
99 | def __div__(self, other):
100 | v = _to_rcfnum(other, self.ctx)
101 | return RCFNum(Z3_rcf_div(self.ctx_ref(), self.num, v.num), self.ctx)
102 |
103 | def __rdiv__(self, other):
104 | v = _to_rcfnum(other, self.ctx)
105 | return RCFNum(Z3_rcf_div(self.ctx_ref(), v.num, self.num), self.ctx)
106 |
107 | def __neg__(self):
108 | return self.__rsub__(0)
109 |
110 | def power(self, k):
111 | return RCFNum(Z3_rcf_power(self.ctx_ref(), self.num, k), self.ctx)
112 |
113 | def __pow__(self, k):
114 | return self.power(k)
115 |
116 | def decimal(self, prec=5):
117 | return Z3_rcf_num_to_decimal_string(self.ctx_ref(), self.num, prec)
118 |
119 | def __lt__(self, other):
120 | v = _to_rcfnum(other, self.ctx)
121 | return Z3_rcf_lt(self.ctx_ref(), self.num, v.num)
122 |
123 | def __rlt__(self, other):
124 | v = _to_rcfnum(other, self.ctx)
125 | return Z3_rcf_lt(self.ctx_ref(), v.num, self.num)
126 |
127 | def __gt__(self, other):
128 | v = _to_rcfnum(other, self.ctx)
129 | return Z3_rcf_gt(self.ctx_ref(), self.num, v.num)
130 |
131 | def __rgt__(self, other):
132 | v = _to_rcfnum(other, self.ctx)
133 | return Z3_rcf_gt(self.ctx_ref(), v.num, self.num)
134 |
135 | def __le__(self, other):
136 | v = _to_rcfnum(other, self.ctx)
137 | return Z3_rcf_le(self.ctx_ref(), self.num, v.num)
138 |
139 | def __rle__(self, other):
140 | v = _to_rcfnum(other, self.ctx)
141 | return Z3_rcf_le(self.ctx_ref(), v.num, self.num)
142 |
143 | def __ge__(self, other):
144 | v = _to_rcfnum(other, self.ctx)
145 | return Z3_rcf_ge(self.ctx_ref(), self.num, v.num)
146 |
147 | def __rge__(self, other):
148 | v = _to_rcfnum(other, self.ctx)
149 | return Z3_rcf_ge(self.ctx_ref(), v.num, self.num)
150 |
151 | def __eq__(self, other):
152 | v = _to_rcfnum(other, self.ctx)
153 | return Z3_rcf_eq(self.ctx_ref(), self.num, v.num)
154 |
155 | def __ne__(self, other):
156 | v = _to_rcfnum(other, self.ctx)
157 | return Z3_rcf_neq(self.ctx_ref(), self.num, v.num)
158 |
159 | def split(self):
160 | n = (RCFNumObj * 1)()
161 | d = (RCFNumObj * 1)()
162 | Z3_rcf_get_numerator_denominator(self.ctx_ref(), self.num, n, d)
163 | return (RCFNum(n[0], self.ctx), RCFNum(d[0], self.ctx))
164 |
--------------------------------------------------------------------------------
/z3/bin/python/z3/z3rcf.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sajedjalil/C-Path-Finder/ee748c939fbad4fd0d8aa2647abca411f320e734/z3/bin/python/z3/z3rcf.pyc
--------------------------------------------------------------------------------
/z3/bin/python/z3/z3types.py:
--------------------------------------------------------------------------------
1 | ############################################
2 | # Copyright (c) 2012 Microsoft Corporation
3 | #
4 | # Z3 Python interface
5 | #
6 | # Author: Leonardo de Moura (leonardo)
7 | ############################################
8 |
9 | import ctypes
10 |
11 | class Z3Exception(Exception):
12 | def __init__(self, value):
13 | self.value = value
14 | def __str__(self):
15 | return str(self.value)
16 |
17 | class ContextObj(ctypes.c_void_p):
18 | def __init__(self, context): self._as_parameter_ = context
19 | def from_param(obj): return obj
20 |
21 | class Config(ctypes.c_void_p):
22 | def __init__(self, config): self._as_parameter_ = config
23 | def from_param(obj): return obj
24 |
25 | class Symbol(ctypes.c_void_p):
26 | def __init__(self, symbol): self._as_parameter_ = symbol
27 | def from_param(obj): return obj
28 |
29 | class Sort(ctypes.c_void_p):
30 | def __init__(self, sort): self._as_parameter_ = sort
31 | def from_param(obj): return obj
32 |
33 | class FuncDecl(ctypes.c_void_p):
34 | def __init__(self, decl): self._as_parameter_ = decl
35 | def from_param(obj): return obj
36 |
37 | class Ast(ctypes.c_void_p):
38 | def __init__(self, ast): self._as_parameter_ = ast
39 | def from_param(obj): return obj
40 |
41 | class Pattern(ctypes.c_void_p):
42 | def __init__(self, pattern): self._as_parameter_ = pattern
43 | def from_param(obj): return obj
44 |
45 | class Model(ctypes.c_void_p):
46 | def __init__(self, model): self._as_parameter_ = model
47 | def from_param(obj): return obj
48 |
49 | class Literals(ctypes.c_void_p):
50 | def __init__(self, literals): self._as_parameter_ = literals
51 | def from_param(obj): return obj
52 |
53 | class Constructor(ctypes.c_void_p):
54 | def __init__(self, constructor): self._as_parameter_ = constructor
55 | def from_param(obj): return obj
56 |
57 | class ConstructorList(ctypes.c_void_p):
58 | def __init__(self, constructor_list): self._as_parameter_ = constructor_list
59 | def from_param(obj): return obj
60 |
61 | class GoalObj(ctypes.c_void_p):
62 | def __init__(self, goal): self._as_parameter_ = goal
63 | def from_param(obj): return obj
64 |
65 | class TacticObj(ctypes.c_void_p):
66 | def __init__(self, tactic): self._as_parameter_ = tactic
67 | def from_param(obj): return obj
68 |
69 | class ProbeObj(ctypes.c_void_p):
70 | def __init__(self, probe): self._as_parameter_ = probe
71 | def from_param(obj): return obj
72 |
73 | class ApplyResultObj(ctypes.c_void_p):
74 | def __init__(self, obj): self._as_parameter_ = obj
75 | def from_param(obj): return obj
76 |
77 | class StatsObj(ctypes.c_void_p):
78 | def __init__(self, statistics): self._as_parameter_ = statistics
79 | def from_param(obj): return obj
80 |
81 | class SolverObj(ctypes.c_void_p):
82 | def __init__(self, solver): self._as_parameter_ = solver
83 | def from_param(obj): return obj
84 |
85 | class FixedpointObj(ctypes.c_void_p):
86 | def __init__(self, fixedpoint): self._as_parameter_ = fixedpoint
87 | def from_param(obj): return obj
88 |
89 | class OptimizeObj(ctypes.c_void_p):
90 | def __init__(self, optimize): self._as_parameter_ = optimize
91 | def from_param(obj): return obj
92 |
93 | class ModelObj(ctypes.c_void_p):
94 | def __init__(self, model): self._as_parameter_ = model
95 | def from_param(obj): return obj
96 |
97 | class AstVectorObj(ctypes.c_void_p):
98 | def __init__(self, vector): self._as_parameter_ = vector
99 | def from_param(obj): return obj
100 |
101 | class AstMapObj(ctypes.c_void_p):
102 | def __init__(self, ast_map): self._as_parameter_ = ast_map
103 | def from_param(obj): return obj
104 |
105 | class Params(ctypes.c_void_p):
106 | def __init__(self, params): self._as_parameter_ = params
107 | def from_param(obj): return obj
108 |
109 | class ParamDescrs(ctypes.c_void_p):
110 | def __init__(self, paramdescrs): self._as_parameter_ = paramdescrs
111 | def from_param(obj): return obj
112 |
113 | class FuncInterpObj(ctypes.c_void_p):
114 | def __init__(self, f): self._as_parameter_ = f
115 | def from_param(obj): return obj
116 |
117 | class FuncEntryObj(ctypes.c_void_p):
118 | def __init__(self, e): self._as_parameter_ = e
119 | def from_param(obj): return obj
120 |
121 | class RCFNumObj(ctypes.c_void_p):
122 | def __init__(self, e): self._as_parameter_ = e
123 | def from_param(obj): return obj
124 |
--------------------------------------------------------------------------------
/z3/bin/python/z3/z3types.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sajedjalil/C-Path-Finder/ee748c939fbad4fd0d8aa2647abca411f320e734/z3/bin/python/z3/z3types.pyc
--------------------------------------------------------------------------------
/z3/bin/python/z3/z3util.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sajedjalil/C-Path-Finder/ee748c939fbad4fd0d8aa2647abca411f320e734/z3/bin/python/z3/z3util.pyc
--------------------------------------------------------------------------------
/z3/bin/z3.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sajedjalil/C-Path-Finder/ee748c939fbad4fd0d8aa2647abca411f320e734/z3/bin/z3.exe
--------------------------------------------------------------------------------
/z3/bin/z3.h:
--------------------------------------------------------------------------------
1 | /*++
2 | Copyright (c) 2007 Microsoft Corporation
3 |
4 | Module Name:
5 |
6 | z3.h
7 |
8 | Abstract:
9 |
10 | Z3 API.
11 |
12 | Author:
13 |
14 | Nikolaj Bjorner (nbjorner)
15 | Leonardo de Moura (leonardo) 2007-06-8
16 |
17 | Notes:
18 |
19 | --*/
20 |
21 | #ifndef Z3_H_
22 | #define Z3_H_
23 |
24 | #include
25 | #include
26 | #include
27 | #include "z3_macros.h"
28 | #include "z3_api.h"
29 | #include "z3_ast_containers.h"
30 | #include "z3_algebraic.h"
31 | #include "z3_polynomial.h"
32 | #include "z3_rcf.h"
33 | #include "z3_fixedpoint.h"
34 | #include "z3_optimization.h"
35 | #include "z3_interp.h"
36 | #include "z3_fpa.h"
37 | #include "z3_spacer.h"
38 | #endif
39 |
40 |
--------------------------------------------------------------------------------
/z3/bin/z3_macros.h:
--------------------------------------------------------------------------------
1 |
2 | /*++
3 | Copyright (c) 2015 Microsoft Corporation
4 |
5 | --*/
6 |
7 | #ifndef Z3_bool_opt
8 | #define Z3_bool_opt Z3_bool
9 | #endif
10 |
11 | #ifndef Z3_API
12 | # ifdef __GNUC__
13 | # define Z3_API __attribute__ ((visibility ("default")))
14 | # else
15 | # define Z3_API
16 | # endif
17 | #endif
18 |
19 | #ifndef DEFINE_TYPE
20 | #define DEFINE_TYPE(T) typedef struct _ ## T *T
21 | #endif
22 |
23 | #ifndef DEFINE_VOID
24 | #define DEFINE_VOID(T) typedef void* T
25 | #endif
26 |
--------------------------------------------------------------------------------
/z3/bin/z3_polynomial.h:
--------------------------------------------------------------------------------
1 | /*++
2 | Copyright (c) 2012 Microsoft Corporation
3 |
4 | Module Name:
5 |
6 | z3_polynomial.h
7 |
8 | Abstract:
9 |
10 | Additional APIs for polynomials.
11 |
12 | Author:
13 |
14 | Leonardo de Moura (leonardo) 2012-12-09
15 |
16 | Notes:
17 |
18 | --*/
19 |
20 | #ifndef Z3_POLYNOMIAL_H_
21 | #define Z3_POLYNOMIAL_H_
22 |
23 | #ifdef __cplusplus
24 | extern "C" {
25 | #endif // __cplusplus
26 |
27 | /** \defgroup capi C API */
28 | /*@{*/
29 |
30 |
31 | /** @name Polynomials */
32 | /*@{*/
33 |
34 | /**
35 | \brief Return the nonzero subresultants of \c p and \c q with respect to the "variable" \c x.
36 |
37 | \pre \c p, \c q and \c x are Z3 expressions where \c p and \c q are arithmetic terms.
38 | Note that, any subterm that cannot be viewed as a polynomial is assumed to be a variable.
39 | Example: f(a) is a considered to be a variable in the polynomial
40 |
41 | f(a)*f(a) + 2*f(a) + 1
42 |
43 | def_API('Z3_polynomial_subresultants', AST_VECTOR, (_in(CONTEXT), _in(AST), _in(AST), _in(AST)))
44 | */
45 | Z3_ast_vector Z3_API Z3_polynomial_subresultants(Z3_context c, Z3_ast p, Z3_ast q, Z3_ast x);
46 |
47 |
48 | /*@}*/
49 | /*@}*/
50 |
51 | #ifdef __cplusplus
52 | }
53 | #endif // __cplusplus
54 |
55 | #endif
56 |
--------------------------------------------------------------------------------
/z3/bin/z3_spacer.h:
--------------------------------------------------------------------------------
1 | /*++
2 | Copyright (c) 2017 Arie Gurfinkel
3 |
4 | Module Name:
5 |
6 | z3_spacer.h
7 |
8 | Abstract:
9 |
10 | Spacer API
11 |
12 | Author:
13 |
14 | Arie Gurfinkel (arie)
15 |
16 | Notes:
17 |
18 | --*/
19 | #ifndef Z3_SPACER_H_
20 | #define Z3_SPACER_H_
21 |
22 | #ifdef __cplusplus
23 | extern "C" {
24 | #endif // __cplusplus
25 |
26 | /** \defgroup capi C API */
27 | /*@{*/
28 |
29 | /** @name Spacer facilities */
30 | /*@{*/
31 | /**
32 | \brief Pose a query against the asserted rules at the given level.
33 |
34 | \code
35 | query ::= (exists (bound-vars) query)
36 | | literals
37 | \endcode
38 |
39 | query returns
40 | - Z3_L_FALSE if the query is unsatisfiable.
41 | - Z3_L_TRUE if the query is satisfiable. Obtain the answer by calling #Z3_fixedpoint_get_answer.
42 | - Z3_L_UNDEF if the query was interrupted, timed out or otherwise failed.
43 |
44 | def_API('Z3_fixedpoint_query_from_lvl', INT, (_in(CONTEXT), _in(FIXEDPOINT), _in(AST), _in(UINT)))
45 | */
46 | Z3_lbool Z3_API Z3_fixedpoint_query_from_lvl (Z3_context c,Z3_fixedpoint d, Z3_ast query, unsigned lvl);
47 |
48 | /**
49 | \brief Retrieve a bottom-up (from query) sequence of ground facts
50 |
51 | The previous call to Z3_fixedpoint_query must have returned Z3_L_TRUE.
52 |
53 | def_API('Z3_fixedpoint_get_ground_sat_answer', AST, (_in(CONTEXT), _in(FIXEDPOINT)))
54 | */
55 | Z3_ast Z3_API Z3_fixedpoint_get_ground_sat_answer(Z3_context c,Z3_fixedpoint d);
56 |
57 | /**
58 | \brief Obtain the list of rules along the counterexample trace.
59 |
60 | def_API('Z3_fixedpoint_get_rules_along_trace', AST_VECTOR, (_in(CONTEXT), _in(FIXEDPOINT)))
61 | */
62 | Z3_ast_vector Z3_API Z3_fixedpoint_get_rules_along_trace(Z3_context c,Z3_fixedpoint d);
63 |
64 | /**
65 | \brief Obtain the list of rules along the counterexample trace.
66 |
67 | def_API('Z3_fixedpoint_get_rule_names_along_trace', SYMBOL, (_in(CONTEXT), _in(FIXEDPOINT)))
68 | */
69 | Z3_symbol Z3_API Z3_fixedpoint_get_rule_names_along_trace(Z3_context c,Z3_fixedpoint d);
70 |
71 | /**
72 | \brief Add an invariant for the predicate \c pred.
73 | Add an assumed invariant of predicate \c pred.
74 |
75 | Note: this functionality is Spacer specific.
76 |
77 | def_API('Z3_fixedpoint_add_invariant', VOID, (_in(CONTEXT), _in(FIXEDPOINT), _in(FUNC_DECL), _in(AST)))
78 | */
79 | void Z3_API Z3_fixedpoint_add_invariant(Z3_context c, Z3_fixedpoint d, Z3_func_decl pred, Z3_ast property);
80 |
81 |
82 | /**
83 | Retrieve reachable states of a predicate.
84 | Note: this functionality is Spacer specific.
85 |
86 | def_API('Z3_fixedpoint_get_reachable', AST, (_in(CONTEXT), _in(FIXEDPOINT), _in(FUNC_DECL)))
87 | */
88 | Z3_ast Z3_API Z3_fixedpoint_get_reachable(Z3_context c, Z3_fixedpoint d, Z3_func_decl pred);
89 |
90 | /**
91 | \brief Project variables given a model
92 |
93 | def_API('Z3_qe_model_project', AST, (_in(CONTEXT), _in(MODEL), _in(UINT), _in_array(2, APP), _in(AST)))
94 | */
95 | Z3_ast Z3_API Z3_qe_model_project
96 | (Z3_context c,
97 | Z3_model m,
98 | unsigned num_bounds,
99 | Z3_app const bound[],
100 | Z3_ast body);
101 |
102 |
103 | /**
104 | \brief Project variables given a model
105 |
106 | def_API('Z3_qe_model_project_skolem', AST, (_in(CONTEXT), _in(MODEL), _in(UINT), _in_array(2, APP), _in(AST), _in(AST_MAP)))
107 | */
108 | Z3_ast Z3_API Z3_qe_model_project_skolem
109 | (Z3_context c,
110 | Z3_model m,
111 | unsigned num_bounds,
112 | Z3_app const bound[],
113 | Z3_ast body,
114 | Z3_ast_map map);
115 |
116 | /**
117 | \brief Extrapolates a model of a formula
118 |
119 | def_API('Z3_model_extrapolate', AST, (_in(CONTEXT), _in(MODEL), _in(AST)))
120 | */
121 | Z3_ast Z3_API Z3_model_extrapolate
122 | (Z3_context c,
123 | Z3_model m,
124 | Z3_ast fml);
125 |
126 | /**
127 | \brief Best-effort quantifier elimination
128 |
129 | def_API ('Z3_qe_lite', AST, (_in(CONTEXT), _in(AST_VECTOR), _in(AST)))
130 | */
131 | Z3_ast Z3_API Z3_qe_lite
132 | (Z3_context c,
133 | Z3_ast_vector vars,
134 | Z3_ast body);
135 |
136 | /*@}*/
137 | /*@}*/
138 |
139 | #ifdef __cplusplus
140 | }
141 | #endif // __cplusplus
142 |
143 | #endif
144 |
--------------------------------------------------------------------------------
/z3/bin/z3_v1.h:
--------------------------------------------------------------------------------
1 | /*++
2 | Copyright (c) 2011 Microsoft Corporation
3 |
4 | Module Name:
5 |
6 | z3_v1.h
7 |
8 | Abstract:
9 |
10 | Z3 1.x backwards compatibility macros.
11 | These macros are used to simulate the Z3 API using in the 1.x versions.
12 | This file should only be used by users still using the Z3 1.x API.
13 |
14 | Author:
15 |
16 | Leonardo de Moura (leonardo) 2011-09-22
17 |
18 | Notes:
19 |
20 | --*/
21 | #ifndef Z3_V1_H_
22 | #define Z3_V1_H_
23 |
24 | #include "api/z3.h"
25 |
26 | // Backwards compatibility
27 | #define Z3_type_ast Z3_sort
28 | #define Z3_const_decl_ast Z3_func_decl
29 | #define Z3_const Z3_app
30 | #define Z3_pattern_ast Z3_pattern
31 | #define Z3_UNINTERPRETED_TYPE Z3_UNINTERPRETED_SORT
32 | #define Z3_BOOL_TYPE Z3_BOOL_SORT
33 | #define Z3_INT_TYPE Z3_INT_SORT
34 | #define Z3_REAL_TYPE Z3_REAL_SORT
35 | #define Z3_BV_TYPE Z3_BV_SORT
36 | #define Z3_ARRAY_TYPE Z3_ARRAY_SORT
37 | #define Z3_TUPLE_TYPE Z3_DATATYPE_SORT
38 | #define Z3_UNKNOWN_TYPE Z3_UNKNOWN_SORT
39 | #define Z3_CONST_DECL_AST Z3_FUNC_DECL_AST
40 | #define Z3_TYPE_AST Z3_SORT_AST
41 | #define Z3_SORT_ERROR Z3_TYPE_ERROR
42 | #define Z3_mk_uninterpreted_type Z3_mk_uninterpreted_sort
43 | #define Z3_mk_bool_type Z3_mk_bool_sort
44 | #define Z3_mk_int_type Z3_mk_int_sort
45 | #define Z3_mk_real_type Z3_mk_real_sort
46 | #define Z3_mk_bv_type Z3_mk_bv_sort
47 | #define Z3_mk_array_type Z3_mk_array_sort
48 | #define Z3_mk_tuple_type Z3_mk_tuple_sort
49 | #define Z3_get_type Z3_get_sort
50 | #define Z3_get_pattern_ast Z3_get_pattern
51 | #define Z3_get_type_kind Z3_get_sort_kind
52 | #define Z3_get_type_name Z3_get_sort_name
53 | #define Z3_get_bv_type_size Z3_get_bv_sort_size
54 | #define Z3_get_array_type_domain Z3_get_array_sort_domain
55 | #define Z3_get_array_type_range Z3_get_array_sort_range
56 | #define Z3_get_tuple_type_num_fields Z3_get_tuple_sort_num_fields
57 | #define Z3_get_tuple_type_field_decl Z3_get_tuple_sort_field_decl
58 | #define Z3_get_tuple_type_mk_decl Z3_get_tuple_sort_mk_decl
59 | #define Z3_to_const_ast Z3_to_app
60 | #define Z3_get_numeral_value_string Z3_get_numeral_string
61 | #define Z3_get_const_ast_decl Z3_get_app_decl
62 | #define Z3_get_value Z3_eval_func_decl
63 |
64 | #endif
65 |
--------------------------------------------------------------------------------
/z3/include/z3.h:
--------------------------------------------------------------------------------
1 | /*++
2 | Copyright (c) 2007 Microsoft Corporation
3 |
4 | Module Name:
5 |
6 | z3.h
7 |
8 | Abstract:
9 |
10 | Z3 API.
11 |
12 | Author:
13 |
14 | Nikolaj Bjorner (nbjorner)
15 | Leonardo de Moura (leonardo) 2007-06-8
16 |
17 | Notes:
18 |
19 | --*/
20 |
21 | #ifndef Z3_H_
22 | #define Z3_H_
23 |
24 | #include
25 | #include
26 | #include
27 | #include "z3_macros.h"
28 | #include "z3_api.h"
29 | #include "z3_ast_containers.h"
30 | #include "z3_algebraic.h"
31 | #include "z3_polynomial.h"
32 | #include "z3_rcf.h"
33 | #include "z3_fixedpoint.h"
34 | #include "z3_optimization.h"
35 | #include "z3_interp.h"
36 | #include "z3_fpa.h"
37 | #include "z3_spacer.h"
38 | #endif
39 |
40 |
--------------------------------------------------------------------------------
/z3/include/z3_macros.h:
--------------------------------------------------------------------------------
1 |
2 | /*++
3 | Copyright (c) 2015 Microsoft Corporation
4 |
5 | --*/
6 |
7 | #ifndef Z3_bool_opt
8 | #define Z3_bool_opt Z3_bool
9 | #endif
10 |
11 | #ifndef Z3_API
12 | # ifdef __GNUC__
13 | # define Z3_API __attribute__ ((visibility ("default")))
14 | # else
15 | # define Z3_API
16 | # endif
17 | #endif
18 |
19 | #ifndef DEFINE_TYPE
20 | #define DEFINE_TYPE(T) typedef struct _ ## T *T
21 | #endif
22 |
23 | #ifndef DEFINE_VOID
24 | #define DEFINE_VOID(T) typedef void* T
25 | #endif
26 |
--------------------------------------------------------------------------------
/z3/include/z3_polynomial.h:
--------------------------------------------------------------------------------
1 | /*++
2 | Copyright (c) 2012 Microsoft Corporation
3 |
4 | Module Name:
5 |
6 | z3_polynomial.h
7 |
8 | Abstract:
9 |
10 | Additional APIs for polynomials.
11 |
12 | Author:
13 |
14 | Leonardo de Moura (leonardo) 2012-12-09
15 |
16 | Notes:
17 |
18 | --*/
19 |
20 | #ifndef Z3_POLYNOMIAL_H_
21 | #define Z3_POLYNOMIAL_H_
22 |
23 | #ifdef __cplusplus
24 | extern "C" {
25 | #endif // __cplusplus
26 |
27 | /** \defgroup capi C API */
28 | /*@{*/
29 |
30 |
31 | /** @name Polynomials */
32 | /*@{*/
33 |
34 | /**
35 | \brief Return the nonzero subresultants of \c p and \c q with respect to the "variable" \c x.
36 |
37 | \pre \c p, \c q and \c x are Z3 expressions where \c p and \c q are arithmetic terms.
38 | Note that, any subterm that cannot be viewed as a polynomial is assumed to be a variable.
39 | Example: f(a) is a considered to be a variable in the polynomial
40 |
41 | f(a)*f(a) + 2*f(a) + 1
42 |
43 | def_API('Z3_polynomial_subresultants', AST_VECTOR, (_in(CONTEXT), _in(AST), _in(AST), _in(AST)))
44 | */
45 | Z3_ast_vector Z3_API Z3_polynomial_subresultants(Z3_context c, Z3_ast p, Z3_ast q, Z3_ast x);
46 |
47 |
48 | /*@}*/
49 | /*@}*/
50 |
51 | #ifdef __cplusplus
52 | }
53 | #endif // __cplusplus
54 |
55 | #endif
56 |
--------------------------------------------------------------------------------
/z3/include/z3_spacer.h:
--------------------------------------------------------------------------------
1 | /*++
2 | Copyright (c) 2017 Arie Gurfinkel
3 |
4 | Module Name:
5 |
6 | z3_spacer.h
7 |
8 | Abstract:
9 |
10 | Spacer API
11 |
12 | Author:
13 |
14 | Arie Gurfinkel (arie)
15 |
16 | Notes:
17 |
18 | --*/
19 | #ifndef Z3_SPACER_H_
20 | #define Z3_SPACER_H_
21 |
22 | #ifdef __cplusplus
23 | extern "C" {
24 | #endif // __cplusplus
25 |
26 | /** \defgroup capi C API */
27 | /*@{*/
28 |
29 | /** @name Spacer facilities */
30 | /*@{*/
31 | /**
32 | \brief Pose a query against the asserted rules at the given level.
33 |
34 | \code
35 | query ::= (exists (bound-vars) query)
36 | | literals
37 | \endcode
38 |
39 | query returns
40 | - Z3_L_FALSE if the query is unsatisfiable.
41 | - Z3_L_TRUE if the query is satisfiable. Obtain the answer by calling #Z3_fixedpoint_get_answer.
42 | - Z3_L_UNDEF if the query was interrupted, timed out or otherwise failed.
43 |
44 | def_API('Z3_fixedpoint_query_from_lvl', INT, (_in(CONTEXT), _in(FIXEDPOINT), _in(AST), _in(UINT)))
45 | */
46 | Z3_lbool Z3_API Z3_fixedpoint_query_from_lvl (Z3_context c,Z3_fixedpoint d, Z3_ast query, unsigned lvl);
47 |
48 | /**
49 | \brief Retrieve a bottom-up (from query) sequence of ground facts
50 |
51 | The previous call to Z3_fixedpoint_query must have returned Z3_L_TRUE.
52 |
53 | def_API('Z3_fixedpoint_get_ground_sat_answer', AST, (_in(CONTEXT), _in(FIXEDPOINT)))
54 | */
55 | Z3_ast Z3_API Z3_fixedpoint_get_ground_sat_answer(Z3_context c,Z3_fixedpoint d);
56 |
57 | /**
58 | \brief Obtain the list of rules along the counterexample trace.
59 |
60 | def_API('Z3_fixedpoint_get_rules_along_trace', AST_VECTOR, (_in(CONTEXT), _in(FIXEDPOINT)))
61 | */
62 | Z3_ast_vector Z3_API Z3_fixedpoint_get_rules_along_trace(Z3_context c,Z3_fixedpoint d);
63 |
64 | /**
65 | \brief Obtain the list of rules along the counterexample trace.
66 |
67 | def_API('Z3_fixedpoint_get_rule_names_along_trace', SYMBOL, (_in(CONTEXT), _in(FIXEDPOINT)))
68 | */
69 | Z3_symbol Z3_API Z3_fixedpoint_get_rule_names_along_trace(Z3_context c,Z3_fixedpoint d);
70 |
71 | /**
72 | \brief Add an invariant for the predicate \c pred.
73 | Add an assumed invariant of predicate \c pred.
74 |
75 | Note: this functionality is Spacer specific.
76 |
77 | def_API('Z3_fixedpoint_add_invariant', VOID, (_in(CONTEXT), _in(FIXEDPOINT), _in(FUNC_DECL), _in(AST)))
78 | */
79 | void Z3_API Z3_fixedpoint_add_invariant(Z3_context c, Z3_fixedpoint d, Z3_func_decl pred, Z3_ast property);
80 |
81 |
82 | /**
83 | Retrieve reachable states of a predicate.
84 | Note: this functionality is Spacer specific.
85 |
86 | def_API('Z3_fixedpoint_get_reachable', AST, (_in(CONTEXT), _in(FIXEDPOINT), _in(FUNC_DECL)))
87 | */
88 | Z3_ast Z3_API Z3_fixedpoint_get_reachable(Z3_context c, Z3_fixedpoint d, Z3_func_decl pred);
89 |
90 | /**
91 | \brief Project variables given a model
92 |
93 | def_API('Z3_qe_model_project', AST, (_in(CONTEXT), _in(MODEL), _in(UINT), _in_array(2, APP), _in(AST)))
94 | */
95 | Z3_ast Z3_API Z3_qe_model_project
96 | (Z3_context c,
97 | Z3_model m,
98 | unsigned num_bounds,
99 | Z3_app const bound[],
100 | Z3_ast body);
101 |
102 |
103 | /**
104 | \brief Project variables given a model
105 |
106 | def_API('Z3_qe_model_project_skolem', AST, (_in(CONTEXT), _in(MODEL), _in(UINT), _in_array(2, APP), _in(AST), _in(AST_MAP)))
107 | */
108 | Z3_ast Z3_API Z3_qe_model_project_skolem
109 | (Z3_context c,
110 | Z3_model m,
111 | unsigned num_bounds,
112 | Z3_app const bound[],
113 | Z3_ast body,
114 | Z3_ast_map map);
115 |
116 | /**
117 | \brief Extrapolates a model of a formula
118 |
119 | def_API('Z3_model_extrapolate', AST, (_in(CONTEXT), _in(MODEL), _in(AST)))
120 | */
121 | Z3_ast Z3_API Z3_model_extrapolate
122 | (Z3_context c,
123 | Z3_model m,
124 | Z3_ast fml);
125 |
126 | /**
127 | \brief Best-effort quantifier elimination
128 |
129 | def_API ('Z3_qe_lite', AST, (_in(CONTEXT), _in(AST_VECTOR), _in(AST)))
130 | */
131 | Z3_ast Z3_API Z3_qe_lite
132 | (Z3_context c,
133 | Z3_ast_vector vars,
134 | Z3_ast body);
135 |
136 | /*@}*/
137 | /*@}*/
138 |
139 | #ifdef __cplusplus
140 | }
141 | #endif // __cplusplus
142 |
143 | #endif
144 |
--------------------------------------------------------------------------------
/z3/include/z3_v1.h:
--------------------------------------------------------------------------------
1 | /*++
2 | Copyright (c) 2011 Microsoft Corporation
3 |
4 | Module Name:
5 |
6 | z3_v1.h
7 |
8 | Abstract:
9 |
10 | Z3 1.x backwards compatibility macros.
11 | These macros are used to simulate the Z3 API using in the 1.x versions.
12 | This file should only be used by users still using the Z3 1.x API.
13 |
14 | Author:
15 |
16 | Leonardo de Moura (leonardo) 2011-09-22
17 |
18 | Notes:
19 |
20 | --*/
21 | #ifndef Z3_V1_H_
22 | #define Z3_V1_H_
23 |
24 | #include "api/z3.h"
25 |
26 | // Backwards compatibility
27 | #define Z3_type_ast Z3_sort
28 | #define Z3_const_decl_ast Z3_func_decl
29 | #define Z3_const Z3_app
30 | #define Z3_pattern_ast Z3_pattern
31 | #define Z3_UNINTERPRETED_TYPE Z3_UNINTERPRETED_SORT
32 | #define Z3_BOOL_TYPE Z3_BOOL_SORT
33 | #define Z3_INT_TYPE Z3_INT_SORT
34 | #define Z3_REAL_TYPE Z3_REAL_SORT
35 | #define Z3_BV_TYPE Z3_BV_SORT
36 | #define Z3_ARRAY_TYPE Z3_ARRAY_SORT
37 | #define Z3_TUPLE_TYPE Z3_DATATYPE_SORT
38 | #define Z3_UNKNOWN_TYPE Z3_UNKNOWN_SORT
39 | #define Z3_CONST_DECL_AST Z3_FUNC_DECL_AST
40 | #define Z3_TYPE_AST Z3_SORT_AST
41 | #define Z3_SORT_ERROR Z3_TYPE_ERROR
42 | #define Z3_mk_uninterpreted_type Z3_mk_uninterpreted_sort
43 | #define Z3_mk_bool_type Z3_mk_bool_sort
44 | #define Z3_mk_int_type Z3_mk_int_sort
45 | #define Z3_mk_real_type Z3_mk_real_sort
46 | #define Z3_mk_bv_type Z3_mk_bv_sort
47 | #define Z3_mk_array_type Z3_mk_array_sort
48 | #define Z3_mk_tuple_type Z3_mk_tuple_sort
49 | #define Z3_get_type Z3_get_sort
50 | #define Z3_get_pattern_ast Z3_get_pattern
51 | #define Z3_get_type_kind Z3_get_sort_kind
52 | #define Z3_get_type_name Z3_get_sort_name
53 | #define Z3_get_bv_type_size Z3_get_bv_sort_size
54 | #define Z3_get_array_type_domain Z3_get_array_sort_domain
55 | #define Z3_get_array_type_range Z3_get_array_sort_range
56 | #define Z3_get_tuple_type_num_fields Z3_get_tuple_sort_num_fields
57 | #define Z3_get_tuple_type_field_decl Z3_get_tuple_sort_field_decl
58 | #define Z3_get_tuple_type_mk_decl Z3_get_tuple_sort_mk_decl
59 | #define Z3_to_const_ast Z3_to_app
60 | #define Z3_get_numeral_value_string Z3_get_numeral_string
61 | #define Z3_get_const_ast_decl Z3_get_app_decl
62 | #define Z3_get_value Z3_eval_func_decl
63 |
64 | #endif
65 |
--------------------------------------------------------------------------------