Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Portability fixes #85

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions include/ctc.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@

#pragma once

#ifndef CTC_API
// define this to __declspec(dllexport) when building the libary with visual studio
#define CTC_API
#endif

#ifdef __cplusplus
#include <cstddef>
extern "C" {
Expand All @@ -22,13 +27,13 @@ typedef enum {
} ctcStatus_t;

/** Returns a single integer which specifies the API version of the warpctc library */
int get_warpctc_version();
CTC_API int get_warpctc_version();

/** Returns a string containing a description of status that was passed in
* \param[in] status identifies which string should be returned
* \return C style string containing the text description
* */
const char* ctcGetStatusString(ctcStatus_t status);
CTC_API const char* ctcGetStatusString(ctcStatus_t status);

typedef enum {
CTC_CPU = 0,
Expand Down Expand Up @@ -91,7 +96,7 @@ struct ctcOptions {
* \return Status information
*
* */
ctcStatus_t compute_ctc_loss(const float* const activations,
CTC_API ctcStatus_t compute_ctc_loss(const float* const activations,
float* gradients,
const int* const flat_labels,
const int* const label_lengths,
Expand Down Expand Up @@ -120,7 +125,7 @@ ctcStatus_t compute_ctc_loss(const float* const activations,
*
* \return Status information
**/
ctcStatus_t get_workspace_size(const int* const label_lengths,
CTC_API ctcStatus_t get_workspace_size(const int* const label_lengths,
const int* const input_lengths,
int alphabet_size, int minibatch,
ctcOptions info,
Expand Down
1 change: 1 addition & 0 deletions src/ctc_entrypoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include <iostream>
#include <algorithm>

#define CTC_API __declspec(dllexport)
#include <ctc.h>

#include "detail/cpu_ctc.h"
Expand Down
46 changes: 24 additions & 22 deletions tests/test_cpu.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#include <algorithm>
#include <numeric>
#include <cmath>
#include <random>
#include <tuple>
Expand All @@ -13,8 +15,8 @@ bool small_test() {
const int alphabet_size = 5;
const int T = 2;

std::vector<float> activations = {0.1, 0.6, 0.1, 0.1, 0.1,
0.1, 0.1, 0.6, 0.1, 0.1};
std::vector<float> activations = {0.1f, 0.6f, 0.1f, 0.1f, 0.1f,
0.1f, 0.1f, 0.6f, 0.1f, 0.1f};

// Calculate the score analytically
float expected_score;
Expand Down Expand Up @@ -78,36 +80,36 @@ bool options_test() {
const int minibatch = 2;

std::vector<float> activations =
{0.633766, 0.221185, 0.0917319, 0.0129757, 0.0142857, 0.0260553,
0.30176, 0.28562, 0.0831517, 0.0862751, 0.0816851, 0.161508,
{0.633766f, 0.221185f, 0.0917319f, 0.0129757f, 0.0142857f, 0.0260553f,
0.30176f, 0.28562f, 0.0831517f, 0.0862751f, 0.0816851f, 0.161508f,

0.111121, 0.588392, 0.278779, 0.0055756, 0.00569609, 0.010436,
0.24082, 0.397533, 0.0557226, 0.0546814, 0.0557528, 0.19549,
0.111121f, 0.588392f, 0.278779f, 0.0055756f, 0.00569609f, 0.010436f,
0.24082f, 0.397533f, 0.0557226f, 0.0546814f, 0.0557528f, 0.19549f,

0.0357786, 0.633813, 0.321418, 0.00249248, 0.00272882, 0.0037688,
0.230246, 0.450868, 0.0389607, 0.038309, 0.0391602, 0.202456,
0.0357786f, 0.633813f, 0.321418f, 0.00249248f, 0.00272882f, 0.0037688f,
0.230246f, 0.450868f, 0.0389607f, 0.038309f, 0.0391602f, 0.202456f,

0.0663296, 0.643849, 0.280111, 0.00283995, 0.0035545, 0.00331533,
0.280884, 0.429522, 0.0326593, 0.0339046, 0.0326856, 0.190345,
0.0663296f, 0.643849f, 0.280111f, 0.00283995f, 0.0035545f, 0.00331533f,
0.280884f, 0.429522f, 0.0326593f, 0.0339046f, 0.0326856f, 0.190345f,

0.458235, 0.396634, 0.123377, 0.00648837, 0.00903441, 0.00623107,
0.423286, 0.315517, 0.0338439, 0.0393744, 0.0339315, 0.154046};
0.458235f, 0.396634f, 0.123377f, 0.00648837f, 0.00903441f, 0.00623107f,
0.423286f, 0.315517f, 0.0338439f, 0.0393744f, 0.0339315f, 0.154046f};

std::vector<float> expected_grads = // from tensorflow
{-0.366234, 0.221185, 0.0917319, 0.0129757, 0.0142857, 0.0260553,
-0.69824, 0.28562, 0.0831517, 0.0862751, 0.0816851, 0.161508,
{-0.366234f, 0.221185f, 0.0917319f, 0.0129757f, 0.0142857f, 0.0260553f,
-0.69824f, 0.28562f, 0.0831517f, 0.0862751f, 0.0816851f, 0.161508f,

0.111121, -0.411608, 0.278779, 0.0055756, 0.00569609, 0.010436,
0.24082, -0.602467, 0.0557226, 0.0546814, 0.0557528, 0.19549,
0.111121f, -0.411608f, 0.278779f, 0.0055756f, 0.00569609f, 0.010436f,
0.24082f, -0.602467f, 0.0557226f, 0.0546814f, 0.0557528f, 0.19549f,

0.0357786, 0.633813, -0.678582, 0.00249248, 0.00272882, 0.0037688,
0.230246, 0.450868, 0.0389607, 0.038309, 0.0391602, -0.797544,
0.0357786f, 0.633813f, -0.678582f, 0.00249248f, 0.00272882f, 0.0037688f,
0.230246f, 0.450868f, 0.0389607f, 0.038309f, 0.0391602f, -0.797544f,

0.0663296, -0.356151, 0.280111, 0.00283995, 0.0035545, 0.00331533,
0.280884, -0.570478, 0.0326593, 0.0339046, 0.0326856, 0.190345,
0.0663296f, -0.356151f, 0.280111f, 0.00283995f, 0.0035545f, 0.00331533f,
0.280884f, -0.570478f, 0.0326593f, 0.0339046f, 0.0326856f, 0.190345f,

-0.541765, 0.396634, 0.123377, 0.00648837, 0.00903441, 0.00623107,
-0.576714, 0.315517, 0.0338439, 0.0393744, 0.0339315, 0.154046};
-0.541765f, 0.396634f, 0.123377f, 0.00648837f, 0.00903441f, 0.00623107f,
-0.576714f, 0.315517f, 0.0338439f, 0.0393744f, 0.0339315f, 0.154046f};


// Calculate the expected scores analytically
Expand Down